Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1 | //===-- ASTReader.cpp - AST File Reader -----------------------------------===// |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the ASTReader class, which reads AST files. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Serialization/ASTReader.h" |
| 15 | #include "ASTCommon.h" |
| 16 | #include "ASTReaderInternals.h" |
| 17 | #include "clang/AST/ASTConsumer.h" |
| 18 | #include "clang/AST/ASTContext.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 19 | #include "clang/AST/ASTMutationListener.h" |
| 20 | #include "clang/AST/ASTUnresolvedSet.h" |
| 21 | #include "clang/AST/Decl.h" |
| 22 | #include "clang/AST/DeclCXX.h" |
| 23 | #include "clang/AST/DeclGroup.h" |
| 24 | #include "clang/AST/DeclObjC.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 25 | #include "clang/AST/DeclTemplate.h" |
| 26 | #include "clang/AST/Expr.h" |
| 27 | #include "clang/AST/ExprCXX.h" |
| 28 | #include "clang/AST/NestedNameSpecifier.h" |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 29 | #include "clang/AST/ODRHash.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 30 | #include "clang/AST/RawCommentList.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 31 | #include "clang/AST/Type.h" |
| 32 | #include "clang/AST/TypeLocVisitor.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 33 | #include "clang/AST/UnresolvedSet.h" |
| 34 | #include "clang/Basic/CommentOptions.h" |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 35 | #include "clang/Basic/DiagnosticOptions.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 36 | #include "clang/Basic/ExceptionSpecificationType.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 37 | #include "clang/Basic/FileManager.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 38 | #include "clang/Basic/FileSystemOptions.h" |
| 39 | #include "clang/Basic/LangOptions.h" |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 40 | #include "clang/Basic/MemoryBufferCache.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 41 | #include "clang/Basic/ObjCRuntime.h" |
| 42 | #include "clang/Basic/OperatorKinds.h" |
| 43 | #include "clang/Basic/Sanitizers.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 44 | #include "clang/Basic/SourceManager.h" |
| 45 | #include "clang/Basic/SourceManagerInternals.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 46 | #include "clang/Basic/Specifiers.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 47 | #include "clang/Basic/TargetInfo.h" |
| 48 | #include "clang/Basic/TargetOptions.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 49 | #include "clang/Basic/TokenKinds.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 50 | #include "clang/Basic/Version.h" |
| 51 | #include "clang/Basic/VersionTuple.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 52 | #include "clang/Frontend/PCHContainerOperations.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 53 | #include "clang/Lex/HeaderSearch.h" |
| 54 | #include "clang/Lex/HeaderSearchOptions.h" |
| 55 | #include "clang/Lex/MacroInfo.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 56 | #include "clang/Lex/ModuleMap.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 57 | #include "clang/Lex/PreprocessingRecord.h" |
| 58 | #include "clang/Lex/Preprocessor.h" |
| 59 | #include "clang/Lex/PreprocessorOptions.h" |
| 60 | #include "clang/Sema/Scope.h" |
| 61 | #include "clang/Sema/Sema.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 62 | #include "clang/Sema/Weak.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 63 | #include "clang/Serialization/ASTDeserializationListener.h" |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 64 | #include "clang/Serialization/GlobalModuleIndex.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 65 | #include "clang/Serialization/ModuleManager.h" |
| 66 | #include "clang/Serialization/SerializationDiagnostic.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 67 | #include "llvm/ADT/APFloat.h" |
| 68 | #include "llvm/ADT/APInt.h" |
| 69 | #include "llvm/ADT/APSInt.h" |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 70 | #include "llvm/ADT/Hashing.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 71 | #include "llvm/ADT/SmallString.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 72 | #include "llvm/ADT/StringExtras.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 73 | #include "llvm/ADT/Triple.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 74 | #include "llvm/Bitcode/BitstreamReader.h" |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 75 | #include "llvm/Support/Compression.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 76 | #include "llvm/Support/Compiler.h" |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 77 | #include "llvm/Support/Error.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 78 | #include "llvm/Support/ErrorHandling.h" |
| 79 | #include "llvm/Support/FileSystem.h" |
| 80 | #include "llvm/Support/MemoryBuffer.h" |
| 81 | #include "llvm/Support/Path.h" |
| 82 | #include "llvm/Support/SaveAndRestore.h" |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 83 | #include "llvm/Support/raw_ostream.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 84 | #include <algorithm> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 85 | #include <cassert> |
| 86 | #include <cstdint> |
Chris Lattner | 91f373e | 2013-01-20 00:57:52 +0000 | [diff] [blame] | 87 | #include <cstdio> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 88 | #include <cstring> |
| 89 | #include <ctime> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 90 | #include <iterator> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 91 | #include <limits> |
| 92 | #include <map> |
| 93 | #include <memory> |
| 94 | #include <new> |
| 95 | #include <string> |
Rafael Espindola | 8a8e554 | 2014-06-12 17:19:42 +0000 | [diff] [blame] | 96 | #include <system_error> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 97 | #include <tuple> |
| 98 | #include <utility> |
| 99 | #include <vector> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 100 | |
| 101 | using namespace clang; |
| 102 | using namespace clang::serialization; |
| 103 | using namespace clang::serialization::reader; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 104 | using llvm::BitstreamCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 105 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 106 | //===----------------------------------------------------------------------===// |
| 107 | // ChainedASTReaderListener implementation |
| 108 | //===----------------------------------------------------------------------===// |
| 109 | |
| 110 | bool |
| 111 | ChainedASTReaderListener::ReadFullVersionInformation(StringRef FullVersion) { |
| 112 | return First->ReadFullVersionInformation(FullVersion) || |
| 113 | Second->ReadFullVersionInformation(FullVersion); |
| 114 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 115 | |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 116 | void ChainedASTReaderListener::ReadModuleName(StringRef ModuleName) { |
| 117 | First->ReadModuleName(ModuleName); |
| 118 | Second->ReadModuleName(ModuleName); |
| 119 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 120 | |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 121 | void ChainedASTReaderListener::ReadModuleMapFile(StringRef ModuleMapPath) { |
| 122 | First->ReadModuleMapFile(ModuleMapPath); |
| 123 | Second->ReadModuleMapFile(ModuleMapPath); |
| 124 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 125 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 126 | bool |
| 127 | ChainedASTReaderListener::ReadLanguageOptions(const LangOptions &LangOpts, |
| 128 | bool Complain, |
| 129 | bool AllowCompatibleDifferences) { |
| 130 | return First->ReadLanguageOptions(LangOpts, Complain, |
| 131 | AllowCompatibleDifferences) || |
| 132 | Second->ReadLanguageOptions(LangOpts, Complain, |
| 133 | AllowCompatibleDifferences); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 134 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 135 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 136 | bool ChainedASTReaderListener::ReadTargetOptions( |
| 137 | const TargetOptions &TargetOpts, bool Complain, |
| 138 | bool AllowCompatibleDifferences) { |
| 139 | return First->ReadTargetOptions(TargetOpts, Complain, |
| 140 | AllowCompatibleDifferences) || |
| 141 | Second->ReadTargetOptions(TargetOpts, Complain, |
| 142 | AllowCompatibleDifferences); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 143 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 144 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 145 | bool ChainedASTReaderListener::ReadDiagnosticOptions( |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 146 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) { |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 147 | return First->ReadDiagnosticOptions(DiagOpts, Complain) || |
| 148 | Second->ReadDiagnosticOptions(DiagOpts, Complain); |
| 149 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 150 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 151 | bool |
| 152 | ChainedASTReaderListener::ReadFileSystemOptions(const FileSystemOptions &FSOpts, |
| 153 | bool Complain) { |
| 154 | return First->ReadFileSystemOptions(FSOpts, Complain) || |
| 155 | Second->ReadFileSystemOptions(FSOpts, Complain); |
| 156 | } |
| 157 | |
| 158 | bool ChainedASTReaderListener::ReadHeaderSearchOptions( |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 159 | const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, |
| 160 | bool Complain) { |
| 161 | return First->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 162 | Complain) || |
| 163 | Second->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 164 | Complain); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 165 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 166 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 167 | bool ChainedASTReaderListener::ReadPreprocessorOptions( |
| 168 | const PreprocessorOptions &PPOpts, bool Complain, |
| 169 | std::string &SuggestedPredefines) { |
| 170 | return First->ReadPreprocessorOptions(PPOpts, Complain, |
| 171 | SuggestedPredefines) || |
| 172 | Second->ReadPreprocessorOptions(PPOpts, Complain, SuggestedPredefines); |
| 173 | } |
| 174 | void ChainedASTReaderListener::ReadCounter(const serialization::ModuleFile &M, |
| 175 | unsigned Value) { |
| 176 | First->ReadCounter(M, Value); |
| 177 | Second->ReadCounter(M, Value); |
| 178 | } |
| 179 | bool ChainedASTReaderListener::needsInputFileVisitation() { |
| 180 | return First->needsInputFileVisitation() || |
| 181 | Second->needsInputFileVisitation(); |
| 182 | } |
| 183 | bool ChainedASTReaderListener::needsSystemInputFileVisitation() { |
| 184 | return First->needsSystemInputFileVisitation() || |
| 185 | Second->needsSystemInputFileVisitation(); |
| 186 | } |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 187 | void ChainedASTReaderListener::visitModuleFile(StringRef Filename, |
| 188 | ModuleKind Kind) { |
| 189 | First->visitModuleFile(Filename, Kind); |
| 190 | Second->visitModuleFile(Filename, Kind); |
Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 191 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 192 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 193 | bool ChainedASTReaderListener::visitInputFile(StringRef Filename, |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 194 | bool isSystem, |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 195 | bool isOverridden, |
| 196 | bool isExplicitModule) { |
Justin Bogner | c65a66d | 2014-05-22 06:04:59 +0000 | [diff] [blame] | 197 | bool Continue = false; |
| 198 | if (First->needsInputFileVisitation() && |
| 199 | (!isSystem || First->needsSystemInputFileVisitation())) |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 200 | Continue |= First->visitInputFile(Filename, isSystem, isOverridden, |
| 201 | isExplicitModule); |
Justin Bogner | c65a66d | 2014-05-22 06:04:59 +0000 | [diff] [blame] | 202 | if (Second->needsInputFileVisitation() && |
| 203 | (!isSystem || Second->needsSystemInputFileVisitation())) |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 204 | Continue |= Second->visitInputFile(Filename, isSystem, isOverridden, |
| 205 | isExplicitModule); |
Justin Bogner | c65a66d | 2014-05-22 06:04:59 +0000 | [diff] [blame] | 206 | return Continue; |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 209 | void ChainedASTReaderListener::readModuleFileExtension( |
| 210 | const ModuleFileExtensionMetadata &Metadata) { |
| 211 | First->readModuleFileExtension(Metadata); |
| 212 | Second->readModuleFileExtension(Metadata); |
| 213 | } |
| 214 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 215 | //===----------------------------------------------------------------------===// |
| 216 | // PCH validator implementation |
| 217 | //===----------------------------------------------------------------------===// |
| 218 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 219 | ASTReaderListener::~ASTReaderListener() {} |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 220 | |
| 221 | /// \brief Compare the given set of language options against an existing set of |
| 222 | /// language options. |
| 223 | /// |
| 224 | /// \param Diags If non-NULL, diagnostics will be emitted via this engine. |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 225 | /// \param AllowCompatibleDifferences If true, differences between compatible |
| 226 | /// language options will be permitted. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 227 | /// |
| 228 | /// \returns true if the languagae options mis-match, false otherwise. |
| 229 | static bool checkLanguageOptions(const LangOptions &LangOpts, |
| 230 | const LangOptions &ExistingLangOpts, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 231 | DiagnosticsEngine *Diags, |
| 232 | bool AllowCompatibleDifferences = true) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 233 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 234 | if (ExistingLangOpts.Name != LangOpts.Name) { \ |
| 235 | if (Diags) \ |
| 236 | Diags->Report(diag::err_pch_langopt_mismatch) \ |
| 237 | << Description << LangOpts.Name << ExistingLangOpts.Name; \ |
| 238 | return true; \ |
| 239 | } |
| 240 | |
| 241 | #define VALUE_LANGOPT(Name, Bits, Default, Description) \ |
| 242 | if (ExistingLangOpts.Name != LangOpts.Name) { \ |
| 243 | if (Diags) \ |
| 244 | Diags->Report(diag::err_pch_langopt_value_mismatch) \ |
| 245 | << Description; \ |
| 246 | return true; \ |
| 247 | } |
| 248 | |
| 249 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 250 | if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \ |
| 251 | if (Diags) \ |
| 252 | Diags->Report(diag::err_pch_langopt_value_mismatch) \ |
| 253 | << Description; \ |
| 254 | return true; \ |
| 255 | } |
| 256 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 257 | #define COMPATIBLE_LANGOPT(Name, Bits, Default, Description) \ |
| 258 | if (!AllowCompatibleDifferences) \ |
| 259 | LANGOPT(Name, Bits, Default, Description) |
| 260 | |
| 261 | #define COMPATIBLE_ENUM_LANGOPT(Name, Bits, Default, Description) \ |
| 262 | if (!AllowCompatibleDifferences) \ |
| 263 | ENUM_LANGOPT(Name, Bits, Default, Description) |
| 264 | |
Richard Smith | a1ddf5e | 2016-04-07 20:47:37 +0000 | [diff] [blame] | 265 | #define COMPATIBLE_VALUE_LANGOPT(Name, Bits, Default, Description) \ |
| 266 | if (!AllowCompatibleDifferences) \ |
| 267 | VALUE_LANGOPT(Name, Bits, Default, Description) |
| 268 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 269 | #define BENIGN_LANGOPT(Name, Bits, Default, Description) |
| 270 | #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) |
Richard Smith | a1ddf5e | 2016-04-07 20:47:37 +0000 | [diff] [blame] | 271 | #define BENIGN_VALUE_LANGOPT(Name, Type, Bits, Default, Description) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 272 | #include "clang/Basic/LangOptions.def" |
| 273 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 274 | if (ExistingLangOpts.ModuleFeatures != LangOpts.ModuleFeatures) { |
| 275 | if (Diags) |
| 276 | Diags->Report(diag::err_pch_langopt_value_mismatch) << "module features"; |
| 277 | return true; |
| 278 | } |
| 279 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 280 | if (ExistingLangOpts.ObjCRuntime != LangOpts.ObjCRuntime) { |
| 281 | if (Diags) |
| 282 | Diags->Report(diag::err_pch_langopt_value_mismatch) |
| 283 | << "target Objective-C runtime"; |
| 284 | return true; |
| 285 | } |
| 286 | |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 287 | if (ExistingLangOpts.CommentOpts.BlockCommandNames != |
| 288 | LangOpts.CommentOpts.BlockCommandNames) { |
| 289 | if (Diags) |
| 290 | Diags->Report(diag::err_pch_langopt_value_mismatch) |
| 291 | << "block command names"; |
| 292 | return true; |
| 293 | } |
| 294 | |
Vedant Kumar | 85a83c2 | 2017-06-01 20:01:01 +0000 | [diff] [blame] | 295 | // Sanitizer feature mismatches are treated as compatible differences. If |
| 296 | // compatible differences aren't allowed, we still only want to check for |
| 297 | // mismatches of non-modular sanitizers (the only ones which can affect AST |
| 298 | // generation). |
| 299 | if (!AllowCompatibleDifferences) { |
| 300 | SanitizerMask ModularSanitizers = getPPTransparentSanitizers(); |
| 301 | SanitizerSet ExistingSanitizers = ExistingLangOpts.Sanitize; |
| 302 | SanitizerSet ImportedSanitizers = LangOpts.Sanitize; |
| 303 | ExistingSanitizers.clear(ModularSanitizers); |
| 304 | ImportedSanitizers.clear(ModularSanitizers); |
| 305 | if (ExistingSanitizers.Mask != ImportedSanitizers.Mask) { |
| 306 | const std::string Flag = "-fsanitize="; |
| 307 | if (Diags) { |
| 308 | #define SANITIZER(NAME, ID) \ |
| 309 | { \ |
| 310 | bool InExistingModule = ExistingSanitizers.has(SanitizerKind::ID); \ |
| 311 | bool InImportedModule = ImportedSanitizers.has(SanitizerKind::ID); \ |
| 312 | if (InExistingModule != InImportedModule) \ |
| 313 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) \ |
| 314 | << InExistingModule << (Flag + NAME); \ |
| 315 | } |
| 316 | #include "clang/Basic/Sanitizers.def" |
| 317 | } |
| 318 | return true; |
| 319 | } |
| 320 | } |
| 321 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 322 | return false; |
| 323 | } |
| 324 | |
| 325 | /// \brief Compare the given set of target options against an existing set of |
| 326 | /// target options. |
| 327 | /// |
| 328 | /// \param Diags If non-NULL, diagnostics will be emitted via this engine. |
| 329 | /// |
| 330 | /// \returns true if the target options mis-match, false otherwise. |
| 331 | static bool checkTargetOptions(const TargetOptions &TargetOpts, |
| 332 | const TargetOptions &ExistingTargetOpts, |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 333 | DiagnosticsEngine *Diags, |
| 334 | bool AllowCompatibleDifferences = true) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 335 | #define CHECK_TARGET_OPT(Field, Name) \ |
| 336 | if (TargetOpts.Field != ExistingTargetOpts.Field) { \ |
| 337 | if (Diags) \ |
| 338 | Diags->Report(diag::err_pch_targetopt_mismatch) \ |
| 339 | << Name << TargetOpts.Field << ExistingTargetOpts.Field; \ |
| 340 | return true; \ |
| 341 | } |
| 342 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 343 | // The triple and ABI must match exactly. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 344 | CHECK_TARGET_OPT(Triple, "target"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 345 | CHECK_TARGET_OPT(ABI, "target ABI"); |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 346 | |
| 347 | // We can tolerate different CPUs in many cases, notably when one CPU |
| 348 | // supports a strict superset of another. When allowing compatible |
| 349 | // differences skip this check. |
| 350 | if (!AllowCompatibleDifferences) |
| 351 | CHECK_TARGET_OPT(CPU, "target CPU"); |
| 352 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 353 | #undef CHECK_TARGET_OPT |
| 354 | |
| 355 | // Compare feature sets. |
| 356 | SmallVector<StringRef, 4> ExistingFeatures( |
| 357 | ExistingTargetOpts.FeaturesAsWritten.begin(), |
| 358 | ExistingTargetOpts.FeaturesAsWritten.end()); |
| 359 | SmallVector<StringRef, 4> ReadFeatures(TargetOpts.FeaturesAsWritten.begin(), |
| 360 | TargetOpts.FeaturesAsWritten.end()); |
| 361 | std::sort(ExistingFeatures.begin(), ExistingFeatures.end()); |
| 362 | std::sort(ReadFeatures.begin(), ReadFeatures.end()); |
| 363 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 364 | // We compute the set difference in both directions explicitly so that we can |
| 365 | // diagnose the differences differently. |
| 366 | SmallVector<StringRef, 4> UnmatchedExistingFeatures, UnmatchedReadFeatures; |
| 367 | std::set_difference( |
| 368 | ExistingFeatures.begin(), ExistingFeatures.end(), ReadFeatures.begin(), |
| 369 | ReadFeatures.end(), std::back_inserter(UnmatchedExistingFeatures)); |
| 370 | std::set_difference(ReadFeatures.begin(), ReadFeatures.end(), |
| 371 | ExistingFeatures.begin(), ExistingFeatures.end(), |
| 372 | std::back_inserter(UnmatchedReadFeatures)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 373 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 374 | // If we are allowing compatible differences and the read feature set is |
| 375 | // a strict subset of the existing feature set, there is nothing to diagnose. |
| 376 | if (AllowCompatibleDifferences && UnmatchedReadFeatures.empty()) |
| 377 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 378 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 379 | if (Diags) { |
| 380 | for (StringRef Feature : UnmatchedReadFeatures) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 381 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 382 | << /* is-existing-feature */ false << Feature; |
| 383 | for (StringRef Feature : UnmatchedExistingFeatures) |
| 384 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
| 385 | << /* is-existing-feature */ true << Feature; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 388 | return !UnmatchedReadFeatures.empty() || !UnmatchedExistingFeatures.empty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | bool |
| 392 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 393 | bool Complain, |
| 394 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 395 | const LangOptions &ExistingLangOpts = PP.getLangOpts(); |
| 396 | return checkLanguageOptions(LangOpts, ExistingLangOpts, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 397 | Complain ? &Reader.Diags : nullptr, |
| 398 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | bool PCHValidator::ReadTargetOptions(const TargetOptions &TargetOpts, |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 402 | bool Complain, |
| 403 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 404 | const TargetOptions &ExistingTargetOpts = PP.getTargetInfo().getTargetOpts(); |
| 405 | return checkTargetOptions(TargetOpts, ExistingTargetOpts, |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 406 | Complain ? &Reader.Diags : nullptr, |
| 407 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 411 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 412 | typedef llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> > |
| 413 | MacroDefinitionsMap; |
Craig Topper | 3598eb7 | 2013-07-05 04:43:31 +0000 | [diff] [blame] | 414 | typedef llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8> > |
| 415 | DeclsMap; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 416 | |
| 417 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 418 | |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 419 | static bool checkDiagnosticGroupMappings(DiagnosticsEngine &StoredDiags, |
| 420 | DiagnosticsEngine &Diags, |
| 421 | bool Complain) { |
| 422 | typedef DiagnosticsEngine::Level Level; |
| 423 | |
| 424 | // Check current mappings for new -Werror mappings, and the stored mappings |
| 425 | // for cases that were explicitly mapped to *not* be errors that are now |
| 426 | // errors because of options like -Werror. |
| 427 | DiagnosticsEngine *MappingSources[] = { &Diags, &StoredDiags }; |
| 428 | |
| 429 | for (DiagnosticsEngine *MappingSource : MappingSources) { |
| 430 | for (auto DiagIDMappingPair : MappingSource->getDiagnosticMappings()) { |
| 431 | diag::kind DiagID = DiagIDMappingPair.first; |
| 432 | Level CurLevel = Diags.getDiagnosticLevel(DiagID, SourceLocation()); |
| 433 | if (CurLevel < DiagnosticsEngine::Error) |
| 434 | continue; // not significant |
| 435 | Level StoredLevel = |
| 436 | StoredDiags.getDiagnosticLevel(DiagID, SourceLocation()); |
| 437 | if (StoredLevel < DiagnosticsEngine::Error) { |
| 438 | if (Complain) |
| 439 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror=" + |
| 440 | Diags.getDiagnosticIDs()->getWarningOptionForDiag(DiagID).str(); |
| 441 | return true; |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | return false; |
| 447 | } |
| 448 | |
Alp Toker | ac4e8e5 | 2014-06-22 21:58:33 +0000 | [diff] [blame] | 449 | static bool isExtHandlingFromDiagsError(DiagnosticsEngine &Diags) { |
| 450 | diag::Severity Ext = Diags.getExtensionHandlingBehavior(); |
| 451 | if (Ext == diag::Severity::Warning && Diags.getWarningsAsErrors()) |
| 452 | return true; |
| 453 | return Ext >= diag::Severity::Error; |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | static bool checkDiagnosticMappings(DiagnosticsEngine &StoredDiags, |
| 457 | DiagnosticsEngine &Diags, |
| 458 | bool IsSystem, bool Complain) { |
| 459 | // Top-level options |
| 460 | if (IsSystem) { |
| 461 | if (Diags.getSuppressSystemWarnings()) |
| 462 | return false; |
| 463 | // If -Wsystem-headers was not enabled before, be conservative |
| 464 | if (StoredDiags.getSuppressSystemWarnings()) { |
| 465 | if (Complain) |
| 466 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Wsystem-headers"; |
| 467 | return true; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | if (Diags.getWarningsAsErrors() && !StoredDiags.getWarningsAsErrors()) { |
| 472 | if (Complain) |
| 473 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror"; |
| 474 | return true; |
| 475 | } |
| 476 | |
| 477 | if (Diags.getWarningsAsErrors() && Diags.getEnableAllWarnings() && |
| 478 | !StoredDiags.getEnableAllWarnings()) { |
| 479 | if (Complain) |
| 480 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Weverything -Werror"; |
| 481 | return true; |
| 482 | } |
| 483 | |
| 484 | if (isExtHandlingFromDiagsError(Diags) && |
| 485 | !isExtHandlingFromDiagsError(StoredDiags)) { |
| 486 | if (Complain) |
| 487 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-pedantic-errors"; |
| 488 | return true; |
| 489 | } |
| 490 | |
| 491 | return checkDiagnosticGroupMappings(StoredDiags, Diags, Complain); |
| 492 | } |
| 493 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 494 | /// Return the top import module if it is implicit, nullptr otherwise. |
| 495 | static Module *getTopImportImplicitModule(ModuleManager &ModuleMgr, |
| 496 | Preprocessor &PP) { |
| 497 | // If the original import came from a file explicitly generated by the user, |
| 498 | // don't check the diagnostic mappings. |
| 499 | // FIXME: currently this is approximated by checking whether this is not a |
| 500 | // module import of an implicitly-loaded module file. |
| 501 | // Note: ModuleMgr.rbegin() may not be the current module, but it must be in |
| 502 | // the transitive closure of its imports, since unrelated modules cannot be |
| 503 | // imported until after this module finishes validation. |
| 504 | ModuleFile *TopImport = &*ModuleMgr.rbegin(); |
| 505 | while (!TopImport->ImportedBy.empty()) |
| 506 | TopImport = TopImport->ImportedBy[0]; |
| 507 | if (TopImport->Kind != MK_ImplicitModule) |
| 508 | return nullptr; |
| 509 | |
| 510 | StringRef ModuleName = TopImport->ModuleName; |
| 511 | assert(!ModuleName.empty() && "diagnostic options read before module name"); |
| 512 | |
| 513 | Module *M = PP.getHeaderSearchInfo().lookupModule(ModuleName); |
| 514 | assert(M && "missing module"); |
| 515 | return M; |
| 516 | } |
| 517 | |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 518 | bool PCHValidator::ReadDiagnosticOptions( |
| 519 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) { |
| 520 | DiagnosticsEngine &ExistingDiags = PP.getDiagnostics(); |
| 521 | IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(ExistingDiags.getDiagnosticIDs()); |
| 522 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags( |
Alp Toker | f994cef | 2014-07-05 03:08:06 +0000 | [diff] [blame] | 523 | new DiagnosticsEngine(DiagIDs, DiagOpts.get())); |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 524 | // This should never fail, because we would have processed these options |
| 525 | // before writing them to an ASTFile. |
| 526 | ProcessWarningOptions(*Diags, *DiagOpts, /*Report*/false); |
| 527 | |
| 528 | ModuleManager &ModuleMgr = Reader.getModuleManager(); |
| 529 | assert(ModuleMgr.size() >= 1 && "what ASTFile is this then"); |
| 530 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 531 | Module *TopM = getTopImportImplicitModule(ModuleMgr, PP); |
| 532 | if (!TopM) |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 533 | return false; |
| 534 | |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 535 | // FIXME: if the diagnostics are incompatible, save a DiagnosticOptions that |
| 536 | // contains the union of their flags. |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 537 | return checkDiagnosticMappings(*Diags, ExistingDiags, TopM->IsSystem, |
| 538 | Complain); |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 539 | } |
| 540 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 541 | /// \brief Collect the macro definitions provided by the given preprocessor |
| 542 | /// options. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 543 | static void |
| 544 | collectMacroDefinitions(const PreprocessorOptions &PPOpts, |
| 545 | MacroDefinitionsMap &Macros, |
| 546 | SmallVectorImpl<StringRef> *MacroNames = nullptr) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 547 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 548 | StringRef Macro = PPOpts.Macros[I].first; |
| 549 | bool IsUndef = PPOpts.Macros[I].second; |
| 550 | |
| 551 | std::pair<StringRef, StringRef> MacroPair = Macro.split('='); |
| 552 | StringRef MacroName = MacroPair.first; |
| 553 | StringRef MacroBody = MacroPair.second; |
| 554 | |
| 555 | // For an #undef'd macro, we only care about the name. |
| 556 | if (IsUndef) { |
| 557 | if (MacroNames && !Macros.count(MacroName)) |
| 558 | MacroNames->push_back(MacroName); |
| 559 | |
| 560 | Macros[MacroName] = std::make_pair("", true); |
| 561 | continue; |
| 562 | } |
| 563 | |
| 564 | // For a #define'd macro, figure out the actual definition. |
| 565 | if (MacroName.size() == Macro.size()) |
| 566 | MacroBody = "1"; |
| 567 | else { |
| 568 | // Note: GCC drops anything following an end-of-line character. |
| 569 | StringRef::size_type End = MacroBody.find_first_of("\n\r"); |
| 570 | MacroBody = MacroBody.substr(0, End); |
| 571 | } |
| 572 | |
| 573 | if (MacroNames && !Macros.count(MacroName)) |
| 574 | MacroNames->push_back(MacroName); |
| 575 | Macros[MacroName] = std::make_pair(MacroBody, false); |
| 576 | } |
| 577 | } |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 578 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 579 | /// \brief Check the preprocessor options deserialized from the control block |
| 580 | /// against the preprocessor options in an existing preprocessor. |
| 581 | /// |
| 582 | /// \param Diags If non-null, produce diagnostics for any mismatches incurred. |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 583 | /// \param Validate If true, validate preprocessor options. If false, allow |
| 584 | /// macros defined by \p ExistingPPOpts to override those defined by |
| 585 | /// \p PPOpts in SuggestedPredefines. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 586 | static bool checkPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 587 | const PreprocessorOptions &ExistingPPOpts, |
| 588 | DiagnosticsEngine *Diags, |
| 589 | FileManager &FileMgr, |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 590 | std::string &SuggestedPredefines, |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 591 | const LangOptions &LangOpts, |
| 592 | bool Validate = true) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 593 | // Check macro definitions. |
| 594 | MacroDefinitionsMap ASTFileMacros; |
| 595 | collectMacroDefinitions(PPOpts, ASTFileMacros); |
| 596 | MacroDefinitionsMap ExistingMacros; |
| 597 | SmallVector<StringRef, 4> ExistingMacroNames; |
| 598 | collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames); |
| 599 | |
| 600 | for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) { |
| 601 | // Dig out the macro definition in the existing preprocessor options. |
| 602 | StringRef MacroName = ExistingMacroNames[I]; |
| 603 | std::pair<StringRef, bool> Existing = ExistingMacros[MacroName]; |
| 604 | |
| 605 | // Check whether we know anything about this macro name or not. |
| 606 | llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> >::iterator Known |
| 607 | = ASTFileMacros.find(MacroName); |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 608 | if (!Validate || Known == ASTFileMacros.end()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 609 | // FIXME: Check whether this identifier was referenced anywhere in the |
| 610 | // AST file. If so, we should reject the AST file. Unfortunately, this |
| 611 | // information isn't in the control block. What shall we do about it? |
| 612 | |
| 613 | if (Existing.second) { |
| 614 | SuggestedPredefines += "#undef "; |
| 615 | SuggestedPredefines += MacroName.str(); |
| 616 | SuggestedPredefines += '\n'; |
| 617 | } else { |
| 618 | SuggestedPredefines += "#define "; |
| 619 | SuggestedPredefines += MacroName.str(); |
| 620 | SuggestedPredefines += ' '; |
| 621 | SuggestedPredefines += Existing.first.str(); |
| 622 | SuggestedPredefines += '\n'; |
| 623 | } |
| 624 | continue; |
| 625 | } |
| 626 | |
| 627 | // If the macro was defined in one but undef'd in the other, we have a |
| 628 | // conflict. |
| 629 | if (Existing.second != Known->second.second) { |
| 630 | if (Diags) { |
| 631 | Diags->Report(diag::err_pch_macro_def_undef) |
| 632 | << MacroName << Known->second.second; |
| 633 | } |
| 634 | return true; |
| 635 | } |
| 636 | |
| 637 | // If the macro was #undef'd in both, or if the macro bodies are identical, |
| 638 | // it's fine. |
| 639 | if (Existing.second || Existing.first == Known->second.first) |
| 640 | continue; |
| 641 | |
| 642 | // The macro bodies differ; complain. |
| 643 | if (Diags) { |
| 644 | Diags->Report(diag::err_pch_macro_def_conflict) |
| 645 | << MacroName << Known->second.first << Existing.first; |
| 646 | } |
| 647 | return true; |
| 648 | } |
| 649 | |
| 650 | // Check whether we're using predefines. |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 651 | if (PPOpts.UsePredefines != ExistingPPOpts.UsePredefines && Validate) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 652 | if (Diags) { |
| 653 | Diags->Report(diag::err_pch_undef) << ExistingPPOpts.UsePredefines; |
| 654 | } |
| 655 | return true; |
| 656 | } |
| 657 | |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 658 | // Detailed record is important since it is used for the module cache hash. |
| 659 | if (LangOpts.Modules && |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 660 | PPOpts.DetailedRecord != ExistingPPOpts.DetailedRecord && Validate) { |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 661 | if (Diags) { |
| 662 | Diags->Report(diag::err_pch_pp_detailed_record) << PPOpts.DetailedRecord; |
| 663 | } |
| 664 | return true; |
| 665 | } |
| 666 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 667 | // Compute the #include and #include_macros lines we need. |
| 668 | for (unsigned I = 0, N = ExistingPPOpts.Includes.size(); I != N; ++I) { |
| 669 | StringRef File = ExistingPPOpts.Includes[I]; |
| 670 | if (File == ExistingPPOpts.ImplicitPCHInclude) |
| 671 | continue; |
| 672 | |
| 673 | if (std::find(PPOpts.Includes.begin(), PPOpts.Includes.end(), File) |
| 674 | != PPOpts.Includes.end()) |
| 675 | continue; |
| 676 | |
| 677 | SuggestedPredefines += "#include \""; |
Manuel Klimek | 9af34ae | 2014-08-12 08:25:57 +0000 | [diff] [blame] | 678 | SuggestedPredefines += File; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 679 | SuggestedPredefines += "\"\n"; |
| 680 | } |
| 681 | |
| 682 | for (unsigned I = 0, N = ExistingPPOpts.MacroIncludes.size(); I != N; ++I) { |
| 683 | StringRef File = ExistingPPOpts.MacroIncludes[I]; |
| 684 | if (std::find(PPOpts.MacroIncludes.begin(), PPOpts.MacroIncludes.end(), |
| 685 | File) |
| 686 | != PPOpts.MacroIncludes.end()) |
| 687 | continue; |
| 688 | |
| 689 | SuggestedPredefines += "#__include_macros \""; |
Manuel Klimek | 9af34ae | 2014-08-12 08:25:57 +0000 | [diff] [blame] | 690 | SuggestedPredefines += File; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 691 | SuggestedPredefines += "\"\n##\n"; |
| 692 | } |
| 693 | |
| 694 | return false; |
| 695 | } |
| 696 | |
| 697 | bool PCHValidator::ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 698 | bool Complain, |
| 699 | std::string &SuggestedPredefines) { |
| 700 | const PreprocessorOptions &ExistingPPOpts = PP.getPreprocessorOpts(); |
| 701 | |
| 702 | return checkPreprocessorOptions(PPOpts, ExistingPPOpts, |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 703 | Complain? &Reader.Diags : nullptr, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 704 | PP.getFileManager(), |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 705 | SuggestedPredefines, |
| 706 | PP.getLangOpts()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 709 | bool SimpleASTReaderListener::ReadPreprocessorOptions( |
| 710 | const PreprocessorOptions &PPOpts, |
| 711 | bool Complain, |
| 712 | std::string &SuggestedPredefines) { |
| 713 | return checkPreprocessorOptions(PPOpts, |
| 714 | PP.getPreprocessorOpts(), |
| 715 | nullptr, |
| 716 | PP.getFileManager(), |
| 717 | SuggestedPredefines, |
| 718 | PP.getLangOpts(), |
| 719 | false); |
| 720 | } |
| 721 | |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 722 | /// Check the header search options deserialized from the control block |
| 723 | /// against the header search options in an existing preprocessor. |
| 724 | /// |
| 725 | /// \param Diags If non-null, produce diagnostics for any mismatches incurred. |
| 726 | static bool checkHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 727 | StringRef SpecificModuleCachePath, |
| 728 | StringRef ExistingModuleCachePath, |
| 729 | DiagnosticsEngine *Diags, |
| 730 | const LangOptions &LangOpts) { |
| 731 | if (LangOpts.Modules) { |
| 732 | if (SpecificModuleCachePath != ExistingModuleCachePath) { |
| 733 | if (Diags) |
| 734 | Diags->Report(diag::err_pch_modulecache_mismatch) |
| 735 | << SpecificModuleCachePath << ExistingModuleCachePath; |
| 736 | return true; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | return false; |
| 741 | } |
| 742 | |
| 743 | bool PCHValidator::ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 744 | StringRef SpecificModuleCachePath, |
| 745 | bool Complain) { |
| 746 | return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 747 | PP.getHeaderSearchInfo().getModuleCachePath(), |
| 748 | Complain ? &Reader.Diags : nullptr, |
| 749 | PP.getLangOpts()); |
| 750 | } |
| 751 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 752 | void PCHValidator::ReadCounter(const ModuleFile &M, unsigned Value) { |
| 753 | PP.setCounterValue(Value); |
| 754 | } |
| 755 | |
| 756 | //===----------------------------------------------------------------------===// |
| 757 | // AST reader implementation |
| 758 | //===----------------------------------------------------------------------===// |
| 759 | |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 760 | void ASTReader::setDeserializationListener(ASTDeserializationListener *Listener, |
| 761 | bool TakeOwnership) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 762 | DeserializationListener = Listener; |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 763 | OwnsDeserializationListener = TakeOwnership; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 764 | } |
| 765 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 766 | unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { |
| 767 | return serialization::ComputeHash(Sel); |
| 768 | } |
| 769 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 770 | std::pair<unsigned, unsigned> |
| 771 | ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 772 | using namespace llvm::support; |
| 773 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 774 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 775 | return std::make_pair(KeyLen, DataLen); |
| 776 | } |
| 777 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 778 | ASTSelectorLookupTrait::internal_key_type |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 779 | ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 780 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 781 | SelectorTable &SelTable = Reader.getContext().Selectors; |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 782 | unsigned N = endian::readNext<uint16_t, little, unaligned>(d); |
| 783 | IdentifierInfo *FirstII = Reader.getLocalIdentifier( |
| 784 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 785 | if (N == 0) |
| 786 | return SelTable.getNullarySelector(FirstII); |
| 787 | else if (N == 1) |
| 788 | return SelTable.getUnarySelector(FirstII); |
| 789 | |
| 790 | SmallVector<IdentifierInfo *, 16> Args; |
| 791 | Args.push_back(FirstII); |
| 792 | for (unsigned I = 1; I != N; ++I) |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 793 | Args.push_back(Reader.getLocalIdentifier( |
| 794 | F, endian::readNext<uint32_t, little, unaligned>(d))); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 795 | |
| 796 | return SelTable.getSelector(N, Args.data()); |
| 797 | } |
| 798 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 799 | ASTSelectorLookupTrait::data_type |
| 800 | ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 801 | unsigned DataLen) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 802 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 803 | |
| 804 | data_type Result; |
| 805 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 806 | Result.ID = Reader.getGlobalSelectorID( |
| 807 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 808 | unsigned FullInstanceBits = endian::readNext<uint16_t, little, unaligned>(d); |
| 809 | unsigned FullFactoryBits = endian::readNext<uint16_t, little, unaligned>(d); |
| 810 | Result.InstanceBits = FullInstanceBits & 0x3; |
| 811 | Result.InstanceHasMoreThanOneDecl = (FullInstanceBits >> 2) & 0x1; |
| 812 | Result.FactoryBits = FullFactoryBits & 0x3; |
| 813 | Result.FactoryHasMoreThanOneDecl = (FullFactoryBits >> 2) & 0x1; |
| 814 | unsigned NumInstanceMethods = FullInstanceBits >> 3; |
| 815 | unsigned NumFactoryMethods = FullFactoryBits >> 3; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 816 | |
| 817 | // Load instance methods |
| 818 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 819 | if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>( |
| 820 | F, endian::readNext<uint32_t, little, unaligned>(d))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 821 | Result.Instance.push_back(Method); |
| 822 | } |
| 823 | |
| 824 | // Load factory methods |
| 825 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 826 | if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>( |
| 827 | F, endian::readNext<uint32_t, little, unaligned>(d))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 828 | Result.Factory.push_back(Method); |
| 829 | } |
| 830 | |
| 831 | return Result; |
| 832 | } |
| 833 | |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 834 | unsigned ASTIdentifierLookupTraitBase::ComputeHash(const internal_key_type& a) { |
| 835 | return llvm::HashString(a); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | std::pair<unsigned, unsigned> |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 839 | ASTIdentifierLookupTraitBase::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 840 | using namespace llvm::support; |
| 841 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 842 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 843 | return std::make_pair(KeyLen, DataLen); |
| 844 | } |
| 845 | |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 846 | ASTIdentifierLookupTraitBase::internal_key_type |
| 847 | ASTIdentifierLookupTraitBase::ReadKey(const unsigned char* d, unsigned n) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 848 | assert(n >= 2 && d[n-1] == '\0'); |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 849 | return StringRef((const char*) d, n-1); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 850 | } |
| 851 | |
Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 852 | /// \brief Whether the given identifier is "interesting". |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 853 | static bool isInterestingIdentifier(ASTReader &Reader, IdentifierInfo &II, |
| 854 | bool IsModule) { |
Richard Smith | cab8980 | 2015-07-17 20:19:56 +0000 | [diff] [blame] | 855 | return II.hadMacroDefinition() || |
| 856 | II.isPoisoned() || |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 857 | (IsModule ? II.hasRevertedBuiltin() : II.getObjCOrBuiltinID()) || |
Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 858 | II.hasRevertedTokenIDToIdentifier() || |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 859 | (!(IsModule && Reader.getPreprocessor().getLangOpts().CPlusPlus) && |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 860 | II.getFETokenInfo<void>()); |
Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 861 | } |
| 862 | |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 863 | static bool readBit(unsigned &Bits) { |
| 864 | bool Value = Bits & 0x1; |
| 865 | Bits >>= 1; |
| 866 | return Value; |
| 867 | } |
| 868 | |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 869 | IdentID ASTIdentifierLookupTrait::ReadIdentifierID(const unsigned char *d) { |
| 870 | using namespace llvm::support; |
| 871 | unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d); |
| 872 | return Reader.getGlobalIdentifierID(F, RawID >> 1); |
| 873 | } |
| 874 | |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 875 | static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II) { |
| 876 | if (!II.isFromAST()) { |
| 877 | II.setIsFromAST(); |
| 878 | bool IsModule = Reader.getPreprocessor().getCurrentModule() != nullptr; |
| 879 | if (isInterestingIdentifier(Reader, II, IsModule)) |
| 880 | II.setChangedSinceDeserialization(); |
| 881 | } |
| 882 | } |
| 883 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 884 | IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, |
| 885 | const unsigned char* d, |
| 886 | unsigned DataLen) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 887 | using namespace llvm::support; |
| 888 | unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 889 | bool IsInteresting = RawID & 0x01; |
| 890 | |
| 891 | // Wipe out the "is interesting" bit. |
| 892 | RawID = RawID >> 1; |
| 893 | |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 894 | // Build the IdentifierInfo and link the identifier ID with it. |
| 895 | IdentifierInfo *II = KnownII; |
| 896 | if (!II) { |
| 897 | II = &Reader.getIdentifierTable().getOwn(k); |
| 898 | KnownII = II; |
| 899 | } |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 900 | markIdentifierFromAST(Reader, *II); |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 901 | Reader.markIdentifierUpToDate(II); |
| 902 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 903 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
| 904 | if (!IsInteresting) { |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 905 | // For uninteresting identifiers, there's nothing else to do. Just notify |
| 906 | // the reader that we've finished loading this identifier. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 907 | Reader.SetIdentifierInfo(ID, II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 908 | return II; |
| 909 | } |
| 910 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 911 | unsigned ObjCOrBuiltinID = endian::readNext<uint16_t, little, unaligned>(d); |
| 912 | unsigned Bits = endian::readNext<uint16_t, little, unaligned>(d); |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 913 | bool CPlusPlusOperatorKeyword = readBit(Bits); |
| 914 | bool HasRevertedTokenIDToIdentifier = readBit(Bits); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 915 | bool HasRevertedBuiltin = readBit(Bits); |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 916 | bool Poisoned = readBit(Bits); |
| 917 | bool ExtensionToken = readBit(Bits); |
| 918 | bool HadMacroDefinition = readBit(Bits); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 919 | |
| 920 | assert(Bits == 0 && "Extra bits in the identifier?"); |
| 921 | DataLen -= 8; |
| 922 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 923 | // Set or check the various bits in the IdentifierInfo structure. |
| 924 | // Token IDs are read-only. |
Argyrios Kyrtzidis | ddee8c9 | 2013-02-27 01:13:51 +0000 | [diff] [blame] | 925 | if (HasRevertedTokenIDToIdentifier && II->getTokenID() != tok::identifier) |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 926 | II->revertTokenIDToIdentifier(); |
| 927 | if (!F.isModule()) |
| 928 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 929 | else if (HasRevertedBuiltin && II->getBuiltinID()) { |
| 930 | II->revertBuiltin(); |
| 931 | assert((II->hasRevertedBuiltin() || |
| 932 | II->getObjCOrBuiltinID() == ObjCOrBuiltinID) && |
| 933 | "Incorrect ObjC keyword or builtin ID"); |
| 934 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 935 | assert(II->isExtensionToken() == ExtensionToken && |
| 936 | "Incorrect extension token flag"); |
| 937 | (void)ExtensionToken; |
| 938 | if (Poisoned) |
| 939 | II->setIsPoisoned(true); |
| 940 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 941 | "Incorrect C++ operator keyword flag"); |
| 942 | (void)CPlusPlusOperatorKeyword; |
| 943 | |
| 944 | // If this identifier is a macro, deserialize the macro |
| 945 | // definition. |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 946 | if (HadMacroDefinition) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 947 | uint32_t MacroDirectivesOffset = |
| 948 | endian::readNext<uint32_t, little, unaligned>(d); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 949 | DataLen -= 4; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 950 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 951 | Reader.addPendingMacro(II, &F, MacroDirectivesOffset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | Reader.SetIdentifierInfo(ID, II); |
| 955 | |
| 956 | // Read all of the declarations visible at global scope with this |
| 957 | // name. |
| 958 | if (DataLen > 0) { |
| 959 | SmallVector<uint32_t, 4> DeclIDs; |
| 960 | for (; DataLen > 0; DataLen -= 4) |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 961 | DeclIDs.push_back(Reader.getGlobalDeclID( |
| 962 | F, endian::readNext<uint32_t, little, unaligned>(d))); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 963 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
| 964 | } |
| 965 | |
| 966 | return II; |
| 967 | } |
| 968 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 969 | DeclarationNameKey::DeclarationNameKey(DeclarationName Name) |
| 970 | : Kind(Name.getNameKind()) { |
| 971 | switch (Kind) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 972 | case DeclarationName::Identifier: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 973 | Data = (uint64_t)Name.getAsIdentifierInfo(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 974 | break; |
| 975 | case DeclarationName::ObjCZeroArgSelector: |
| 976 | case DeclarationName::ObjCOneArgSelector: |
| 977 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 978 | Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 979 | break; |
| 980 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 981 | Data = Name.getCXXOverloadedOperator(); |
| 982 | break; |
| 983 | case DeclarationName::CXXLiteralOperatorName: |
| 984 | Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 985 | break; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 986 | case DeclarationName::CXXDeductionGuideName: |
| 987 | Data = (uint64_t)Name.getCXXDeductionGuideTemplate() |
| 988 | ->getDeclName().getAsIdentifierInfo(); |
| 989 | break; |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 990 | case DeclarationName::CXXConstructorName: |
| 991 | case DeclarationName::CXXDestructorName: |
| 992 | case DeclarationName::CXXConversionFunctionName: |
| 993 | case DeclarationName::CXXUsingDirective: |
| 994 | Data = 0; |
| 995 | break; |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | unsigned DeclarationNameKey::getHash() const { |
| 1000 | llvm::FoldingSetNodeID ID; |
| 1001 | ID.AddInteger(Kind); |
| 1002 | |
| 1003 | switch (Kind) { |
| 1004 | case DeclarationName::Identifier: |
| 1005 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1006 | case DeclarationName::CXXDeductionGuideName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1007 | ID.AddString(((IdentifierInfo*)Data)->getName()); |
| 1008 | break; |
| 1009 | case DeclarationName::ObjCZeroArgSelector: |
| 1010 | case DeclarationName::ObjCOneArgSelector: |
| 1011 | case DeclarationName::ObjCMultiArgSelector: |
| 1012 | ID.AddInteger(serialization::ComputeHash(Selector(Data))); |
| 1013 | break; |
| 1014 | case DeclarationName::CXXOperatorName: |
| 1015 | ID.AddInteger((OverloadedOperatorKind)Data); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1016 | break; |
| 1017 | case DeclarationName::CXXConstructorName: |
| 1018 | case DeclarationName::CXXDestructorName: |
| 1019 | case DeclarationName::CXXConversionFunctionName: |
| 1020 | case DeclarationName::CXXUsingDirective: |
| 1021 | break; |
| 1022 | } |
| 1023 | |
| 1024 | return ID.ComputeHash(); |
| 1025 | } |
| 1026 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1027 | ModuleFile * |
| 1028 | ASTDeclContextNameLookupTrait::ReadFileRef(const unsigned char *&d) { |
| 1029 | using namespace llvm::support; |
| 1030 | uint32_t ModuleFileID = endian::readNext<uint32_t, little, unaligned>(d); |
| 1031 | return Reader.getLocalModuleFile(F, ModuleFileID); |
| 1032 | } |
| 1033 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1034 | std::pair<unsigned, unsigned> |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1035 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char *&d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1036 | using namespace llvm::support; |
| 1037 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 1038 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1039 | return std::make_pair(KeyLen, DataLen); |
| 1040 | } |
| 1041 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1042 | ASTDeclContextNameLookupTrait::internal_key_type |
| 1043 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char *d, unsigned) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1044 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1045 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1046 | auto Kind = (DeclarationName::NameKind)*d++; |
| 1047 | uint64_t Data; |
| 1048 | switch (Kind) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1049 | case DeclarationName::Identifier: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1050 | case DeclarationName::CXXLiteralOperatorName: |
| 1051 | case DeclarationName::CXXDeductionGuideName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1052 | Data = (uint64_t)Reader.getLocalIdentifier( |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1053 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1054 | break; |
| 1055 | case DeclarationName::ObjCZeroArgSelector: |
| 1056 | case DeclarationName::ObjCOneArgSelector: |
| 1057 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1058 | Data = |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1059 | (uint64_t)Reader.getLocalSelector( |
| 1060 | F, endian::readNext<uint32_t, little, unaligned>( |
| 1061 | d)).getAsOpaquePtr(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1062 | break; |
| 1063 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1064 | Data = *d++; // OverloadedOperatorKind |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1065 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1066 | case DeclarationName::CXXConstructorName: |
| 1067 | case DeclarationName::CXXDestructorName: |
| 1068 | case DeclarationName::CXXConversionFunctionName: |
| 1069 | case DeclarationName::CXXUsingDirective: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1070 | Data = 0; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1071 | break; |
| 1072 | } |
| 1073 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1074 | return DeclarationNameKey(Kind, Data); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1077 | void ASTDeclContextNameLookupTrait::ReadDataInto(internal_key_type, |
| 1078 | const unsigned char *d, |
| 1079 | unsigned DataLen, |
| 1080 | data_type_builder &Val) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1081 | using namespace llvm::support; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1082 | for (unsigned NumDecls = DataLen / 4; NumDecls; --NumDecls) { |
| 1083 | uint32_t LocalID = endian::readNext<uint32_t, little, unaligned>(d); |
| 1084 | Val.insert(Reader.getGlobalDeclID(F, LocalID)); |
| 1085 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1088 | bool ASTReader::ReadLexicalDeclContextStorage(ModuleFile &M, |
| 1089 | BitstreamCursor &Cursor, |
| 1090 | uint64_t Offset, |
| 1091 | DeclContext *DC) { |
| 1092 | assert(Offset != 0); |
| 1093 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1094 | SavedStreamPosition SavedPosition(Cursor); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1095 | Cursor.JumpToBit(Offset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1096 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1097 | RecordData Record; |
| 1098 | StringRef Blob; |
| 1099 | unsigned Code = Cursor.ReadCode(); |
| 1100 | unsigned RecCode = Cursor.readRecord(Code, Record, &Blob); |
| 1101 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 1102 | Error("Expected lexical block"); |
| 1103 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 1106 | assert(!isa<TranslationUnitDecl>(DC) && |
| 1107 | "expected a TU_UPDATE_LEXICAL record for TU"); |
Richard Smith | 9c9173d | 2015-08-11 22:00:24 +0000 | [diff] [blame] | 1108 | // If we are handling a C++ class template instantiation, we can see multiple |
| 1109 | // lexical updates for the same record. It's important that we select only one |
| 1110 | // of them, so that field numbering works properly. Just pick the first one we |
| 1111 | // see. |
| 1112 | auto &Lex = LexicalDecls[DC]; |
| 1113 | if (!Lex.first) { |
| 1114 | Lex = std::make_pair( |
| 1115 | &M, llvm::makeArrayRef( |
| 1116 | reinterpret_cast<const llvm::support::unaligned_uint32_t *>( |
| 1117 | Blob.data()), |
| 1118 | Blob.size() / 4)); |
| 1119 | } |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1120 | DC->setHasExternalLexicalStorage(true); |
| 1121 | return false; |
| 1122 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1123 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1124 | bool ASTReader::ReadVisibleDeclContextStorage(ModuleFile &M, |
| 1125 | BitstreamCursor &Cursor, |
| 1126 | uint64_t Offset, |
| 1127 | DeclID ID) { |
| 1128 | assert(Offset != 0); |
| 1129 | |
| 1130 | SavedStreamPosition SavedPosition(Cursor); |
| 1131 | Cursor.JumpToBit(Offset); |
| 1132 | |
| 1133 | RecordData Record; |
| 1134 | StringRef Blob; |
| 1135 | unsigned Code = Cursor.ReadCode(); |
| 1136 | unsigned RecCode = Cursor.readRecord(Code, Record, &Blob); |
| 1137 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 1138 | Error("Expected visible lookup table block"); |
| 1139 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1142 | // We can't safely determine the primary context yet, so delay attaching the |
| 1143 | // lookup table until we're done with recursive deserialization. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1144 | auto *Data = (const unsigned char*)Blob.data(); |
| 1145 | PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&M, Data}); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1146 | return false; |
| 1147 | } |
| 1148 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 1149 | void ASTReader::Error(StringRef Msg) const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1150 | Error(diag::err_fe_pch_malformed, Msg); |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 1151 | if (PP.getLangOpts().Modules && !Diags.isDiagnosticInFlight() && |
Richard Smith | fb1e7f7 | 2015-08-14 05:02:58 +0000 | [diff] [blame] | 1152 | !PP.getHeaderSearchInfo().getModuleCachePath().empty()) { |
Douglas Gregor | 940e805 | 2013-05-10 22:15:13 +0000 | [diff] [blame] | 1153 | Diag(diag::note_module_cache_path) |
| 1154 | << PP.getHeaderSearchInfo().getModuleCachePath(); |
| 1155 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | void ASTReader::Error(unsigned DiagID, |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 1159 | StringRef Arg1, StringRef Arg2) const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1160 | if (Diags.isDiagnosticInFlight()) |
| 1161 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 1162 | else |
| 1163 | Diag(DiagID) << Arg1 << Arg2; |
| 1164 | } |
| 1165 | |
| 1166 | //===----------------------------------------------------------------------===// |
| 1167 | // Source Manager Deserialization |
| 1168 | //===----------------------------------------------------------------------===// |
| 1169 | |
| 1170 | /// \brief Read the line table in the source manager block. |
| 1171 | /// \returns true if there was an error. |
| 1172 | bool ASTReader::ParseLineTable(ModuleFile &F, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1173 | const RecordData &Record) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1174 | unsigned Idx = 0; |
| 1175 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1176 | |
| 1177 | // Parse the file names |
| 1178 | std::map<int, int> FileIDs; |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1179 | for (unsigned I = 0; Record[Idx]; ++I) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1180 | // Extract the file name |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1181 | auto Filename = ReadPath(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1182 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
| 1183 | } |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1184 | ++Idx; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1185 | |
| 1186 | // Parse the line entries |
| 1187 | std::vector<LineEntry> Entries; |
| 1188 | while (Idx < Record.size()) { |
| 1189 | int FID = Record[Idx++]; |
| 1190 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 1191 | // Remap FileID from 1-based old view. |
| 1192 | FID += F.SLocEntryBaseID - 1; |
| 1193 | |
| 1194 | // Extract the line entries |
| 1195 | unsigned NumEntries = Record[Idx++]; |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1196 | assert(NumEntries && "no line entries for file ID"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1197 | Entries.clear(); |
| 1198 | Entries.reserve(NumEntries); |
| 1199 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1200 | unsigned FileOffset = Record[Idx++]; |
| 1201 | unsigned LineNo = Record[Idx++]; |
| 1202 | int FilenameID = FileIDs[Record[Idx++]]; |
| 1203 | SrcMgr::CharacteristicKind FileKind |
| 1204 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1205 | unsigned IncludeOffset = Record[Idx++]; |
| 1206 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1207 | FileKind, IncludeOffset)); |
| 1208 | } |
| 1209 | LineTable.AddEntry(FileID::get(FID), Entries); |
| 1210 | } |
| 1211 | |
| 1212 | return false; |
| 1213 | } |
| 1214 | |
| 1215 | /// \brief Read a source manager block |
| 1216 | bool ASTReader::ReadSourceManagerBlock(ModuleFile &F) { |
| 1217 | using namespace SrcMgr; |
| 1218 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1219 | BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1220 | |
| 1221 | // Set the source-location entry cursor to the current position in |
| 1222 | // the stream. This cursor will be used to read the contents of the |
| 1223 | // source manager block initially, and then lazily read |
| 1224 | // source-location entries as needed. |
| 1225 | SLocEntryCursor = F.Stream; |
| 1226 | |
| 1227 | // The stream itself is going to skip over the source manager block. |
| 1228 | if (F.Stream.SkipBlock()) { |
| 1229 | Error("malformed block record in AST file"); |
| 1230 | return true; |
| 1231 | } |
| 1232 | |
| 1233 | // Enter the source manager block. |
| 1234 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
| 1235 | Error("malformed source manager block record in AST file"); |
| 1236 | return true; |
| 1237 | } |
| 1238 | |
| 1239 | RecordData Record; |
| 1240 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1241 | llvm::BitstreamEntry E = SLocEntryCursor.advanceSkippingSubblocks(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1242 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1243 | switch (E.Kind) { |
| 1244 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1245 | case llvm::BitstreamEntry::Error: |
| 1246 | Error("malformed block record in AST file"); |
| 1247 | return true; |
| 1248 | case llvm::BitstreamEntry::EndBlock: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1249 | return false; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1250 | case llvm::BitstreamEntry::Record: |
| 1251 | // The interesting case. |
| 1252 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1253 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1254 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1255 | // Read a record. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1256 | Record.clear(); |
Chris Lattner | 15c3e7d | 2013-01-21 18:28:26 +0000 | [diff] [blame] | 1257 | StringRef Blob; |
| 1258 | switch (SLocEntryCursor.readRecord(E.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1259 | default: // Default behavior: ignore. |
| 1260 | break; |
| 1261 | |
| 1262 | case SM_SLOC_FILE_ENTRY: |
| 1263 | case SM_SLOC_BUFFER_ENTRY: |
| 1264 | case SM_SLOC_EXPANSION_ENTRY: |
| 1265 | // Once we hit one of the source location entries, we're done. |
| 1266 | return false; |
| 1267 | } |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | /// \brief If a header file is not found at the path that we expect it to be |
| 1272 | /// and the PCH file was moved from its original location, try to resolve the |
| 1273 | /// file by assuming that header+PCH were moved together and the header is in |
| 1274 | /// the same place relative to the PCH. |
| 1275 | static std::string |
| 1276 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1277 | const std::string &OriginalDir, |
| 1278 | const std::string &CurrDir) { |
| 1279 | assert(OriginalDir != CurrDir && |
| 1280 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1281 | using namespace llvm::sys; |
| 1282 | SmallString<128> filePath(Filename); |
| 1283 | fs::make_absolute(filePath); |
| 1284 | assert(path::is_absolute(OriginalDir)); |
| 1285 | SmallString<128> currPCHPath(CurrDir); |
| 1286 | |
| 1287 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1288 | fileDirE = path::end(path::parent_path(filePath)); |
| 1289 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1290 | origDirE = path::end(OriginalDir); |
| 1291 | // Skip the common path components from filePath and OriginalDir. |
| 1292 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1293 | *fileDirI == *origDirI) { |
| 1294 | ++fileDirI; |
| 1295 | ++origDirI; |
| 1296 | } |
| 1297 | for (; origDirI != origDirE; ++origDirI) |
| 1298 | path::append(currPCHPath, ".."); |
| 1299 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1300 | path::append(currPCHPath, path::filename(Filename)); |
| 1301 | return currPCHPath.str(); |
| 1302 | } |
| 1303 | |
| 1304 | bool ASTReader::ReadSLocEntry(int ID) { |
| 1305 | if (ID == 0) |
| 1306 | return false; |
| 1307 | |
| 1308 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
| 1309 | Error("source location entry ID out-of-range for AST file"); |
| 1310 | return true; |
| 1311 | } |
| 1312 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1313 | // Local helper to read the (possibly-compressed) buffer data following the |
| 1314 | // entry record. |
| 1315 | auto ReadBuffer = [this]( |
| 1316 | BitstreamCursor &SLocEntryCursor, |
| 1317 | StringRef Name) -> std::unique_ptr<llvm::MemoryBuffer> { |
| 1318 | RecordData Record; |
| 1319 | StringRef Blob; |
| 1320 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1321 | unsigned RecCode = SLocEntryCursor.readRecord(Code, Record, &Blob); |
| 1322 | |
| 1323 | if (RecCode == SM_SLOC_BUFFER_BLOB_COMPRESSED) { |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 1324 | if (!llvm::zlib::isAvailable()) { |
| 1325 | Error("zlib is not available"); |
| 1326 | return nullptr; |
| 1327 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1328 | SmallString<0> Uncompressed; |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 1329 | if (llvm::Error E = |
| 1330 | llvm::zlib::uncompress(Blob, Uncompressed, Record[0])) { |
| 1331 | Error("could not decompress embedded file contents: " + |
| 1332 | llvm::toString(std::move(E))); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1333 | return nullptr; |
| 1334 | } |
| 1335 | return llvm::MemoryBuffer::getMemBufferCopy(Uncompressed, Name); |
| 1336 | } else if (RecCode == SM_SLOC_BUFFER_BLOB) { |
| 1337 | return llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), Name, true); |
| 1338 | } else { |
| 1339 | Error("AST record has invalid code"); |
| 1340 | return nullptr; |
| 1341 | } |
| 1342 | }; |
| 1343 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1344 | ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second; |
| 1345 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1346 | BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1347 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
| 1348 | |
| 1349 | ++NumSLocEntriesRead; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1350 | llvm::BitstreamEntry Entry = SLocEntryCursor.advance(); |
| 1351 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1352 | Error("incorrectly-formatted source location entry in AST file"); |
| 1353 | return true; |
| 1354 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1355 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1356 | RecordData Record; |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1357 | StringRef Blob; |
| 1358 | switch (SLocEntryCursor.readRecord(Entry.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1359 | default: |
| 1360 | Error("incorrectly-formatted source location entry in AST file"); |
| 1361 | return true; |
| 1362 | |
| 1363 | case SM_SLOC_FILE_ENTRY: { |
| 1364 | // We will detect whether a file changed and return 'Failure' for it, but |
| 1365 | // we will also try to fail gracefully by setting up the SLocEntry. |
| 1366 | unsigned InputID = Record[4]; |
| 1367 | InputFile IF = getInputFile(*F, InputID); |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 1368 | const FileEntry *File = IF.getFile(); |
| 1369 | bool OverriddenBuffer = IF.isOverridden(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1370 | |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 1371 | // Note that we only check if a File was returned. If it was out-of-date |
| 1372 | // we have complained but we will continue creating a FileID to recover |
| 1373 | // gracefully. |
| 1374 | if (!File) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1375 | return true; |
| 1376 | |
| 1377 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
| 1378 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
| 1379 | // This is the module's main file. |
| 1380 | IncludeLoc = getImportLocation(F); |
| 1381 | } |
| 1382 | SrcMgr::CharacteristicKind |
| 1383 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1384 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter, |
| 1385 | ID, BaseOffset + Record[0]); |
| 1386 | SrcMgr::FileInfo &FileInfo = |
| 1387 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
| 1388 | FileInfo.NumCreatedFIDs = Record[5]; |
| 1389 | if (Record[3]) |
| 1390 | FileInfo.setHasLineDirectives(); |
| 1391 | |
| 1392 | const DeclID *FirstDecl = F->FileSortedDecls + Record[6]; |
| 1393 | unsigned NumFileDecls = Record[7]; |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 1394 | if (NumFileDecls && ContextObj) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1395 | assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?"); |
| 1396 | FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl, |
| 1397 | NumFileDecls)); |
| 1398 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1399 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1400 | const SrcMgr::ContentCache *ContentCache |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1401 | = SourceMgr.getOrCreateContentCache(File, isSystem(FileCharacter)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1402 | if (OverriddenBuffer && !ContentCache->BufferOverridden && |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1403 | ContentCache->ContentsEntry == ContentCache->OrigEntry && |
| 1404 | !ContentCache->getRawBuffer()) { |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1405 | auto Buffer = ReadBuffer(SLocEntryCursor, File->getName()); |
| 1406 | if (!Buffer) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1407 | return true; |
David Blaikie | 49cc318 | 2014-08-27 20:54:45 +0000 | [diff] [blame] | 1408 | SourceMgr.overrideFileContents(File, std::move(Buffer)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | break; |
| 1412 | } |
| 1413 | |
| 1414 | case SM_SLOC_BUFFER_ENTRY: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1415 | const char *Name = Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1416 | unsigned Offset = Record[0]; |
| 1417 | SrcMgr::CharacteristicKind |
| 1418 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1419 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 1420 | if (IncludeLoc.isInvalid() && F->isModule()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1421 | IncludeLoc = getImportLocation(F); |
| 1422 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1423 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1424 | auto Buffer = ReadBuffer(SLocEntryCursor, Name); |
| 1425 | if (!Buffer) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1426 | return true; |
David Blaikie | 50a5f97 | 2014-08-29 07:59:55 +0000 | [diff] [blame] | 1427 | SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID, |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 1428 | BaseOffset + Offset, IncludeLoc); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1429 | break; |
| 1430 | } |
| 1431 | |
| 1432 | case SM_SLOC_EXPANSION_ENTRY: { |
| 1433 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
| 1434 | SourceMgr.createExpansionLoc(SpellingLoc, |
| 1435 | ReadSourceLocation(*F, Record[2]), |
| 1436 | ReadSourceLocation(*F, Record[3]), |
| 1437 | Record[4], |
| 1438 | ID, |
| 1439 | BaseOffset + Record[0]); |
| 1440 | break; |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | return false; |
| 1445 | } |
| 1446 | |
| 1447 | std::pair<SourceLocation, StringRef> ASTReader::getModuleImportLoc(int ID) { |
| 1448 | if (ID == 0) |
| 1449 | return std::make_pair(SourceLocation(), ""); |
| 1450 | |
| 1451 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
| 1452 | Error("source location entry ID out-of-range for AST file"); |
| 1453 | return std::make_pair(SourceLocation(), ""); |
| 1454 | } |
| 1455 | |
| 1456 | // Find which module file this entry lands in. |
| 1457 | ModuleFile *M = GlobalSLocEntryMap.find(-ID)->second; |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 1458 | if (!M->isModule()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1459 | return std::make_pair(SourceLocation(), ""); |
| 1460 | |
| 1461 | // FIXME: Can we map this down to a particular submodule? That would be |
| 1462 | // ideal. |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1463 | return std::make_pair(M->ImportLoc, StringRef(M->ModuleName)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | /// \brief Find the location where the module F is imported. |
| 1467 | SourceLocation ASTReader::getImportLocation(ModuleFile *F) { |
| 1468 | if (F->ImportLoc.isValid()) |
| 1469 | return F->ImportLoc; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1470 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1471 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1472 | // location of its includer. |
| 1473 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1474 | // Main file is the importer. |
Yaron Keren | 8b56366 | 2015-10-03 10:46:20 +0000 | [diff] [blame] | 1475 | assert(SourceMgr.getMainFileID().isValid() && "missing main file"); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1476 | return SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1477 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1478 | return F->ImportedBy[0]->FirstLoc; |
| 1479 | } |
| 1480 | |
| 1481 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1482 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1483 | /// and then leave the cursor pointing into the block. |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1484 | bool ASTReader::ReadBlockAbbrevs(BitstreamCursor &Cursor, unsigned BlockID) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1485 | if (Cursor.EnterSubBlock(BlockID)) |
| 1486 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1487 | |
| 1488 | while (true) { |
| 1489 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
| 1490 | unsigned Code = Cursor.ReadCode(); |
| 1491 | |
| 1492 | // We expect all abbrevs to be at the start of the block. |
| 1493 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1494 | Cursor.JumpToBit(Offset); |
| 1495 | return false; |
| 1496 | } |
| 1497 | Cursor.ReadAbbrevRecord(); |
| 1498 | } |
| 1499 | } |
| 1500 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 1501 | Token ASTReader::ReadToken(ModuleFile &F, const RecordDataImpl &Record, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1502 | unsigned &Idx) { |
| 1503 | Token Tok; |
| 1504 | Tok.startToken(); |
| 1505 | Tok.setLocation(ReadSourceLocation(F, Record, Idx)); |
| 1506 | Tok.setLength(Record[Idx++]); |
| 1507 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[Idx++])) |
| 1508 | Tok.setIdentifierInfo(II); |
| 1509 | Tok.setKind((tok::TokenKind)Record[Idx++]); |
| 1510 | Tok.setFlag((Token::TokenFlags)Record[Idx++]); |
| 1511 | return Tok; |
| 1512 | } |
| 1513 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1514 | MacroInfo *ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1515 | BitstreamCursor &Stream = F.MacroCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1516 | |
| 1517 | // Keep track of where we are in the stream, then jump back there |
| 1518 | // after reading this macro. |
| 1519 | SavedStreamPosition SavedPosition(Stream); |
| 1520 | |
| 1521 | Stream.JumpToBit(Offset); |
| 1522 | RecordData Record; |
Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame] | 1523 | SmallVector<IdentifierInfo*, 16> MacroParams; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1524 | MacroInfo *Macro = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1525 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1526 | while (true) { |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1527 | // Advance to the next record, but if we get to the end of the block, don't |
| 1528 | // pop it (removing all the abbreviations from the cursor) since we want to |
| 1529 | // be able to reseek within the block and read entries. |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1530 | unsigned Flags = BitstreamCursor::AF_DontPopBlockAtEnd; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1531 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(Flags); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1532 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1533 | switch (Entry.Kind) { |
| 1534 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1535 | case llvm::BitstreamEntry::Error: |
| 1536 | Error("malformed block record in AST file"); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1537 | return Macro; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1538 | case llvm::BitstreamEntry::EndBlock: |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1539 | return Macro; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1540 | case llvm::BitstreamEntry::Record: |
| 1541 | // The interesting case. |
| 1542 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | // Read a record. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1546 | Record.clear(); |
| 1547 | PreprocessorRecordTypes RecType = |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1548 | (PreprocessorRecordTypes)Stream.readRecord(Entry.ID, Record); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1549 | switch (RecType) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1550 | case PP_MODULE_MACRO: |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1551 | case PP_MACRO_DIRECTIVE_HISTORY: |
| 1552 | return Macro; |
| 1553 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1554 | case PP_MACRO_OBJECT_LIKE: |
| 1555 | case PP_MACRO_FUNCTION_LIKE: { |
| 1556 | // If we already have a macro, that means that we've hit the end |
| 1557 | // of the definition of the macro we were looking for. We're |
| 1558 | // done. |
| 1559 | if (Macro) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1560 | return Macro; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1561 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1562 | unsigned NextIndex = 1; // Skip identifier ID. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1563 | SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex); |
Richard Smith | 3f6dd7a | 2017-05-12 23:40:52 +0000 | [diff] [blame] | 1564 | MacroInfo *MI = PP.AllocateMacroInfo(Loc); |
Argyrios Kyrtzidis | 7572be2 | 2013-01-07 19:16:23 +0000 | [diff] [blame] | 1565 | MI->setDefinitionEndLoc(ReadSourceLocation(F, Record, NextIndex)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1566 | MI->setIsUsed(Record[NextIndex++]); |
Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 1567 | MI->setUsedForHeaderGuard(Record[NextIndex++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1568 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1569 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
| 1570 | // Decode function-like macro info. |
| 1571 | bool isC99VarArgs = Record[NextIndex++]; |
| 1572 | bool isGNUVarArgs = Record[NextIndex++]; |
| 1573 | bool hasCommaPasting = Record[NextIndex++]; |
Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame] | 1574 | MacroParams.clear(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1575 | unsigned NumArgs = Record[NextIndex++]; |
| 1576 | for (unsigned i = 0; i != NumArgs; ++i) |
Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame] | 1577 | MacroParams.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1578 | |
| 1579 | // Install function-like macro info. |
| 1580 | MI->setIsFunctionLike(); |
| 1581 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1582 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
| 1583 | if (hasCommaPasting) MI->setHasCommaPasting(); |
Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame] | 1584 | MI->setParameterList(MacroParams, PP.getPreprocessorAllocator()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1587 | // Remember that we saw this macro last so that we add the tokens that |
| 1588 | // form its body to it. |
| 1589 | Macro = MI; |
| 1590 | |
| 1591 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() && |
| 1592 | Record[NextIndex]) { |
| 1593 | // We have a macro definition. Register the association |
| 1594 | PreprocessedEntityID |
| 1595 | GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]); |
| 1596 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 1597 | PreprocessingRecord::PPEntityID PPID = |
| 1598 | PPRec.getPPEntityID(GlobalID - 1, /*isLoaded=*/true); |
| 1599 | MacroDefinitionRecord *PPDef = cast_or_null<MacroDefinitionRecord>( |
| 1600 | PPRec.getPreprocessedEntity(PPID)); |
Argyrios Kyrtzidis | 832de9f | 2013-02-22 18:35:59 +0000 | [diff] [blame] | 1601 | if (PPDef) |
| 1602 | PPRec.RegisterMacroDefinition(Macro, PPDef); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | ++NumMacrosRead; |
| 1606 | break; |
| 1607 | } |
| 1608 | |
| 1609 | case PP_TOKEN: { |
| 1610 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1611 | // erroneous, just pretend we didn't see this. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1612 | if (!Macro) break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1613 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1614 | unsigned Idx = 0; |
| 1615 | Token Tok = ReadToken(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1616 | Macro->AddTokenToBody(Tok); |
| 1617 | break; |
| 1618 | } |
| 1619 | } |
| 1620 | } |
| 1621 | } |
| 1622 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1623 | PreprocessedEntityID |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 1624 | ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M, |
| 1625 | unsigned LocalID) const { |
| 1626 | if (!M.ModuleOffsetMap.empty()) |
| 1627 | ReadModuleOffsetMap(M); |
| 1628 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1629 | ContinuousRangeMap<uint32_t, int, 2>::const_iterator |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1630 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1631 | assert(I != M.PreprocessedEntityRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1632 | && "Invalid index into preprocessed entity index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1633 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1634 | return LocalID + I->second; |
| 1635 | } |
| 1636 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1637 | unsigned HeaderFileInfoTrait::ComputeHash(internal_key_ref ikey) { |
| 1638 | return llvm::hash_combine(ikey.Size, ikey.ModTime); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1639 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1640 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1641 | HeaderFileInfoTrait::internal_key_type |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1642 | HeaderFileInfoTrait::GetInternalKey(const FileEntry *FE) { |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1643 | internal_key_type ikey = {FE->getSize(), |
| 1644 | M.HasTimestamps ? FE->getModificationTime() : 0, |
| 1645 | FE->getName(), /*Imported*/ false}; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1646 | return ikey; |
| 1647 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1648 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1649 | bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) { |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1650 | if (a.Size != b.Size || (a.ModTime && b.ModTime && a.ModTime != b.ModTime)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1651 | return false; |
| 1652 | |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1653 | if (llvm::sys::path::is_absolute(a.Filename) && a.Filename == b.Filename) |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1654 | return true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1655 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1656 | // Determine whether the actual files are equivalent. |
Argyrios Kyrtzidis | 2a513e8 | 2013-03-04 20:33:40 +0000 | [diff] [blame] | 1657 | FileManager &FileMgr = Reader.getFileManager(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1658 | auto GetFile = [&](const internal_key_type &Key) -> const FileEntry* { |
| 1659 | if (!Key.Imported) |
| 1660 | return FileMgr.getFile(Key.Filename); |
| 1661 | |
| 1662 | std::string Resolved = Key.Filename; |
| 1663 | Reader.ResolveImportedPath(M, Resolved); |
| 1664 | return FileMgr.getFile(Resolved); |
| 1665 | }; |
| 1666 | |
| 1667 | const FileEntry *FEA = GetFile(a); |
| 1668 | const FileEntry *FEB = GetFile(b); |
| 1669 | return FEA && FEA == FEB; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1670 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1671 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1672 | std::pair<unsigned, unsigned> |
| 1673 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1674 | using namespace llvm::support; |
| 1675 | unsigned KeyLen = (unsigned) endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1676 | unsigned DataLen = (unsigned) *d++; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1677 | return std::make_pair(KeyLen, DataLen); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1678 | } |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1679 | |
| 1680 | HeaderFileInfoTrait::internal_key_type |
| 1681 | HeaderFileInfoTrait::ReadKey(const unsigned char *d, unsigned) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1682 | using namespace llvm::support; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1683 | internal_key_type ikey; |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1684 | ikey.Size = off_t(endian::readNext<uint64_t, little, unaligned>(d)); |
| 1685 | ikey.ModTime = time_t(endian::readNext<uint64_t, little, unaligned>(d)); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1686 | ikey.Filename = (const char *)d; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1687 | ikey.Imported = true; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1688 | return ikey; |
| 1689 | } |
| 1690 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1691 | HeaderFileInfoTrait::data_type |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1692 | HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1693 | unsigned DataLen) { |
| 1694 | const unsigned char *End = d + DataLen; |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1695 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1696 | HeaderFileInfo HFI; |
| 1697 | unsigned Flags = *d++; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1698 | // FIXME: Refactor with mergeHeaderFileInfo in HeaderSearch.cpp. |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1699 | HFI.isImport |= (Flags >> 5) & 0x01; |
| 1700 | HFI.isPragmaOnce |= (Flags >> 4) & 0x01; |
| 1701 | HFI.DirInfo = (Flags >> 1) & 0x07; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1702 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1703 | // FIXME: Find a better way to handle this. Maybe just store a |
| 1704 | // "has been included" flag? |
| 1705 | HFI.NumIncludes = std::max(endian::readNext<uint16_t, little, unaligned>(d), |
| 1706 | HFI.NumIncludes); |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1707 | HFI.ControllingMacroID = Reader.getGlobalIdentifierID( |
| 1708 | M, endian::readNext<uint32_t, little, unaligned>(d)); |
| 1709 | if (unsigned FrameworkOffset = |
| 1710 | endian::readNext<uint32_t, little, unaligned>(d)) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1711 | // The framework offset is 1 greater than the actual offset, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1712 | // since 0 is used as an indicator for "no framework name". |
| 1713 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1714 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1715 | } |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1716 | |
| 1717 | assert((End - d) % 4 == 0 && |
| 1718 | "Wrong data length in HeaderFileInfo deserialization"); |
| 1719 | while (d != End) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1720 | uint32_t LocalSMID = endian::readNext<uint32_t, little, unaligned>(d); |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1721 | auto HeaderRole = static_cast<ModuleMap::ModuleHeaderRole>(LocalSMID & 3); |
| 1722 | LocalSMID >>= 2; |
| 1723 | |
| 1724 | // This header is part of a module. Associate it with the module to enable |
| 1725 | // implicit module import. |
| 1726 | SubmoduleID GlobalSMID = Reader.getGlobalSubmoduleID(M, LocalSMID); |
| 1727 | Module *Mod = Reader.getSubmodule(GlobalSMID); |
| 1728 | FileManager &FileMgr = Reader.getFileManager(); |
| 1729 | ModuleMap &ModMap = |
| 1730 | Reader.getPreprocessor().getHeaderSearchInfo().getModuleMap(); |
| 1731 | |
| 1732 | std::string Filename = key.Filename; |
| 1733 | if (key.Imported) |
| 1734 | Reader.ResolveImportedPath(M, Filename); |
| 1735 | // FIXME: This is not always the right filename-as-written, but we're not |
| 1736 | // going to use this information to rebuild the module, so it doesn't make |
| 1737 | // a lot of difference. |
| 1738 | Module::Header H = { key.Filename, FileMgr.getFile(Filename) }; |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1739 | ModMap.addHeader(Mod, H, HeaderRole, /*Imported*/true); |
| 1740 | HFI.isModuleHeader |= !(HeaderRole & ModuleMap::TextualHeader); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1743 | // This HeaderFileInfo was externally loaded. |
| 1744 | HFI.External = true; |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1745 | HFI.IsValid = true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1746 | return HFI; |
| 1747 | } |
| 1748 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1749 | void ASTReader::addPendingMacro(IdentifierInfo *II, |
| 1750 | ModuleFile *M, |
| 1751 | uint64_t MacroDirectivesOffset) { |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1752 | assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard"); |
| 1753 | PendingMacroIDs[II].push_back(PendingMacroInfo(M, MacroDirectivesOffset)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | void ASTReader::ReadDefinedMacros() { |
| 1757 | // Note that we are loading defined macros. |
| 1758 | Deserializing Macros(this); |
| 1759 | |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1760 | for (ModuleFile &I : llvm::reverse(ModuleMgr)) { |
| 1761 | BitstreamCursor &MacroCursor = I.MacroCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1762 | |
| 1763 | // If there was no preprocessor block, skip this file. |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 1764 | if (MacroCursor.getBitcodeBytes().empty()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1765 | continue; |
| 1766 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1767 | BitstreamCursor Cursor = MacroCursor; |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1768 | Cursor.JumpToBit(I.MacroStartOffset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1769 | |
| 1770 | RecordData Record; |
| 1771 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1772 | llvm::BitstreamEntry E = Cursor.advanceSkippingSubblocks(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1773 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1774 | switch (E.Kind) { |
| 1775 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1776 | case llvm::BitstreamEntry::Error: |
| 1777 | Error("malformed block record in AST file"); |
| 1778 | return; |
| 1779 | case llvm::BitstreamEntry::EndBlock: |
| 1780 | goto NextCursor; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1781 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1782 | case llvm::BitstreamEntry::Record: |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1783 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1784 | switch (Cursor.readRecord(E.ID, Record)) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1785 | default: // Default behavior: ignore. |
| 1786 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1787 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1788 | case PP_MACRO_OBJECT_LIKE: |
Sean Callanan | f3682a7 | 2016-05-14 06:24:14 +0000 | [diff] [blame] | 1789 | case PP_MACRO_FUNCTION_LIKE: { |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1790 | IdentifierInfo *II = getLocalIdentifier(I, Record[0]); |
Sean Callanan | f3682a7 | 2016-05-14 06:24:14 +0000 | [diff] [blame] | 1791 | if (II->isOutOfDate()) |
| 1792 | updateOutOfDateIdentifier(*II); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1793 | break; |
Sean Callanan | f3682a7 | 2016-05-14 06:24:14 +0000 | [diff] [blame] | 1794 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1795 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1796 | case PP_TOKEN: |
| 1797 | // Ignore tokens. |
| 1798 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1799 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1800 | break; |
| 1801 | } |
| 1802 | } |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1803 | NextCursor: ; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1808 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1809 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 1810 | class IdentifierLookupVisitor { |
| 1811 | StringRef Name; |
Richard Smith | 3b63741 | 2015-07-14 18:42:41 +0000 | [diff] [blame] | 1812 | unsigned NameHash; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1813 | unsigned PriorGeneration; |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1814 | unsigned &NumIdentifierLookups; |
| 1815 | unsigned &NumIdentifierLookupHits; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1816 | IdentifierInfo *Found; |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1817 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1818 | public: |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1819 | IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration, |
| 1820 | unsigned &NumIdentifierLookups, |
| 1821 | unsigned &NumIdentifierLookupHits) |
Richard Smith | 3b63741 | 2015-07-14 18:42:41 +0000 | [diff] [blame] | 1822 | : Name(Name), NameHash(ASTIdentifierLookupTrait::ComputeHash(Name)), |
| 1823 | PriorGeneration(PriorGeneration), |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1824 | NumIdentifierLookups(NumIdentifierLookups), |
| 1825 | NumIdentifierLookupHits(NumIdentifierLookupHits), |
| 1826 | Found() |
| 1827 | { |
| 1828 | } |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 1829 | |
| 1830 | bool operator()(ModuleFile &M) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1831 | // If we've already searched this module file, skip it now. |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1832 | if (M.Generation <= PriorGeneration) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1833 | return true; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1834 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1835 | ASTIdentifierLookupTable *IdTable |
| 1836 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 1837 | if (!IdTable) |
| 1838 | return false; |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 1839 | |
| 1840 | ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), M, |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1841 | Found); |
| 1842 | ++NumIdentifierLookups; |
Richard Smith | 3b63741 | 2015-07-14 18:42:41 +0000 | [diff] [blame] | 1843 | ASTIdentifierLookupTable::iterator Pos = |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1844 | IdTable->find_hashed(Name, NameHash, &Trait); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1845 | if (Pos == IdTable->end()) |
| 1846 | return false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1847 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1848 | // Dereferencing the iterator has the effect of building the |
| 1849 | // IdentifierInfo node and populating it with the various |
| 1850 | // declarations it needs. |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1851 | ++NumIdentifierLookupHits; |
| 1852 | Found = *Pos; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1853 | return true; |
| 1854 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1855 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1856 | // \brief Retrieve the identifier info found within the module |
| 1857 | // files. |
| 1858 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 1859 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1860 | |
| 1861 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1862 | |
| 1863 | void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { |
| 1864 | // Note that we are loading an identifier. |
| 1865 | Deserializing AnIdentifier(this); |
| 1866 | |
| 1867 | unsigned PriorGeneration = 0; |
| 1868 | if (getContext().getLangOpts().Modules) |
| 1869 | PriorGeneration = IdentifierGeneration[&II]; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1870 | |
| 1871 | // If there is a global index, look there first to determine which modules |
| 1872 | // provably do not have any results for this identifier. |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1873 | GlobalModuleIndex::HitSet Hits; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1874 | GlobalModuleIndex::HitSet *HitsPtr = nullptr; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1875 | if (!loadGlobalIndex()) { |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1876 | if (GlobalIndex->lookupIdentifier(II.getName(), Hits)) { |
| 1877 | HitsPtr = &Hits; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1878 | } |
| 1879 | } |
| 1880 | |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1881 | IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration, |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1882 | NumIdentifierLookups, |
| 1883 | NumIdentifierLookupHits); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 1884 | ModuleMgr.visit(Visitor, HitsPtr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1885 | markIdentifierUpToDate(&II); |
| 1886 | } |
| 1887 | |
| 1888 | void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { |
| 1889 | if (!II) |
| 1890 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1891 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1892 | II->setOutOfDate(false); |
| 1893 | |
| 1894 | // Update the generation for this identifier. |
| 1895 | if (getContext().getLangOpts().Modules) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1896 | IdentifierGeneration[II] = getGeneration(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1899 | void ASTReader::resolvePendingMacro(IdentifierInfo *II, |
| 1900 | const PendingMacroInfo &PMInfo) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1901 | ModuleFile &M = *PMInfo.M; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1902 | |
| 1903 | BitstreamCursor &Cursor = M.MacroCursor; |
| 1904 | SavedStreamPosition SavedPosition(Cursor); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1905 | Cursor.JumpToBit(PMInfo.MacroDirectivesOffset); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1906 | |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1907 | struct ModuleMacroRecord { |
| 1908 | SubmoduleID SubModID; |
| 1909 | MacroInfo *MI; |
| 1910 | SmallVector<SubmoduleID, 8> Overrides; |
| 1911 | }; |
| 1912 | llvm::SmallVector<ModuleMacroRecord, 8> ModuleMacros; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1913 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1914 | // We expect to see a sequence of PP_MODULE_MACRO records listing exported |
| 1915 | // macros, followed by a PP_MACRO_DIRECTIVE_HISTORY record with the complete |
| 1916 | // macro histroy. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1917 | RecordData Record; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1918 | while (true) { |
| 1919 | llvm::BitstreamEntry Entry = |
| 1920 | Cursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd); |
| 1921 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| 1922 | Error("malformed block record in AST file"); |
| 1923 | return; |
| 1924 | } |
| 1925 | |
| 1926 | Record.clear(); |
Aaron Ballman | c75a192 | 2015-04-22 15:25:05 +0000 | [diff] [blame] | 1927 | switch ((PreprocessorRecordTypes)Cursor.readRecord(Entry.ID, Record)) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1928 | case PP_MACRO_DIRECTIVE_HISTORY: |
| 1929 | break; |
| 1930 | |
| 1931 | case PP_MODULE_MACRO: { |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1932 | ModuleMacros.push_back(ModuleMacroRecord()); |
| 1933 | auto &Info = ModuleMacros.back(); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1934 | Info.SubModID = getGlobalSubmoduleID(M, Record[0]); |
| 1935 | Info.MI = getMacro(getGlobalMacroID(M, Record[1])); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1936 | for (int I = 2, N = Record.size(); I != N; ++I) |
| 1937 | Info.Overrides.push_back(getGlobalSubmoduleID(M, Record[I])); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1938 | continue; |
| 1939 | } |
| 1940 | |
| 1941 | default: |
| 1942 | Error("malformed block record in AST file"); |
| 1943 | return; |
| 1944 | } |
| 1945 | |
| 1946 | // We found the macro directive history; that's the last record |
| 1947 | // for this macro. |
| 1948 | break; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1949 | } |
| 1950 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1951 | // Module macros are listed in reverse dependency order. |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1952 | { |
| 1953 | std::reverse(ModuleMacros.begin(), ModuleMacros.end()); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1954 | llvm::SmallVector<ModuleMacro*, 8> Overrides; |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1955 | for (auto &MMR : ModuleMacros) { |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1956 | Overrides.clear(); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1957 | for (unsigned ModID : MMR.Overrides) { |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 1958 | Module *Mod = getSubmodule(ModID); |
| 1959 | auto *Macro = PP.getModuleMacro(Mod, II); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1960 | assert(Macro && "missing definition for overridden macro"); |
Richard Smith | 5dbef92 | 2015-04-22 02:09:43 +0000 | [diff] [blame] | 1961 | Overrides.push_back(Macro); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | bool Inserted = false; |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1965 | Module *Owner = getSubmodule(MMR.SubModID); |
Richard Smith | 20e883e | 2015-04-29 23:20:19 +0000 | [diff] [blame] | 1966 | PP.addModuleMacro(Owner, II, MMR.MI, Overrides, Inserted); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1967 | } |
| 1968 | } |
| 1969 | |
| 1970 | // Don't read the directive history for a module; we don't have anywhere |
| 1971 | // to put it. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 1972 | if (M.isModule()) |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1973 | return; |
| 1974 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1975 | // Deserialize the macro directives history in reverse source-order. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1976 | MacroDirective *Latest = nullptr, *Earliest = nullptr; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1977 | unsigned Idx = 0, N = Record.size(); |
| 1978 | while (Idx < N) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1979 | MacroDirective *MD = nullptr; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1980 | SourceLocation Loc = ReadSourceLocation(M, Record, Idx); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1981 | MacroDirective::Kind K = (MacroDirective::Kind)Record[Idx++]; |
| 1982 | switch (K) { |
| 1983 | case MacroDirective::MD_Define: { |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1984 | MacroInfo *MI = getMacro(getGlobalMacroID(M, Record[Idx++])); |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 1985 | MD = PP.AllocateDefMacroDirective(MI, Loc); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1986 | break; |
| 1987 | } |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 1988 | case MacroDirective::MD_Undefine: { |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 1989 | MD = PP.AllocateUndefMacroDirective(Loc); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1990 | break; |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 1991 | } |
| 1992 | case MacroDirective::MD_Visibility: |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1993 | bool isPublic = Record[Idx++]; |
| 1994 | MD = PP.AllocateVisibilityMacroDirective(Loc, isPublic); |
| 1995 | break; |
| 1996 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1997 | |
| 1998 | if (!Latest) |
| 1999 | Latest = MD; |
| 2000 | if (Earliest) |
| 2001 | Earliest->setPrevious(MD); |
| 2002 | Earliest = MD; |
| 2003 | } |
| 2004 | |
Richard Smith | d6e8c0d | 2015-05-04 19:58:00 +0000 | [diff] [blame] | 2005 | if (Latest) |
Nico Weber | fd87070 | 2016-12-09 17:32:52 +0000 | [diff] [blame] | 2006 | PP.setLoadedMacroDirective(II, Earliest, Latest); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2007 | } |
| 2008 | |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 2009 | ASTReader::InputFileInfo |
| 2010 | ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) { |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2011 | // Go find this input file. |
| 2012 | BitstreamCursor &Cursor = F.InputFilesCursor; |
| 2013 | SavedStreamPosition SavedPosition(Cursor); |
| 2014 | Cursor.JumpToBit(F.InputFileOffsets[ID-1]); |
| 2015 | |
| 2016 | unsigned Code = Cursor.ReadCode(); |
| 2017 | RecordData Record; |
| 2018 | StringRef Blob; |
| 2019 | |
| 2020 | unsigned Result = Cursor.readRecord(Code, Record, &Blob); |
| 2021 | assert(static_cast<InputFileRecordTypes>(Result) == INPUT_FILE && |
| 2022 | "invalid record type for input file"); |
| 2023 | (void)Result; |
| 2024 | |
| 2025 | assert(Record[0] == ID && "Bogus stored ID or offset"); |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2026 | InputFileInfo R; |
| 2027 | R.StoredSize = static_cast<off_t>(Record[1]); |
| 2028 | R.StoredTime = static_cast<time_t>(Record[2]); |
| 2029 | R.Overridden = static_cast<bool>(Record[3]); |
| 2030 | R.Transient = static_cast<bool>(Record[4]); |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 2031 | R.TopLevelModuleMap = static_cast<bool>(Record[5]); |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2032 | R.Filename = Blob; |
| 2033 | ResolveImportedPath(F, R.Filename); |
Hans Wennborg | 7394514 | 2014-03-14 17:45:06 +0000 | [diff] [blame] | 2034 | return R; |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
Manman Ren | c8c9415 | 2016-10-21 23:35:03 +0000 | [diff] [blame] | 2037 | static unsigned moduleKindForDiagnostic(ModuleKind Kind); |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2038 | InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2039 | // If this ID is bogus, just return an empty input file. |
| 2040 | if (ID == 0 || ID > F.InputFilesLoaded.size()) |
| 2041 | return InputFile(); |
| 2042 | |
| 2043 | // If we've already loaded this input file, return it. |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2044 | if (F.InputFilesLoaded[ID-1].getFile()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2045 | return F.InputFilesLoaded[ID-1]; |
| 2046 | |
Argyrios Kyrtzidis | 9308f0a | 2014-01-08 19:13:34 +0000 | [diff] [blame] | 2047 | if (F.InputFilesLoaded[ID-1].isNotFound()) |
| 2048 | return InputFile(); |
| 2049 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2050 | // Go find this input file. |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2051 | BitstreamCursor &Cursor = F.InputFilesCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2052 | SavedStreamPosition SavedPosition(Cursor); |
| 2053 | Cursor.JumpToBit(F.InputFileOffsets[ID-1]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2054 | |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 2055 | InputFileInfo FI = readInputFileInfo(F, ID); |
| 2056 | off_t StoredSize = FI.StoredSize; |
| 2057 | time_t StoredTime = FI.StoredTime; |
| 2058 | bool Overridden = FI.Overridden; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2059 | bool Transient = FI.Transient; |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 2060 | StringRef Filename = FI.Filename; |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2061 | |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2062 | const FileEntry *File = FileMgr.getFile(Filename, /*OpenFile=*/false); |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2063 | // If we didn't find the file, resolve it relative to the |
| 2064 | // original directory from which this AST file was created. |
Manuel Klimek | 1b29b4f | 2017-07-25 10:22:06 +0000 | [diff] [blame] | 2065 | if (File == nullptr && !F.OriginalDir.empty() && !F.BaseDirectory.empty() && |
| 2066 | F.OriginalDir != F.BaseDirectory) { |
| 2067 | std::string Resolved = resolveFileRelativeToOriginalDir( |
| 2068 | Filename, F.OriginalDir, F.BaseDirectory); |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2069 | if (!Resolved.empty()) |
| 2070 | File = FileMgr.getFile(Resolved); |
| 2071 | } |
| 2072 | |
| 2073 | // For an overridden file, create a virtual file with the stored |
| 2074 | // size/timestamp. |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2075 | if ((Overridden || Transient) && File == nullptr) |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2076 | File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime); |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2077 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 2078 | if (File == nullptr) { |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2079 | if (Complain) { |
| 2080 | std::string ErrorStr = "could not find file '"; |
| 2081 | ErrorStr += Filename; |
Richard Smith | 6814221 | 2015-10-13 01:26:26 +0000 | [diff] [blame] | 2082 | ErrorStr += "' referenced by AST file '"; |
| 2083 | ErrorStr += F.FileName; |
| 2084 | ErrorStr += "'"; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2085 | Error(ErrorStr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2086 | } |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2087 | // Record that we didn't find the file. |
| 2088 | F.InputFilesLoaded[ID-1] = InputFile::getNotFound(); |
| 2089 | return InputFile(); |
| 2090 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2091 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2092 | // Check if there was a request to override the contents of the file |
| 2093 | // that was part of the precompiled header. Overridding such a file |
| 2094 | // can lead to problems when lexing using the source locations from the |
| 2095 | // PCH. |
| 2096 | SourceManager &SM = getSourceManager(); |
Richard Smith | 64daf7b | 2015-12-01 03:32:49 +0000 | [diff] [blame] | 2097 | // FIXME: Reject if the overrides are different. |
| 2098 | if ((!Overridden && !Transient) && SM.isFileOverridden(File)) { |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2099 | if (Complain) |
| 2100 | Error(diag::err_fe_pch_file_overridden, Filename); |
| 2101 | // After emitting the diagnostic, recover by disabling the override so |
| 2102 | // that the original file will be used. |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2103 | // |
| 2104 | // FIXME: This recovery is just as broken as the original state; there may |
| 2105 | // be another precompiled module that's using the overridden contents, or |
| 2106 | // we might be half way through parsing it. Instead, we should treat the |
| 2107 | // overridden contents as belonging to a separate FileEntry. |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2108 | SM.disableFileContentsOverride(File); |
| 2109 | // The FileEntry is a virtual file entry with the size of the contents |
| 2110 | // that would override the original contents. Set it to the original's |
| 2111 | // size/time. |
| 2112 | FileMgr.modifyFileEntry(const_cast<FileEntry*>(File), |
| 2113 | StoredSize, StoredTime); |
| 2114 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2115 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2116 | bool IsOutOfDate = false; |
| 2117 | |
| 2118 | // For an overridden file, there is nothing to validate. |
Richard Smith | 96fdab6 | 2014-10-28 16:24:08 +0000 | [diff] [blame] | 2119 | if (!Overridden && // |
| 2120 | (StoredSize != File->getSize() || |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 2121 | (StoredTime && StoredTime != File->getModificationTime() && |
| 2122 | !DisableValidation) |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2123 | )) { |
| 2124 | if (Complain) { |
| 2125 | // Build a list of the PCH imports that got us here (in reverse). |
| 2126 | SmallVector<ModuleFile *, 4> ImportStack(1, &F); |
| 2127 | while (ImportStack.back()->ImportedBy.size() > 0) |
| 2128 | ImportStack.push_back(ImportStack.back()->ImportedBy[0]); |
Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 2129 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2130 | // The top-level PCH is stale. |
| 2131 | StringRef TopLevelPCHName(ImportStack.back()->FileName); |
Manman Ren | c8c9415 | 2016-10-21 23:35:03 +0000 | [diff] [blame] | 2132 | unsigned DiagnosticKind = moduleKindForDiagnostic(ImportStack.back()->Kind); |
| 2133 | if (DiagnosticKind == 0) |
| 2134 | Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName); |
| 2135 | else if (DiagnosticKind == 1) |
| 2136 | Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName); |
| 2137 | else |
| 2138 | Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName); |
Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 2139 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2140 | // Print the import stack. |
| 2141 | if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) { |
| 2142 | Diag(diag::note_pch_required_by) |
| 2143 | << Filename << ImportStack[0]->FileName; |
| 2144 | for (unsigned I = 1; I < ImportStack.size(); ++I) |
Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 2145 | Diag(diag::note_pch_required_by) |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2146 | << ImportStack[I-1]->FileName << ImportStack[I]->FileName; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 2147 | } |
| 2148 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2149 | if (!Diags.isDiagnosticInFlight()) |
| 2150 | Diag(diag::note_pch_rebuild_required) << TopLevelPCHName; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2153 | IsOutOfDate = true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2154 | } |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2155 | // FIXME: If the file is overridden and we've already opened it, |
| 2156 | // issue an error (or split it into a separate FileEntry). |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2157 | |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2158 | InputFile IF = InputFile(File, Overridden || Transient, IsOutOfDate); |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2159 | |
| 2160 | // Note that we've loaded this input file. |
| 2161 | F.InputFilesLoaded[ID-1] = IF; |
| 2162 | return IF; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2163 | } |
| 2164 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2165 | /// \brief If we are loading a relocatable PCH or module file, and the filename |
| 2166 | /// is not an absolute path, add the system or module root to the beginning of |
| 2167 | /// the file name. |
| 2168 | void ASTReader::ResolveImportedPath(ModuleFile &M, std::string &Filename) { |
| 2169 | // Resolve relative to the base directory, if we have one. |
| 2170 | if (!M.BaseDirectory.empty()) |
| 2171 | return ResolveImportedPath(Filename, M.BaseDirectory); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2172 | } |
| 2173 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2174 | void ASTReader::ResolveImportedPath(std::string &Filename, StringRef Prefix) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2175 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
| 2176 | return; |
| 2177 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2178 | SmallString<128> Buffer; |
| 2179 | llvm::sys::path::append(Buffer, Prefix, Filename); |
| 2180 | Filename.assign(Buffer.begin(), Buffer.end()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2181 | } |
| 2182 | |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2183 | static bool isDiagnosedResult(ASTReader::ASTReadResult ARR, unsigned Caps) { |
| 2184 | switch (ARR) { |
| 2185 | case ASTReader::Failure: return true; |
| 2186 | case ASTReader::Missing: return !(Caps & ASTReader::ARR_Missing); |
| 2187 | case ASTReader::OutOfDate: return !(Caps & ASTReader::ARR_OutOfDate); |
| 2188 | case ASTReader::VersionMismatch: return !(Caps & ASTReader::ARR_VersionMismatch); |
| 2189 | case ASTReader::ConfigurationMismatch: |
| 2190 | return !(Caps & ASTReader::ARR_ConfigurationMismatch); |
| 2191 | case ASTReader::HadErrors: return true; |
| 2192 | case ASTReader::Success: return false; |
| 2193 | } |
| 2194 | |
| 2195 | llvm_unreachable("unknown ASTReadResult"); |
| 2196 | } |
| 2197 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2198 | ASTReader::ASTReadResult ASTReader::ReadOptionsBlock( |
| 2199 | BitstreamCursor &Stream, unsigned ClientLoadCapabilities, |
| 2200 | bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener, |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2201 | std::string &SuggestedPredefines) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2202 | if (Stream.EnterSubBlock(OPTIONS_BLOCK_ID)) |
| 2203 | return Failure; |
| 2204 | |
| 2205 | // Read all of the records in the options block. |
| 2206 | RecordData Record; |
| 2207 | ASTReadResult Result = Success; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2208 | while (true) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2209 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2210 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2211 | switch (Entry.Kind) { |
| 2212 | case llvm::BitstreamEntry::Error: |
| 2213 | case llvm::BitstreamEntry::SubBlock: |
| 2214 | return Failure; |
| 2215 | |
| 2216 | case llvm::BitstreamEntry::EndBlock: |
| 2217 | return Result; |
| 2218 | |
| 2219 | case llvm::BitstreamEntry::Record: |
| 2220 | // The interesting case. |
| 2221 | break; |
| 2222 | } |
| 2223 | |
| 2224 | // Read and process a record. |
| 2225 | Record.clear(); |
| 2226 | switch ((OptionsRecordTypes)Stream.readRecord(Entry.ID, Record)) { |
| 2227 | case LANGUAGE_OPTIONS: { |
| 2228 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2229 | if (ParseLanguageOptions(Record, Complain, Listener, |
| 2230 | AllowCompatibleConfigurationMismatch)) |
| 2231 | Result = ConfigurationMismatch; |
| 2232 | break; |
| 2233 | } |
| 2234 | |
| 2235 | case TARGET_OPTIONS: { |
| 2236 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2237 | if (ParseTargetOptions(Record, Complain, Listener, |
| 2238 | AllowCompatibleConfigurationMismatch)) |
| 2239 | Result = ConfigurationMismatch; |
| 2240 | break; |
| 2241 | } |
| 2242 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2243 | case FILE_SYSTEM_OPTIONS: { |
| 2244 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2245 | if (!AllowCompatibleConfigurationMismatch && |
| 2246 | ParseFileSystemOptions(Record, Complain, Listener)) |
| 2247 | Result = ConfigurationMismatch; |
| 2248 | break; |
| 2249 | } |
| 2250 | |
| 2251 | case HEADER_SEARCH_OPTIONS: { |
| 2252 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2253 | if (!AllowCompatibleConfigurationMismatch && |
| 2254 | ParseHeaderSearchOptions(Record, Complain, Listener)) |
| 2255 | Result = ConfigurationMismatch; |
| 2256 | break; |
| 2257 | } |
| 2258 | |
| 2259 | case PREPROCESSOR_OPTIONS: |
| 2260 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2261 | if (!AllowCompatibleConfigurationMismatch && |
| 2262 | ParsePreprocessorOptions(Record, Complain, Listener, |
| 2263 | SuggestedPredefines)) |
| 2264 | Result = ConfigurationMismatch; |
| 2265 | break; |
| 2266 | } |
| 2267 | } |
| 2268 | } |
| 2269 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2270 | ASTReader::ASTReadResult |
| 2271 | ASTReader::ReadControlBlock(ModuleFile &F, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2272 | SmallVectorImpl<ImportedModule> &Loaded, |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2273 | const ModuleFile *ImportedBy, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2274 | unsigned ClientLoadCapabilities) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2275 | BitstreamCursor &Stream = F.Stream; |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2276 | ASTReadResult Result = Success; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2277 | |
| 2278 | if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
| 2279 | Error("malformed block record in AST file"); |
| 2280 | return Failure; |
| 2281 | } |
| 2282 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2283 | // Lambda to read the unhashed control block the first time it's called. |
| 2284 | // |
| 2285 | // For PCM files, the unhashed control block cannot be read until after the |
| 2286 | // MODULE_NAME record. However, PCH files have no MODULE_NAME, and yet still |
| 2287 | // need to look ahead before reading the IMPORTS record. For consistency, |
| 2288 | // this block is always read somehow (see BitstreamEntry::EndBlock). |
| 2289 | bool HasReadUnhashedControlBlock = false; |
| 2290 | auto readUnhashedControlBlockOnce = [&]() { |
| 2291 | if (!HasReadUnhashedControlBlock) { |
| 2292 | HasReadUnhashedControlBlock = true; |
| 2293 | if (ASTReadResult Result = |
| 2294 | readUnhashedControlBlock(F, ImportedBy, ClientLoadCapabilities)) |
| 2295 | return Result; |
| 2296 | } |
| 2297 | return Success; |
| 2298 | }; |
| 2299 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2300 | // Read all of the records and blocks in the control block. |
| 2301 | RecordData Record; |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2302 | unsigned NumInputs = 0; |
| 2303 | unsigned NumUserInputs = 0; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2304 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2305 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2306 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2307 | switch (Entry.Kind) { |
| 2308 | case llvm::BitstreamEntry::Error: |
| 2309 | Error("malformed block record in AST file"); |
| 2310 | return Failure; |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2311 | case llvm::BitstreamEntry::EndBlock: { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2312 | // Validate the module before returning. This call catches an AST with |
| 2313 | // no module name and no imports. |
| 2314 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2315 | return Result; |
| 2316 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2317 | // Validate input files. |
| 2318 | const HeaderSearchOptions &HSOpts = |
| 2319 | PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2320 | |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2321 | // All user input files reside at the index range [0, NumUserInputs), and |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2322 | // system input files reside at [NumUserInputs, NumInputs). For explicitly |
| 2323 | // loaded module files, ignore missing inputs. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2324 | if (!DisableValidation && F.Kind != MK_ExplicitModule && |
| 2325 | F.Kind != MK_PrebuiltModule) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2326 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2327 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2328 | // If we are reading a module, we will create a verification timestamp, |
| 2329 | // so we verify all input files. Otherwise, verify only user input |
| 2330 | // files. |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2331 | |
| 2332 | unsigned N = NumUserInputs; |
| 2333 | if (ValidateSystemInputs || |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 2334 | (HSOpts.ModulesValidateOncePerBuildSession && |
Ben Langmuir | acb803e | 2014-11-10 22:13:10 +0000 | [diff] [blame] | 2335 | F.InputFilesValidationTimestamp <= HSOpts.BuildSessionTimestamp && |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 2336 | F.Kind == MK_ImplicitModule)) |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2337 | N = NumInputs; |
| 2338 | |
Ben Langmuir | 3d4417c | 2014-02-07 17:31:11 +0000 | [diff] [blame] | 2339 | for (unsigned I = 0; I < N; ++I) { |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2340 | InputFile IF = getInputFile(F, I+1, Complain); |
| 2341 | if (!IF.getFile() || IF.isOutOfDate()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2342 | return OutOfDate; |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2343 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2344 | } |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2345 | |
Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 2346 | if (Listener) |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 2347 | Listener->visitModuleFile(F.FileName, F.Kind); |
Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 2348 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2349 | if (Listener && Listener->needsInputFileVisitation()) { |
| 2350 | unsigned N = Listener->needsSystemInputFileVisitation() ? NumInputs |
| 2351 | : NumUserInputs; |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 2352 | for (unsigned I = 0; I < N; ++I) { |
| 2353 | bool IsSystem = I >= NumUserInputs; |
| 2354 | InputFileInfo FI = readInputFileInfo(F, I+1); |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 2355 | Listener->visitInputFile(FI.Filename, IsSystem, FI.Overridden, |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2356 | F.Kind == MK_ExplicitModule || |
| 2357 | F.Kind == MK_PrebuiltModule); |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 2358 | } |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2359 | } |
| 2360 | |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2361 | return Result; |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2362 | } |
| 2363 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2364 | case llvm::BitstreamEntry::SubBlock: |
| 2365 | switch (Entry.ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2366 | case INPUT_FILES_BLOCK_ID: |
| 2367 | F.InputFilesCursor = Stream; |
| 2368 | if (Stream.SkipBlock() || // Skip with the main cursor |
| 2369 | // Read the abbreviations |
| 2370 | ReadBlockAbbrevs(F.InputFilesCursor, INPUT_FILES_BLOCK_ID)) { |
| 2371 | Error("malformed block record in AST file"); |
| 2372 | return Failure; |
| 2373 | } |
| 2374 | continue; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2375 | |
| 2376 | case OPTIONS_BLOCK_ID: |
| 2377 | // If we're reading the first module for this group, check its options |
| 2378 | // are compatible with ours. For modules it imports, no further checking |
| 2379 | // is required, because we checked them when we built it. |
| 2380 | if (Listener && !ImportedBy) { |
| 2381 | // Should we allow the configuration of the module file to differ from |
| 2382 | // the configuration of the current translation unit in a compatible |
| 2383 | // way? |
| 2384 | // |
| 2385 | // FIXME: Allow this for files explicitly specified with -include-pch. |
| 2386 | bool AllowCompatibleConfigurationMismatch = |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2387 | F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2388 | |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2389 | Result = ReadOptionsBlock(Stream, ClientLoadCapabilities, |
| 2390 | AllowCompatibleConfigurationMismatch, |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2391 | *Listener, SuggestedPredefines); |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2392 | if (Result == Failure) { |
| 2393 | Error("malformed block record in AST file"); |
| 2394 | return Result; |
| 2395 | } |
| 2396 | |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2397 | if (DisableValidation || |
| 2398 | (AllowConfigurationMismatch && Result == ConfigurationMismatch)) |
| 2399 | Result = Success; |
| 2400 | |
Ben Langmuir | 9b1e442e | 2016-02-11 18:54:02 +0000 | [diff] [blame] | 2401 | // If we can't load the module, exit early since we likely |
| 2402 | // will rebuild the module anyway. The stream may be in the |
| 2403 | // middle of a block. |
| 2404 | if (Result != Success) |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2405 | return Result; |
| 2406 | } else if (Stream.SkipBlock()) { |
| 2407 | Error("malformed block record in AST file"); |
| 2408 | return Failure; |
| 2409 | } |
| 2410 | continue; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2411 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2412 | default: |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2413 | if (Stream.SkipBlock()) { |
| 2414 | Error("malformed block record in AST file"); |
| 2415 | return Failure; |
| 2416 | } |
| 2417 | continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2418 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2419 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2420 | case llvm::BitstreamEntry::Record: |
| 2421 | // The interesting case. |
| 2422 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | // Read and process a record. |
| 2426 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2427 | StringRef Blob; |
| 2428 | switch ((ControlRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2429 | case METADATA: { |
| 2430 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 2431 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 2432 | Diag(Record[0] < VERSION_MAJOR? diag::err_pch_version_too_old |
| 2433 | : diag::err_pch_version_too_new); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2434 | return VersionMismatch; |
| 2435 | } |
| 2436 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 2437 | bool hasErrors = Record[6]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2438 | if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) { |
| 2439 | Diag(diag::err_pch_with_compiler_errors); |
| 2440 | return HadErrors; |
| 2441 | } |
Argyrios Kyrtzidis | 70ec1c7 | 2016-07-13 20:35:26 +0000 | [diff] [blame] | 2442 | if (hasErrors) { |
| 2443 | Diags.ErrorOccurred = true; |
| 2444 | Diags.UncompilableErrorOccurred = true; |
| 2445 | Diags.UnrecoverableErrorOccurred = true; |
| 2446 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2447 | |
| 2448 | F.RelocatablePCH = Record[4]; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2449 | // Relative paths in a relocatable PCH are relative to our sysroot. |
| 2450 | if (F.RelocatablePCH) |
| 2451 | F.BaseDirectory = isysroot.empty() ? "/" : isysroot; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2452 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 2453 | F.HasTimestamps = Record[5]; |
| 2454 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2455 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2456 | StringRef ASTBranch = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2457 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2458 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 2459 | Diag(diag::err_pch_different_branch) << ASTBranch << CurBranch; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2460 | return VersionMismatch; |
| 2461 | } |
| 2462 | break; |
| 2463 | } |
| 2464 | |
| 2465 | case IMPORTS: { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2466 | // Validate the AST before processing any imports (otherwise, untangling |
| 2467 | // them can be error-prone and expensive). A module will have a name and |
| 2468 | // will already have been validated, but this catches the PCH case. |
| 2469 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2470 | return Result; |
| 2471 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2472 | // Load each of the imported PCH files. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2473 | unsigned Idx = 0, N = Record.size(); |
| 2474 | while (Idx < N) { |
| 2475 | // Read information about the AST file. |
| 2476 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 2477 | // The import location will be the local one for now; we will adjust |
| 2478 | // all import locations of module imports after the global source |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2479 | // location info are setup, in ReadAST. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2480 | SourceLocation ImportLoc = |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2481 | ReadUntranslatedSourceLocation(Record[Idx++]); |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 2482 | off_t StoredSize = (off_t)Record[Idx++]; |
| 2483 | time_t StoredModTime = (time_t)Record[Idx++]; |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2484 | ASTFileSignature StoredSignature = { |
| 2485 | {{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++], |
| 2486 | (uint32_t)Record[Idx++], (uint32_t)Record[Idx++], |
| 2487 | (uint32_t)Record[Idx++]}}}; |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 2488 | |
| 2489 | std::string ImportedName = ReadString(Record, Idx); |
| 2490 | std::string ImportedFile; |
| 2491 | |
| 2492 | // For prebuilt and explicit modules first consult the file map for |
| 2493 | // an override. Note that here we don't search prebuilt module |
| 2494 | // directories, only the explicit name to file mappings. Also, we will |
| 2495 | // still verify the size/signature making sure it is essentially the |
| 2496 | // same file but perhaps in a different location. |
| 2497 | if (ImportedKind == MK_PrebuiltModule || ImportedKind == MK_ExplicitModule) |
| 2498 | ImportedFile = PP.getHeaderSearchInfo().getPrebuiltModuleFileName( |
| 2499 | ImportedName, /*FileMapOnly*/ true); |
| 2500 | |
| 2501 | if (ImportedFile.empty()) |
| 2502 | ImportedFile = ReadPath(F, Record, Idx); |
| 2503 | else |
| 2504 | SkipPath(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2505 | |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2506 | // If our client can't cope with us being out of date, we can't cope with |
| 2507 | // our dependency being missing. |
| 2508 | unsigned Capabilities = ClientLoadCapabilities; |
| 2509 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 2510 | Capabilities &= ~ARR_Missing; |
| 2511 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2512 | // Load the AST file. |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2513 | auto Result = ReadASTCore(ImportedFile, ImportedKind, ImportLoc, &F, |
| 2514 | Loaded, StoredSize, StoredModTime, |
| 2515 | StoredSignature, Capabilities); |
| 2516 | |
| 2517 | // If we diagnosed a problem, produce a backtrace. |
| 2518 | if (isDiagnosedResult(Result, Capabilities)) |
| 2519 | Diag(diag::note_module_file_imported_by) |
| 2520 | << F.FileName << !F.ModuleName.empty() << F.ModuleName; |
| 2521 | |
| 2522 | switch (Result) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2523 | case Failure: return Failure; |
| 2524 | // If we have to ignore the dependency, we'll have to ignore this too. |
Douglas Gregor | 2f1806e | 2013-03-19 00:38:50 +0000 | [diff] [blame] | 2525 | case Missing: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2526 | case OutOfDate: return OutOfDate; |
| 2527 | case VersionMismatch: return VersionMismatch; |
| 2528 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 2529 | case HadErrors: return HadErrors; |
| 2530 | case Success: break; |
| 2531 | } |
| 2532 | } |
| 2533 | break; |
| 2534 | } |
| 2535 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2536 | case ORIGINAL_FILE: |
| 2537 | F.OriginalSourceFileID = FileID::get(Record[0]); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2538 | F.ActualOriginalSourceFileName = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2539 | F.OriginalSourceFileName = F.ActualOriginalSourceFileName; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2540 | ResolveImportedPath(F, F.OriginalSourceFileName); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2541 | break; |
| 2542 | |
| 2543 | case ORIGINAL_FILE_ID: |
| 2544 | F.OriginalSourceFileID = FileID::get(Record[0]); |
| 2545 | break; |
| 2546 | |
| 2547 | case ORIGINAL_PCH_DIR: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2548 | F.OriginalDir = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2549 | break; |
| 2550 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2551 | case MODULE_NAME: |
| 2552 | F.ModuleName = Blob; |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 2553 | if (Listener) |
| 2554 | Listener->ReadModuleName(F.ModuleName); |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2555 | |
| 2556 | // Validate the AST as soon as we have a name so we can exit early on |
| 2557 | // failure. |
| 2558 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2559 | return Result; |
| 2560 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2561 | break; |
| 2562 | |
Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2563 | case MODULE_DIRECTORY: { |
| 2564 | assert(!F.ModuleName.empty() && |
| 2565 | "MODULE_DIRECTORY found before MODULE_NAME"); |
| 2566 | // If we've already loaded a module map file covering this module, we may |
| 2567 | // have a better path for it (relative to the current build). |
| 2568 | Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName); |
| 2569 | if (M && M->Directory) { |
| 2570 | // If we're implicitly loading a module, the base directory can't |
| 2571 | // change between the build and use. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2572 | if (F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) { |
Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2573 | const DirectoryEntry *BuildDir = |
| 2574 | PP.getFileManager().getDirectory(Blob); |
| 2575 | if (!BuildDir || BuildDir != M->Directory) { |
| 2576 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 2577 | Diag(diag::err_imported_module_relocated) |
| 2578 | << F.ModuleName << Blob << M->Directory->getName(); |
| 2579 | return OutOfDate; |
| 2580 | } |
| 2581 | } |
| 2582 | F.BaseDirectory = M->Directory->getName(); |
| 2583 | } else { |
| 2584 | F.BaseDirectory = Blob; |
| 2585 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2586 | break; |
Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2587 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2588 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2589 | case MODULE_MAP_FILE: |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 2590 | if (ASTReadResult Result = |
| 2591 | ReadModuleMapFileBlock(Record, F, ImportedBy, ClientLoadCapabilities)) |
| 2592 | return Result; |
Ben Langmuir | 264ea15 | 2014-11-08 00:06:39 +0000 | [diff] [blame] | 2593 | break; |
| 2594 | |
Justin Bogner | ca9c0cc | 2015-06-21 20:32:36 +0000 | [diff] [blame] | 2595 | case INPUT_FILE_OFFSETS: |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2596 | NumInputs = Record[0]; |
| 2597 | NumUserInputs = Record[1]; |
Justin Bogner | 4c18324 | 2015-06-21 20:32:40 +0000 | [diff] [blame] | 2598 | F.InputFileOffsets = |
| 2599 | (const llvm::support::unaligned_uint64_t *)Blob.data(); |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2600 | F.InputFilesLoaded.resize(NumInputs); |
Argyrios Kyrtzidis | a38cb20 | 2017-01-30 06:05:58 +0000 | [diff] [blame] | 2601 | F.NumUserInputFiles = NumUserInputs; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2602 | break; |
| 2603 | } |
| 2604 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2605 | } |
| 2606 | |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2607 | ASTReader::ASTReadResult |
| 2608 | ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2609 | BitstreamCursor &Stream = F.Stream; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2610 | |
| 2611 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
| 2612 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2613 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | // Read all of the records and blocks for the AST file. |
| 2617 | RecordData Record; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2618 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2619 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2620 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2621 | switch (Entry.Kind) { |
| 2622 | case llvm::BitstreamEntry::Error: |
| 2623 | Error("error at end of module block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2624 | return Failure; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2625 | case llvm::BitstreamEntry::EndBlock: { |
Richard Smith | c0fbba7 | 2013-04-03 22:49:41 +0000 | [diff] [blame] | 2626 | // Outside of C++, we do not store a lookup map for the translation unit. |
| 2627 | // Instead, mark it as needing a lookup map to be built if this module |
| 2628 | // contains any declarations lexically within it (which it always does!). |
| 2629 | // This usually has no cost, since we very rarely need the lookup map for |
| 2630 | // the translation unit outside C++. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2631 | if (ASTContext *Ctx = ContextObj) { |
| 2632 | DeclContext *DC = Ctx->getTranslationUnitDecl(); |
| 2633 | if (DC->hasExternalLexicalStorage() && !Ctx->getLangOpts().CPlusPlus) |
| 2634 | DC->setMustBuildLookupTable(); |
| 2635 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2636 | |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2637 | return Success; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2638 | } |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2639 | case llvm::BitstreamEntry::SubBlock: |
| 2640 | switch (Entry.ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2641 | case DECLTYPES_BLOCK_ID: |
| 2642 | // We lazily load the decls block, but we want to set up the |
| 2643 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 2644 | // cursor to it, enter the block and read the abbrevs in that block. |
| 2645 | // With the main cursor, we just skip over it. |
| 2646 | F.DeclsCursor = Stream; |
| 2647 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 2648 | // Read the abbrevs. |
| 2649 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
| 2650 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2651 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2652 | } |
| 2653 | break; |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 2654 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2655 | case PREPROCESSOR_BLOCK_ID: |
| 2656 | F.MacroCursor = Stream; |
| 2657 | if (!PP.getExternalSource()) |
| 2658 | PP.setExternalSource(this); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2659 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2660 | if (Stream.SkipBlock() || |
| 2661 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
| 2662 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2663 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2664 | } |
| 2665 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
| 2666 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2667 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2668 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 2669 | F.PreprocessorDetailCursor = Stream; |
| 2670 | if (Stream.SkipBlock() || |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2671 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2672 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2673 | Error("malformed preprocessor detail record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2674 | return Failure; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2675 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2676 | F.PreprocessorDetailStartOffset |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2677 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2678 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2679 | if (!PP.getPreprocessingRecord()) |
| 2680 | PP.createPreprocessingRecord(); |
| 2681 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2682 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2683 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2684 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2685 | case SOURCE_MANAGER_BLOCK_ID: |
| 2686 | if (ReadSourceManagerBlock(F)) |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2687 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2688 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2689 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2690 | case SUBMODULE_BLOCK_ID: |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2691 | if (ASTReadResult Result = |
| 2692 | ReadSubmoduleBlock(F, ClientLoadCapabilities)) |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2693 | return Result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2694 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2695 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2696 | case COMMENTS_BLOCK_ID: { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2697 | BitstreamCursor C = Stream; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2698 | if (Stream.SkipBlock() || |
| 2699 | ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) { |
| 2700 | Error("malformed comments block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2701 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2702 | } |
| 2703 | CommentsCursors.push_back(std::make_pair(C, &F)); |
| 2704 | break; |
| 2705 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2706 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2707 | default: |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2708 | if (Stream.SkipBlock()) { |
| 2709 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2710 | return Failure; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2711 | } |
| 2712 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2713 | } |
| 2714 | continue; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2715 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2716 | case llvm::BitstreamEntry::Record: |
| 2717 | // The interesting case. |
| 2718 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | // Read and process a record. |
| 2722 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2723 | StringRef Blob; |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2724 | auto RecordType = |
| 2725 | (ASTRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob); |
| 2726 | |
| 2727 | // If we're not loading an AST context, we don't care about most records. |
| 2728 | if (!ContextObj) { |
| 2729 | switch (RecordType) { |
| 2730 | case IDENTIFIER_TABLE: |
| 2731 | case IDENTIFIER_OFFSET: |
| 2732 | case INTERESTING_IDENTIFIERS: |
| 2733 | case STATISTICS: |
| 2734 | case PP_CONDITIONAL_STACK: |
| 2735 | case PP_COUNTER_VALUE: |
| 2736 | case SOURCE_LOCATION_OFFSETS: |
| 2737 | case MODULE_OFFSET_MAP: |
| 2738 | case SOURCE_MANAGER_LINE_TABLE: |
| 2739 | case SOURCE_LOCATION_PRELOADS: |
| 2740 | case PPD_ENTITIES_OFFSETS: |
| 2741 | case HEADER_SEARCH_TABLE: |
| 2742 | case IMPORTED_MODULES: |
| 2743 | case MACRO_OFFSET: |
| 2744 | break; |
| 2745 | default: |
| 2746 | continue; |
| 2747 | } |
| 2748 | } |
| 2749 | |
| 2750 | switch (RecordType) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2751 | default: // Default behavior: ignore. |
| 2752 | break; |
| 2753 | |
| 2754 | case TYPE_OFFSET: { |
| 2755 | if (F.LocalNumTypes != 0) { |
| 2756 | Error("duplicate TYPE_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2757 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2758 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2759 | F.TypeOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2760 | F.LocalNumTypes = Record[0]; |
| 2761 | unsigned LocalBaseTypeIndex = Record[1]; |
| 2762 | F.BaseTypeIndex = getTotalNumTypes(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2763 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2764 | if (F.LocalNumTypes > 0) { |
| 2765 | // Introduce the global -> local mapping for types within this module. |
| 2766 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2767 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2768 | // Introduce the local -> global mapping for types within this module. |
| 2769 | F.TypeRemap.insertOrReplace( |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2770 | std::make_pair(LocalBaseTypeIndex, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2771 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2772 | |
| 2773 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2774 | } |
| 2775 | break; |
| 2776 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2777 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2778 | case DECL_OFFSET: { |
| 2779 | if (F.LocalNumDecls != 0) { |
| 2780 | Error("duplicate DECL_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2781 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2782 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2783 | F.DeclOffsets = (const DeclOffset *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2784 | F.LocalNumDecls = Record[0]; |
| 2785 | unsigned LocalBaseDeclID = Record[1]; |
| 2786 | F.BaseDeclID = getTotalNumDecls(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2787 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2788 | if (F.LocalNumDecls > 0) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2789 | // Introduce the global -> local mapping for declarations within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2790 | // module. |
| 2791 | GlobalDeclMap.insert( |
| 2792 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2793 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2794 | // Introduce the local -> global mapping for declarations within this |
| 2795 | // module. |
| 2796 | F.DeclRemap.insertOrReplace( |
| 2797 | std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2798 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2799 | // Introduce the global -> local mapping for declarations within this |
| 2800 | // module. |
| 2801 | F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID; |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 2802 | |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2803 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 2804 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2805 | break; |
| 2806 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2807 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2808 | case TU_UPDATE_LEXICAL: { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2809 | DeclContext *TU = ContextObj->getTranslationUnitDecl(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2810 | LexicalContents Contents( |
| 2811 | reinterpret_cast<const llvm::support::unaligned_uint32_t *>( |
| 2812 | Blob.data()), |
| 2813 | static_cast<unsigned int>(Blob.size() / 4)); |
| 2814 | TULexicalDecls.push_back(std::make_pair(&F, Contents)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2815 | TU->setHasExternalLexicalStorage(true); |
| 2816 | break; |
| 2817 | } |
| 2818 | |
| 2819 | case UPDATE_VISIBLE: { |
| 2820 | unsigned Idx = 0; |
| 2821 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 2822 | auto *Data = (const unsigned char*)Blob.data(); |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 2823 | PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&F, Data}); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 2824 | // If we've already loaded the decl, perform the updates when we finish |
| 2825 | // loading this block. |
| 2826 | if (Decl *D = GetExistingDecl(ID)) |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 2827 | PendingUpdateRecords.push_back( |
| 2828 | PendingUpdateRecord(ID, D, /*JustLoaded=*/false)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2829 | break; |
| 2830 | } |
| 2831 | |
| 2832 | case IDENTIFIER_TABLE: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2833 | F.IdentifierTableData = Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2834 | if (Record[0]) { |
Justin Bogner | da4e650 | 2014-04-14 16:34:29 +0000 | [diff] [blame] | 2835 | F.IdentifierLookupTable = ASTIdentifierLookupTable::Create( |
| 2836 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2837 | (const unsigned char *)F.IdentifierTableData + sizeof(uint32_t), |
| 2838 | (const unsigned char *)F.IdentifierTableData, |
| 2839 | ASTIdentifierLookupTrait(*this, F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2840 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2841 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
| 2842 | } |
| 2843 | break; |
| 2844 | |
| 2845 | case IDENTIFIER_OFFSET: { |
| 2846 | if (F.LocalNumIdentifiers != 0) { |
| 2847 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2848 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2849 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2850 | F.IdentifierOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2851 | F.LocalNumIdentifiers = Record[0]; |
| 2852 | unsigned LocalBaseIdentifierID = Record[1]; |
| 2853 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2854 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2855 | if (F.LocalNumIdentifiers > 0) { |
| 2856 | // Introduce the global -> local mapping for identifiers within this |
| 2857 | // module. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2858 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2859 | &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2860 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2861 | // Introduce the local -> global mapping for identifiers within this |
| 2862 | // module. |
| 2863 | F.IdentifierRemap.insertOrReplace( |
| 2864 | std::make_pair(LocalBaseIdentifierID, |
| 2865 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 2866 | |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2867 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 2868 | + F.LocalNumIdentifiers); |
| 2869 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2870 | break; |
| 2871 | } |
| 2872 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 2873 | case INTERESTING_IDENTIFIERS: |
| 2874 | F.PreloadIdentifierOffsets.assign(Record.begin(), Record.end()); |
| 2875 | break; |
| 2876 | |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2877 | case EAGERLY_DESERIALIZED_DECLS: |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 2878 | // FIXME: Skip reading this record if our ASTConsumer doesn't care |
| 2879 | // about "interesting" decls (for instance, if we're building a module). |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2880 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2881 | EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2882 | break; |
| 2883 | |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2884 | case MODULAR_CODEGEN_DECLS: |
| 2885 | // FIXME: Skip reading this record if our ASTConsumer doesn't care about |
| 2886 | // them (ie: if we're not codegenerating this module). |
| 2887 | if (F.Kind == MK_MainFile) |
| 2888 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2889 | EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2890 | break; |
| 2891 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2892 | case SPECIAL_TYPES: |
Douglas Gregor | 44180f8 | 2013-02-01 23:45:03 +0000 | [diff] [blame] | 2893 | if (SpecialTypes.empty()) { |
| 2894 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2895 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
| 2896 | break; |
| 2897 | } |
| 2898 | |
| 2899 | if (SpecialTypes.size() != Record.size()) { |
| 2900 | Error("invalid special-types record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2901 | return Failure; |
Douglas Gregor | 44180f8 | 2013-02-01 23:45:03 +0000 | [diff] [blame] | 2902 | } |
| 2903 | |
| 2904 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 2905 | serialization::TypeID ID = getGlobalTypeID(F, Record[I]); |
| 2906 | if (!SpecialTypes[I]) |
| 2907 | SpecialTypes[I] = ID; |
| 2908 | // FIXME: If ID && SpecialTypes[I] != ID, do we need a separate |
| 2909 | // merge step? |
| 2910 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2911 | break; |
| 2912 | |
| 2913 | case STATISTICS: |
| 2914 | TotalNumStatements += Record[0]; |
| 2915 | TotalNumMacros += Record[1]; |
| 2916 | TotalLexicalDeclContexts += Record[2]; |
| 2917 | TotalVisibleDeclContexts += Record[3]; |
| 2918 | break; |
| 2919 | |
| 2920 | case UNUSED_FILESCOPED_DECLS: |
| 2921 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2922 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2923 | break; |
| 2924 | |
| 2925 | case DELEGATING_CTORS: |
| 2926 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2927 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2928 | break; |
| 2929 | |
| 2930 | case WEAK_UNDECLARED_IDENTIFIERS: |
| 2931 | if (Record.size() % 4 != 0) { |
| 2932 | Error("invalid weak identifiers record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2933 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2934 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2935 | |
| 2936 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2937 | // files. This isn't the way to do it :) |
| 2938 | WeakUndeclaredIdentifiers.clear(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2939 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2940 | // Translate the weak, undeclared identifiers into global IDs. |
| 2941 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 2942 | WeakUndeclaredIdentifiers.push_back( |
| 2943 | getGlobalIdentifierID(F, Record[I++])); |
| 2944 | WeakUndeclaredIdentifiers.push_back( |
| 2945 | getGlobalIdentifierID(F, Record[I++])); |
| 2946 | WeakUndeclaredIdentifiers.push_back( |
| 2947 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2948 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 2949 | } |
| 2950 | break; |
| 2951 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2952 | case SELECTOR_OFFSETS: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2953 | F.SelectorOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2954 | F.LocalNumSelectors = Record[0]; |
| 2955 | unsigned LocalBaseSelectorID = Record[1]; |
| 2956 | F.BaseSelectorID = getTotalNumSelectors(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2957 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2958 | if (F.LocalNumSelectors > 0) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2959 | // Introduce the global -> local mapping for selectors within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2960 | // module. |
| 2961 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2962 | |
| 2963 | // Introduce the local -> global mapping for selectors within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2964 | // module. |
| 2965 | F.SelectorRemap.insertOrReplace( |
| 2966 | std::make_pair(LocalBaseSelectorID, |
| 2967 | F.BaseSelectorID - LocalBaseSelectorID)); |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2968 | |
| 2969 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2970 | } |
| 2971 | break; |
| 2972 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2973 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2974 | case METHOD_POOL: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2975 | F.SelectorLookupTableData = (const unsigned char *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2976 | if (Record[0]) |
| 2977 | F.SelectorLookupTable |
| 2978 | = ASTSelectorLookupTable::Create( |
| 2979 | F.SelectorLookupTableData + Record[0], |
| 2980 | F.SelectorLookupTableData, |
| 2981 | ASTSelectorLookupTrait(*this, F)); |
| 2982 | TotalNumMethodPoolEntries += Record[1]; |
| 2983 | break; |
| 2984 | |
| 2985 | case REFERENCED_SELECTOR_POOL: |
| 2986 | if (!Record.empty()) { |
| 2987 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2988 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2989 | Record[Idx++])); |
| 2990 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2991 | getRawEncoding()); |
| 2992 | } |
| 2993 | } |
| 2994 | break; |
| 2995 | |
Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 2996 | case PP_CONDITIONAL_STACK: |
| 2997 | if (!Record.empty()) { |
| 2998 | SmallVector<PPConditionalInfo, 4> ConditionalStack; |
| 2999 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 3000 | auto Loc = ReadSourceLocation(F, Record, Idx); |
| 3001 | bool WasSkipping = Record[Idx++]; |
| 3002 | bool FoundNonSkip = Record[Idx++]; |
| 3003 | bool FoundElse = Record[Idx++]; |
| 3004 | ConditionalStack.push_back( |
| 3005 | {Loc, WasSkipping, FoundNonSkip, FoundElse}); |
| 3006 | } |
| 3007 | PP.setReplayablePreambleConditionalStack(ConditionalStack); |
| 3008 | } |
| 3009 | break; |
| 3010 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3011 | case PP_COUNTER_VALUE: |
| 3012 | if (!Record.empty() && Listener) |
| 3013 | Listener->ReadCounter(F, Record[0]); |
| 3014 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3015 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3016 | case FILE_SORTED_DECLS: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3017 | F.FileSortedDecls = (const DeclID *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3018 | F.NumFileSortedDecls = Record[0]; |
| 3019 | break; |
| 3020 | |
| 3021 | case SOURCE_LOCATION_OFFSETS: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3022 | F.SLocEntryOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3023 | F.LocalNumSLocEntries = Record[0]; |
| 3024 | unsigned SLocSpaceSize = Record[1]; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 3025 | std::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3026 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3027 | SLocSpaceSize); |
Richard Smith | 78d81ec | 2015-08-12 22:25:24 +0000 | [diff] [blame] | 3028 | if (!F.SLocEntryBaseID) { |
| 3029 | Error("ran out of source locations"); |
| 3030 | break; |
| 3031 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3032 | // Make our entry in the range map. BaseID is negative and growing, so |
| 3033 | // we invert it. Because we invert it, though, we need the other end of |
| 3034 | // the range. |
| 3035 | unsigned RangeStart = |
| 3036 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 3037 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 3038 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 3039 | |
| 3040 | // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. |
| 3041 | assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); |
| 3042 | GlobalSLocOffsetMap.insert( |
| 3043 | std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset |
| 3044 | - SLocSpaceSize,&F)); |
| 3045 | |
| 3046 | // Initialize the remapping table. |
| 3047 | // Invalid stays invalid. |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 3048 | F.SLocRemap.insertOrReplace(std::make_pair(0U, 0)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3049 | // This module. Base was 2 when being compiled. |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 3050 | F.SLocRemap.insertOrReplace(std::make_pair(2U, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3051 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3052 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3053 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
| 3054 | break; |
| 3055 | } |
| 3056 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3057 | case MODULE_OFFSET_MAP: |
| 3058 | F.ModuleOffsetMap = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3059 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3060 | |
| 3061 | case SOURCE_MANAGER_LINE_TABLE: |
| 3062 | if (ParseLineTable(F, Record)) |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3063 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3064 | break; |
| 3065 | |
| 3066 | case SOURCE_LOCATION_PRELOADS: { |
| 3067 | // Need to transform from the local view (1-based IDs) to the global view, |
| 3068 | // which is based off F.SLocEntryBaseID. |
| 3069 | if (!F.PreloadSLocEntries.empty()) { |
| 3070 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3071 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3072 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3073 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3074 | F.PreloadSLocEntries.swap(Record); |
| 3075 | break; |
| 3076 | } |
| 3077 | |
| 3078 | case EXT_VECTOR_DECLS: |
| 3079 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3080 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 3081 | break; |
| 3082 | |
| 3083 | case VTABLE_USES: |
| 3084 | if (Record.size() % 3 != 0) { |
| 3085 | Error("Invalid VTABLE_USES record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3086 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3087 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3088 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3089 | // Later tables overwrite earlier ones. |
| 3090 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 3091 | // the right way to do this. |
| 3092 | VTableUses.clear(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3093 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3094 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 3095 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 3096 | VTableUses.push_back( |
| 3097 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 3098 | VTableUses.push_back(Record[Idx++]); |
| 3099 | } |
| 3100 | break; |
| 3101 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3102 | case PENDING_IMPLICIT_INSTANTIATIONS: |
| 3103 | if (PendingInstantiations.size() % 2 != 0) { |
| 3104 | Error("Invalid existing PendingInstantiations"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3105 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | if (Record.size() % 2 != 0) { |
| 3109 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3110 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3111 | } |
| 3112 | |
| 3113 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 3114 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 3115 | PendingInstantiations.push_back( |
| 3116 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3117 | } |
| 3118 | break; |
| 3119 | |
| 3120 | case SEMA_DECL_REFS: |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 3121 | if (Record.size() != 3) { |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 3122 | Error("Invalid SEMA_DECL_REFS block"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3123 | return Failure; |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 3124 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3125 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3126 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
| 3127 | break; |
| 3128 | |
| 3129 | case PPD_ENTITIES_OFFSETS: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3130 | F.PreprocessedEntityOffsets = (const PPEntityOffset *)Blob.data(); |
| 3131 | assert(Blob.size() % sizeof(PPEntityOffset) == 0); |
| 3132 | F.NumPreprocessedEntities = Blob.size() / sizeof(PPEntityOffset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3133 | |
| 3134 | unsigned LocalBasePreprocessedEntityID = Record[0]; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3135 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3136 | unsigned StartingID; |
| 3137 | if (!PP.getPreprocessingRecord()) |
| 3138 | PP.createPreprocessingRecord(); |
| 3139 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 3140 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3141 | StartingID |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3142 | = PP.getPreprocessingRecord() |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3143 | ->allocateLoadedEntities(F.NumPreprocessedEntities); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3144 | F.BasePreprocessedEntityID = StartingID; |
| 3145 | |
| 3146 | if (F.NumPreprocessedEntities > 0) { |
| 3147 | // Introduce the global -> local mapping for preprocessed entities in |
| 3148 | // this module. |
| 3149 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3150 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3151 | // Introduce the local -> global mapping for preprocessed entities in |
| 3152 | // this module. |
| 3153 | F.PreprocessedEntityRemap.insertOrReplace( |
| 3154 | std::make_pair(LocalBasePreprocessedEntityID, |
| 3155 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 3156 | } |
| 3157 | |
| 3158 | break; |
| 3159 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3160 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3161 | case DECL_UPDATE_OFFSETS: { |
| 3162 | if (Record.size() % 2 != 0) { |
| 3163 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3164 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3165 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3166 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) { |
| 3167 | GlobalDeclID ID = getGlobalDeclID(F, Record[I]); |
| 3168 | DeclUpdateOffsets[ID].push_back(std::make_pair(&F, Record[I + 1])); |
| 3169 | |
| 3170 | // If we've already loaded the decl, perform the updates when we finish |
| 3171 | // loading this block. |
| 3172 | if (Decl *D = GetExistingDecl(ID)) |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3173 | PendingUpdateRecords.push_back( |
| 3174 | PendingUpdateRecord(ID, D, /*JustLoaded=*/false)); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3175 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3176 | break; |
| 3177 | } |
| 3178 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3179 | case OBJC_CATEGORIES_MAP: { |
| 3180 | if (F.LocalNumObjCCategoriesInMap != 0) { |
| 3181 | Error("duplicate OBJC_CATEGORIES_MAP record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3182 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3183 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3184 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3185 | F.LocalNumObjCCategoriesInMap = Record[0]; |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3186 | F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3187 | break; |
| 3188 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3189 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3190 | case OBJC_CATEGORIES: |
| 3191 | F.ObjCCategories.swap(Record); |
| 3192 | break; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 3193 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3194 | case CUDA_SPECIAL_DECL_REFS: |
| 3195 | // Later tables overwrite earlier ones. |
| 3196 | // FIXME: Modules will have trouble with this. |
| 3197 | CUDASpecialDeclRefs.clear(); |
| 3198 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3199 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
| 3200 | break; |
| 3201 | |
| 3202 | case HEADER_SEARCH_TABLE: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3203 | F.HeaderFileInfoTableData = Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3204 | F.LocalNumHeaderFileInfos = Record[1]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3205 | if (Record[0]) { |
| 3206 | F.HeaderFileInfoTable |
| 3207 | = HeaderFileInfoLookupTable::Create( |
| 3208 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 3209 | (const unsigned char *)F.HeaderFileInfoTableData, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3210 | HeaderFileInfoTrait(*this, F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3211 | &PP.getHeaderSearchInfo(), |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3212 | Blob.data() + Record[2])); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3213 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3214 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 3215 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 3216 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
| 3217 | } |
| 3218 | break; |
| 3219 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3220 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3221 | case FP_PRAGMA_OPTIONS: |
| 3222 | // Later tables overwrite earlier ones. |
| 3223 | FPPragmaOptions.swap(Record); |
| 3224 | break; |
| 3225 | |
| 3226 | case OPENCL_EXTENSIONS: |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3227 | for (unsigned I = 0, E = Record.size(); I != E; ) { |
| 3228 | auto Name = ReadString(Record, I); |
| 3229 | auto &Opt = OpenCLExtensions.OptMap[Name]; |
Yaxun Liu | cc2741c | 2016-12-18 06:35:06 +0000 | [diff] [blame] | 3230 | Opt.Supported = Record[I++] != 0; |
| 3231 | Opt.Enabled = Record[I++] != 0; |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3232 | Opt.Avail = Record[I++]; |
| 3233 | Opt.Core = Record[I++]; |
| 3234 | } |
| 3235 | break; |
| 3236 | |
| 3237 | case OPENCL_EXTENSION_TYPES: |
| 3238 | for (unsigned I = 0, E = Record.size(); I != E;) { |
| 3239 | auto TypeID = static_cast<::TypeID>(Record[I++]); |
| 3240 | auto *Type = GetType(TypeID).getTypePtr(); |
| 3241 | auto NumExt = static_cast<unsigned>(Record[I++]); |
| 3242 | for (unsigned II = 0; II != NumExt; ++II) { |
| 3243 | auto Ext = ReadString(Record, I); |
| 3244 | OpenCLTypeExtMap[Type].insert(Ext); |
| 3245 | } |
| 3246 | } |
| 3247 | break; |
| 3248 | |
| 3249 | case OPENCL_EXTENSION_DECLS: |
| 3250 | for (unsigned I = 0, E = Record.size(); I != E;) { |
| 3251 | auto DeclID = static_cast<::DeclID>(Record[I++]); |
| 3252 | auto *Decl = GetDecl(DeclID); |
| 3253 | auto NumExt = static_cast<unsigned>(Record[I++]); |
| 3254 | for (unsigned II = 0; II != NumExt; ++II) { |
| 3255 | auto Ext = ReadString(Record, I); |
| 3256 | OpenCLDeclExtMap[Decl].insert(Ext); |
| 3257 | } |
| 3258 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3259 | break; |
| 3260 | |
| 3261 | case TENTATIVE_DEFINITIONS: |
| 3262 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3263 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
| 3264 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3265 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3266 | case KNOWN_NAMESPACES: |
| 3267 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3268 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
| 3269 | break; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3270 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3271 | case UNDEFINED_BUT_USED: |
| 3272 | if (UndefinedButUsed.size() % 2 != 0) { |
| 3273 | Error("Invalid existing UndefinedButUsed"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3274 | return Failure; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | if (Record.size() % 2 != 0) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3278 | Error("invalid undefined-but-used record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3279 | return Failure; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3280 | } |
| 3281 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3282 | UndefinedButUsed.push_back(getGlobalDeclID(F, Record[I++])); |
| 3283 | UndefinedButUsed.push_back( |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3284 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3285 | } |
| 3286 | break; |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 3287 | case DELETE_EXPRS_TO_ANALYZE: |
| 3288 | for (unsigned I = 0, N = Record.size(); I != N;) { |
| 3289 | DelayedDeleteExprs.push_back(getGlobalDeclID(F, Record[I++])); |
| 3290 | const uint64_t Count = Record[I++]; |
| 3291 | DelayedDeleteExprs.push_back(Count); |
| 3292 | for (uint64_t C = 0; C < Count; ++C) { |
| 3293 | DelayedDeleteExprs.push_back(ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3294 | bool IsArrayForm = Record[I++] == 1; |
| 3295 | DelayedDeleteExprs.push_back(IsArrayForm); |
| 3296 | } |
| 3297 | } |
| 3298 | break; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3299 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3300 | case IMPORTED_MODULES: { |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 3301 | if (!F.isModule()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3302 | // If we aren't loading a module (which has its own exports), make |
| 3303 | // all of the imported modules visible. |
| 3304 | // FIXME: Deal with macros-only imports. |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 3305 | for (unsigned I = 0, N = Record.size(); I != N; /**/) { |
| 3306 | unsigned GlobalID = getGlobalSubmoduleID(F, Record[I++]); |
| 3307 | SourceLocation Loc = ReadSourceLocation(F, Record, I); |
Graydon Hoare | 9c98244 | 2017-01-18 20:36:59 +0000 | [diff] [blame] | 3308 | if (GlobalID) { |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 3309 | ImportedModules.push_back(ImportedSubmodule(GlobalID, Loc)); |
Graydon Hoare | 9c98244 | 2017-01-18 20:36:59 +0000 | [diff] [blame] | 3310 | if (DeserializationListener) |
| 3311 | DeserializationListener->ModuleImportRead(GlobalID, Loc); |
| 3312 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3313 | } |
| 3314 | } |
| 3315 | break; |
| 3316 | } |
| 3317 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3318 | case MACRO_OFFSET: { |
| 3319 | if (F.LocalNumMacros != 0) { |
| 3320 | Error("duplicate MACRO_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3321 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3322 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3323 | F.MacroOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3324 | F.LocalNumMacros = Record[0]; |
| 3325 | unsigned LocalBaseMacroID = Record[1]; |
| 3326 | F.BaseMacroID = getTotalNumMacros(); |
| 3327 | |
| 3328 | if (F.LocalNumMacros > 0) { |
| 3329 | // Introduce the global -> local mapping for macros within this module. |
| 3330 | GlobalMacroMap.insert(std::make_pair(getTotalNumMacros() + 1, &F)); |
| 3331 | |
| 3332 | // Introduce the local -> global mapping for macros within this module. |
| 3333 | F.MacroRemap.insertOrReplace( |
| 3334 | std::make_pair(LocalBaseMacroID, |
| 3335 | F.BaseMacroID - LocalBaseMacroID)); |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3336 | |
| 3337 | MacrosLoaded.resize(MacrosLoaded.size() + F.LocalNumMacros); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3338 | } |
| 3339 | break; |
| 3340 | } |
| 3341 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3342 | case LATE_PARSED_TEMPLATE: { |
| 3343 | LateParsedTemplates.append(Record.begin(), Record.end()); |
| 3344 | break; |
| 3345 | } |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 3346 | |
| 3347 | case OPTIMIZE_PRAGMA_OPTIONS: |
| 3348 | if (Record.size() != 1) { |
| 3349 | Error("invalid pragma optimize record"); |
| 3350 | return Failure; |
| 3351 | } |
| 3352 | OptimizeOffPragmaLocation = ReadSourceLocation(F, Record[0]); |
| 3353 | break; |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 3354 | |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 3355 | case MSSTRUCT_PRAGMA_OPTIONS: |
| 3356 | if (Record.size() != 1) { |
| 3357 | Error("invalid pragma ms_struct record"); |
| 3358 | return Failure; |
| 3359 | } |
| 3360 | PragmaMSStructState = Record[0]; |
| 3361 | break; |
| 3362 | |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 3363 | case POINTERS_TO_MEMBERS_PRAGMA_OPTIONS: |
| 3364 | if (Record.size() != 2) { |
| 3365 | Error("invalid pragma ms_struct record"); |
| 3366 | return Failure; |
| 3367 | } |
| 3368 | PragmaMSPointersToMembersState = Record[0]; |
| 3369 | PointersToMembersPragmaLocation = ReadSourceLocation(F, Record[1]); |
| 3370 | break; |
| 3371 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 3372 | case UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES: |
| 3373 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3374 | UnusedLocalTypedefNameCandidates.push_back( |
| 3375 | getGlobalDeclID(F, Record[I])); |
| 3376 | break; |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 3377 | |
| 3378 | case CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH: |
| 3379 | if (Record.size() != 1) { |
| 3380 | Error("invalid cuda pragma options record"); |
| 3381 | return Failure; |
| 3382 | } |
| 3383 | ForceCUDAHostDeviceDepth = Record[0]; |
| 3384 | break; |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 3385 | |
| 3386 | case PACK_PRAGMA_OPTIONS: { |
| 3387 | if (Record.size() < 3) { |
| 3388 | Error("invalid pragma pack record"); |
| 3389 | return Failure; |
| 3390 | } |
| 3391 | PragmaPackCurrentValue = Record[0]; |
| 3392 | PragmaPackCurrentLocation = ReadSourceLocation(F, Record[1]); |
| 3393 | unsigned NumStackEntries = Record[2]; |
| 3394 | unsigned Idx = 3; |
| 3395 | // Reset the stack when importing a new module. |
| 3396 | PragmaPackStack.clear(); |
| 3397 | for (unsigned I = 0; I < NumStackEntries; ++I) { |
| 3398 | PragmaPackStackEntry Entry; |
| 3399 | Entry.Value = Record[Idx++]; |
| 3400 | Entry.Location = ReadSourceLocation(F, Record[Idx++]); |
Alex Lorenz | 45b4014 | 2017-07-28 14:41:21 +0000 | [diff] [blame] | 3401 | Entry.PushLocation = ReadSourceLocation(F, Record[Idx++]); |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 3402 | PragmaPackStrings.push_back(ReadString(Record, Idx)); |
| 3403 | Entry.SlotLabel = PragmaPackStrings.back(); |
| 3404 | PragmaPackStack.push_back(Entry); |
| 3405 | } |
| 3406 | break; |
| 3407 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3408 | } |
| 3409 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3410 | } |
| 3411 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3412 | void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const { |
| 3413 | assert(!F.ModuleOffsetMap.empty() && "no module offset map to read"); |
| 3414 | |
| 3415 | // Additional remapping information. |
| 3416 | const unsigned char *Data = (const unsigned char*)F.ModuleOffsetMap.data(); |
| 3417 | const unsigned char *DataEnd = Data + F.ModuleOffsetMap.size(); |
| 3418 | F.ModuleOffsetMap = StringRef(); |
| 3419 | |
| 3420 | // If we see this entry before SOURCE_LOCATION_OFFSETS, add placeholders. |
| 3421 | if (F.SLocRemap.find(0) == F.SLocRemap.end()) { |
| 3422 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 3423 | F.SLocRemap.insert(std::make_pair(2U, 1)); |
| 3424 | } |
| 3425 | |
| 3426 | // Continuous range maps we may be updating in our module. |
| 3427 | typedef ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 3428 | RemapBuilder; |
| 3429 | RemapBuilder SLocRemap(F.SLocRemap); |
| 3430 | RemapBuilder IdentifierRemap(F.IdentifierRemap); |
| 3431 | RemapBuilder MacroRemap(F.MacroRemap); |
| 3432 | RemapBuilder PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 3433 | RemapBuilder SubmoduleRemap(F.SubmoduleRemap); |
| 3434 | RemapBuilder SelectorRemap(F.SelectorRemap); |
| 3435 | RemapBuilder DeclRemap(F.DeclRemap); |
| 3436 | RemapBuilder TypeRemap(F.TypeRemap); |
| 3437 | |
| 3438 | while (Data < DataEnd) { |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 3439 | // FIXME: Looking up dependency modules by filename is horrible. Let's |
| 3440 | // start fixing this with prebuilt and explicit modules and see how it |
| 3441 | // goes... |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3442 | using namespace llvm::support; |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 3443 | ModuleKind Kind = static_cast<ModuleKind>( |
| 3444 | endian::readNext<uint8_t, little, unaligned>(Data)); |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3445 | uint16_t Len = endian::readNext<uint16_t, little, unaligned>(Data); |
| 3446 | StringRef Name = StringRef((const char*)Data, Len); |
| 3447 | Data += Len; |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 3448 | ModuleFile *OM = (Kind == MK_PrebuiltModule || Kind == MK_ExplicitModule |
| 3449 | ? ModuleMgr.lookupByModuleName(Name) |
| 3450 | : ModuleMgr.lookupByFileName(Name)); |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3451 | if (!OM) { |
| 3452 | std::string Msg = |
| 3453 | "SourceLocation remap refers to unknown module, cannot find "; |
| 3454 | Msg.append(Name); |
| 3455 | Error(Msg); |
| 3456 | return; |
| 3457 | } |
| 3458 | |
| 3459 | uint32_t SLocOffset = |
| 3460 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3461 | uint32_t IdentifierIDOffset = |
| 3462 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3463 | uint32_t MacroIDOffset = |
| 3464 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3465 | uint32_t PreprocessedEntityIDOffset = |
| 3466 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3467 | uint32_t SubmoduleIDOffset = |
| 3468 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3469 | uint32_t SelectorIDOffset = |
| 3470 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3471 | uint32_t DeclIDOffset = |
| 3472 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3473 | uint32_t TypeIndexOffset = |
| 3474 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3475 | |
| 3476 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 3477 | |
| 3478 | auto mapOffset = [&](uint32_t Offset, uint32_t BaseOffset, |
| 3479 | RemapBuilder &Remap) { |
| 3480 | if (Offset != None) |
| 3481 | Remap.insert(std::make_pair(Offset, |
| 3482 | static_cast<int>(BaseOffset - Offset))); |
| 3483 | }; |
| 3484 | mapOffset(SLocOffset, OM->SLocEntryBaseOffset, SLocRemap); |
| 3485 | mapOffset(IdentifierIDOffset, OM->BaseIdentifierID, IdentifierRemap); |
| 3486 | mapOffset(MacroIDOffset, OM->BaseMacroID, MacroRemap); |
| 3487 | mapOffset(PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID, |
| 3488 | PreprocessedEntityRemap); |
| 3489 | mapOffset(SubmoduleIDOffset, OM->BaseSubmoduleID, SubmoduleRemap); |
| 3490 | mapOffset(SelectorIDOffset, OM->BaseSelectorID, SelectorRemap); |
| 3491 | mapOffset(DeclIDOffset, OM->BaseDeclID, DeclRemap); |
| 3492 | mapOffset(TypeIndexOffset, OM->BaseTypeIndex, TypeRemap); |
| 3493 | |
| 3494 | // Global -> local mappings. |
| 3495 | F.GlobalToLocalDeclIDs[OM] = DeclIDOffset; |
| 3496 | } |
| 3497 | } |
| 3498 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3499 | ASTReader::ASTReadResult |
| 3500 | ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, |
| 3501 | const ModuleFile *ImportedBy, |
| 3502 | unsigned ClientLoadCapabilities) { |
| 3503 | unsigned Idx = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3504 | F.ModuleMapPath = ReadPath(F, Record, Idx); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3505 | |
| 3506 | // Try to resolve ModuleName in the current header search context and |
| 3507 | // verify that it is found in the same module map file as we saved. If the |
| 3508 | // top-level AST file is a main file, skip this check because there is no |
| 3509 | // usable header search context. |
| 3510 | assert(!F.ModuleName.empty() && |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3511 | "MODULE_NAME should come before MODULE_MAP_FILE"); |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 3512 | if (F.Kind == MK_ImplicitModule && ModuleMgr.begin()->Kind != MK_MainFile) { |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3513 | // An implicitly-loaded module file should have its module listed in some |
| 3514 | // module map file that we've already loaded. |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3515 | Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName); |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3516 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
| 3517 | const FileEntry *ModMap = M ? Map.getModuleMapFileForUniquing(M) : nullptr; |
| 3518 | if (!ModMap) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3519 | assert(ImportedBy && "top-level import should be verified"); |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3520 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) { |
| 3521 | if (auto *ASTFE = M ? M->getASTFile() : nullptr) |
| 3522 | // This module was defined by an imported (explicit) module. |
| 3523 | Diag(diag::err_module_file_conflict) << F.ModuleName << F.FileName |
| 3524 | << ASTFE->getName(); |
| 3525 | else |
| 3526 | // This module was built with a different module map. |
| 3527 | Diag(diag::err_imported_module_not_found) |
| 3528 | << F.ModuleName << F.FileName << ImportedBy->FileName |
| 3529 | << F.ModuleMapPath; |
| 3530 | } |
| 3531 | return OutOfDate; |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3532 | } |
| 3533 | |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3534 | assert(M->Name == F.ModuleName && "found module with different name"); |
| 3535 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3536 | // Check the primary module map file. |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3537 | const FileEntry *StoredModMap = FileMgr.getFile(F.ModuleMapPath); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3538 | if (StoredModMap == nullptr || StoredModMap != ModMap) { |
| 3539 | assert(ModMap && "found module is missing module map file"); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3540 | assert(ImportedBy && "top-level import should be verified"); |
| 3541 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3542 | Diag(diag::err_imported_module_modmap_changed) |
| 3543 | << F.ModuleName << ImportedBy->FileName |
| 3544 | << ModMap->getName() << F.ModuleMapPath; |
| 3545 | return OutOfDate; |
| 3546 | } |
| 3547 | |
| 3548 | llvm::SmallPtrSet<const FileEntry *, 1> AdditionalStoredMaps; |
| 3549 | for (unsigned I = 0, N = Record[Idx++]; I < N; ++I) { |
| 3550 | // FIXME: we should use input files rather than storing names. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3551 | std::string Filename = ReadPath(F, Record, Idx); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3552 | const FileEntry *F = |
| 3553 | FileMgr.getFile(Filename, false, false); |
| 3554 | if (F == nullptr) { |
| 3555 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3556 | Error("could not find file '" + Filename +"' referenced by AST file"); |
| 3557 | return OutOfDate; |
| 3558 | } |
| 3559 | AdditionalStoredMaps.insert(F); |
| 3560 | } |
| 3561 | |
| 3562 | // Check any additional module map files (e.g. module.private.modulemap) |
| 3563 | // that are not in the pcm. |
| 3564 | if (auto *AdditionalModuleMaps = Map.getAdditionalModuleMapFiles(M)) { |
| 3565 | for (const FileEntry *ModMap : *AdditionalModuleMaps) { |
| 3566 | // Remove files that match |
| 3567 | // Note: SmallPtrSet::erase is really remove |
| 3568 | if (!AdditionalStoredMaps.erase(ModMap)) { |
| 3569 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3570 | Diag(diag::err_module_different_modmap) |
| 3571 | << F.ModuleName << /*new*/0 << ModMap->getName(); |
| 3572 | return OutOfDate; |
| 3573 | } |
| 3574 | } |
| 3575 | } |
| 3576 | |
| 3577 | // Check any additional module map files that are in the pcm, but not |
| 3578 | // found in header search. Cases that match are already removed. |
| 3579 | for (const FileEntry *ModMap : AdditionalStoredMaps) { |
| 3580 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3581 | Diag(diag::err_module_different_modmap) |
| 3582 | << F.ModuleName << /*not new*/1 << ModMap->getName(); |
| 3583 | return OutOfDate; |
| 3584 | } |
| 3585 | } |
| 3586 | |
| 3587 | if (Listener) |
| 3588 | Listener->ReadModuleMapFile(F.ModuleMapPath); |
| 3589 | return Success; |
| 3590 | } |
| 3591 | |
| 3592 | |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3593 | /// \brief Move the given method to the back of the global list of methods. |
| 3594 | static void moveMethodToBackOfGlobalList(Sema &S, ObjCMethodDecl *Method) { |
| 3595 | // Find the entry for this selector in the method pool. |
| 3596 | Sema::GlobalMethodPool::iterator Known |
| 3597 | = S.MethodPool.find(Method->getSelector()); |
| 3598 | if (Known == S.MethodPool.end()) |
| 3599 | return; |
| 3600 | |
| 3601 | // Retrieve the appropriate method list. |
| 3602 | ObjCMethodList &Start = Method->isInstanceMethod()? Known->second.first |
| 3603 | : Known->second.second; |
| 3604 | bool Found = false; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3605 | for (ObjCMethodList *List = &Start; List; List = List->getNext()) { |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3606 | if (!Found) { |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3607 | if (List->getMethod() == Method) { |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3608 | Found = true; |
| 3609 | } else { |
| 3610 | // Keep searching. |
| 3611 | continue; |
| 3612 | } |
| 3613 | } |
| 3614 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3615 | if (List->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3616 | List->setMethod(List->getNext()->getMethod()); |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3617 | else |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3618 | List->setMethod(Method); |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3619 | } |
| 3620 | } |
| 3621 | |
Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 3622 | void ASTReader::makeNamesVisible(const HiddenNames &Names, Module *Owner) { |
Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 3623 | assert(Owner->NameVisibility != Module::Hidden && "nothing to make visible?"); |
Richard Smith | 20e883e | 2015-04-29 23:20:19 +0000 | [diff] [blame] | 3624 | for (Decl *D : Names) { |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 3625 | bool wasHidden = D->isHidden(); |
| 3626 | D->setVisibleDespiteOwningModule(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3627 | |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3628 | if (wasHidden && SemaObj) { |
| 3629 | if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D)) { |
| 3630 | moveMethodToBackOfGlobalList(*SemaObj, Method); |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3631 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3632 | } |
| 3633 | } |
| 3634 | } |
| 3635 | |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3636 | void ASTReader::makeModuleVisible(Module *Mod, |
Argyrios Kyrtzidis | 125df05 | 2013-02-01 16:36:12 +0000 | [diff] [blame] | 3637 | Module::NameVisibilityKind NameVisibility, |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 3638 | SourceLocation ImportLoc) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3639 | llvm::SmallPtrSet<Module *, 4> Visited; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3640 | SmallVector<Module *, 4> Stack; |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3641 | Stack.push_back(Mod); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3642 | while (!Stack.empty()) { |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3643 | Mod = Stack.pop_back_val(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3644 | |
| 3645 | if (NameVisibility <= Mod->NameVisibility) { |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3646 | // This module already has this level of visibility (or greater), so |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3647 | // there is nothing more to do. |
| 3648 | continue; |
| 3649 | } |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3650 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3651 | if (!Mod->isAvailable()) { |
| 3652 | // Modules that aren't available cannot be made visible. |
| 3653 | continue; |
| 3654 | } |
| 3655 | |
| 3656 | // Update the module's name visibility. |
| 3657 | Mod->NameVisibility = NameVisibility; |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3658 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3659 | // If we've already deserialized any names from this module, |
| 3660 | // mark them as visible. |
| 3661 | HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod); |
| 3662 | if (Hidden != HiddenNamesMap.end()) { |
Richard Smith | 57721ac | 2014-07-21 04:10:40 +0000 | [diff] [blame] | 3663 | auto HiddenNames = std::move(*Hidden); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3664 | HiddenNamesMap.erase(Hidden); |
Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 3665 | makeNamesVisible(HiddenNames.second, HiddenNames.first); |
Richard Smith | 57721ac | 2014-07-21 04:10:40 +0000 | [diff] [blame] | 3666 | assert(HiddenNamesMap.find(Mod) == HiddenNamesMap.end() && |
| 3667 | "making names visible added hidden names"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3668 | } |
Dmitri Gribenko | e9bcf5b | 2013-11-04 21:51:33 +0000 | [diff] [blame] | 3669 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3670 | // Push any exported modules onto the stack to be marked as visible. |
Argyrios Kyrtzidis | 8739f7b | 2013-02-19 19:34:40 +0000 | [diff] [blame] | 3671 | SmallVector<Module *, 16> Exports; |
| 3672 | Mod->getExportedModules(Exports); |
| 3673 | for (SmallVectorImpl<Module *>::iterator |
| 3674 | I = Exports.begin(), E = Exports.end(); I != E; ++I) { |
| 3675 | Module *Exported = *I; |
David Blaikie | 82e95a3 | 2014-11-19 07:49:47 +0000 | [diff] [blame] | 3676 | if (Visited.insert(Exported).second) |
Argyrios Kyrtzidis | 8739f7b | 2013-02-19 19:34:40 +0000 | [diff] [blame] | 3677 | Stack.push_back(Exported); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3678 | } |
| 3679 | } |
| 3680 | } |
| 3681 | |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 3682 | /// We've merged the definition \p MergedDef into the existing definition |
| 3683 | /// \p Def. Ensure that \p Def is made visible whenever \p MergedDef is made |
| 3684 | /// visible. |
| 3685 | void ASTReader::mergeDefinitionVisibility(NamedDecl *Def, |
| 3686 | NamedDecl *MergedDef) { |
Benjamin Kramer | a72a70a | 2016-10-17 13:00:44 +0000 | [diff] [blame] | 3687 | // FIXME: This doesn't correctly handle the case where MergedDef is visible |
| 3688 | // in modules other than its owning module. We should instead give the |
| 3689 | // ASTContext a list of merged definitions for Def. |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 3690 | if (Def->isHidden()) { |
| 3691 | // If MergedDef is visible or becomes visible, make the definition visible. |
Benjamin Kramer | a72a70a | 2016-10-17 13:00:44 +0000 | [diff] [blame] | 3692 | if (!MergedDef->isHidden()) |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 3693 | Def->setVisibleDespiteOwningModule(); |
Benjamin Kramer | a72a70a | 2016-10-17 13:00:44 +0000 | [diff] [blame] | 3694 | else if (getContext().getLangOpts().ModulesLocalVisibility) { |
| 3695 | getContext().mergeDefinitionIntoModule( |
| 3696 | Def, MergedDef->getImportedOwningModule(), |
| 3697 | /*NotifyListeners*/ false); |
| 3698 | PendingMergedDefinitionsToDeduplicate.insert(Def); |
| 3699 | } else { |
| 3700 | auto SubmoduleID = MergedDef->getOwningModuleID(); |
| 3701 | assert(SubmoduleID && "hidden definition in no module"); |
| 3702 | HiddenNamesMap[getSubmodule(SubmoduleID)].push_back(Def); |
| 3703 | } |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 3704 | } |
| 3705 | } |
| 3706 | |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3707 | bool ASTReader::loadGlobalIndex() { |
| 3708 | if (GlobalIndex) |
| 3709 | return false; |
| 3710 | |
| 3711 | if (TriedLoadingGlobalIndex || !UseGlobalIndex || |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3712 | !PP.getLangOpts().Modules) |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3713 | return true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3714 | |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3715 | // Try to load the global index. |
| 3716 | TriedLoadingGlobalIndex = true; |
| 3717 | StringRef ModuleCachePath |
| 3718 | = getPreprocessor().getHeaderSearchInfo().getModuleCachePath(); |
| 3719 | std::pair<GlobalModuleIndex *, GlobalModuleIndex::ErrorCode> Result |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3720 | = GlobalModuleIndex::readIndex(ModuleCachePath); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3721 | if (!Result.first) |
| 3722 | return true; |
| 3723 | |
| 3724 | GlobalIndex.reset(Result.first); |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 3725 | ModuleMgr.setGlobalIndex(GlobalIndex.get()); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3726 | return false; |
| 3727 | } |
| 3728 | |
| 3729 | bool ASTReader::isGlobalIndexUnavailable() const { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3730 | return PP.getLangOpts().Modules && UseGlobalIndex && |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3731 | !hasGlobalIndex() && TriedLoadingGlobalIndex; |
| 3732 | } |
| 3733 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3734 | static void updateModuleTimestamp(ModuleFile &MF) { |
| 3735 | // Overwrite the timestamp file contents so that file's mtime changes. |
| 3736 | std::string TimestampFilename = MF.getTimestampFilename(); |
Rafael Espindola | dae941a | 2014-08-25 18:17:04 +0000 | [diff] [blame] | 3737 | std::error_code EC; |
| 3738 | llvm::raw_fd_ostream OS(TimestampFilename, EC, llvm::sys::fs::F_Text); |
| 3739 | if (EC) |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3740 | return; |
| 3741 | OS << "Timestamp file\n"; |
Alex Lorenz | 0bafa02 | 2017-06-02 10:36:56 +0000 | [diff] [blame] | 3742 | OS.close(); |
| 3743 | OS.clear_error(); // Avoid triggering a fatal error. |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3744 | } |
| 3745 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3746 | /// \brief Given a cursor at the start of an AST file, scan ahead and drop the |
| 3747 | /// cursor into the start of the given block ID, returning false on success and |
| 3748 | /// true on failure. |
| 3749 | static bool SkipCursorToBlock(BitstreamCursor &Cursor, unsigned BlockID) { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3750 | while (true) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3751 | llvm::BitstreamEntry Entry = Cursor.advance(); |
| 3752 | switch (Entry.Kind) { |
| 3753 | case llvm::BitstreamEntry::Error: |
| 3754 | case llvm::BitstreamEntry::EndBlock: |
| 3755 | return true; |
| 3756 | |
| 3757 | case llvm::BitstreamEntry::Record: |
| 3758 | // Ignore top-level records. |
| 3759 | Cursor.skipRecord(Entry.ID); |
| 3760 | break; |
| 3761 | |
| 3762 | case llvm::BitstreamEntry::SubBlock: |
| 3763 | if (Entry.ID == BlockID) { |
| 3764 | if (Cursor.EnterSubBlock(BlockID)) |
| 3765 | return true; |
| 3766 | // Found it! |
| 3767 | return false; |
| 3768 | } |
| 3769 | |
| 3770 | if (Cursor.SkipBlock()) |
| 3771 | return true; |
| 3772 | } |
| 3773 | } |
| 3774 | } |
| 3775 | |
Benjamin Kramer | 0772c42 | 2016-02-13 13:42:54 +0000 | [diff] [blame] | 3776 | ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3777 | ModuleKind Type, |
| 3778 | SourceLocation ImportLoc, |
Graydon Hoare | e7196af | 2016-12-09 21:45:49 +0000 | [diff] [blame] | 3779 | unsigned ClientLoadCapabilities, |
| 3780 | SmallVectorImpl<ImportedSubmodule> *Imported) { |
Argyrios Kyrtzidis | dc9fdaf | 2013-05-24 05:44:08 +0000 | [diff] [blame] | 3781 | llvm::SaveAndRestore<SourceLocation> |
| 3782 | SetCurImportLocRAII(CurrentImportLoc, ImportLoc); |
| 3783 | |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 3784 | // Defer any pending actions until we get to the end of reading the AST file. |
| 3785 | Deserializing AnASTFile(this); |
| 3786 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3787 | // Bump the generation number. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3788 | unsigned PreviousGeneration = 0; |
| 3789 | if (ContextObj) |
| 3790 | PreviousGeneration = incrementGeneration(*ContextObj); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3791 | |
| 3792 | unsigned NumModules = ModuleMgr.size(); |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3793 | SmallVector<ImportedModule, 4> Loaded; |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 3794 | switch (ASTReadResult ReadResult = |
| 3795 | ReadASTCore(FileName, Type, ImportLoc, |
| 3796 | /*ImportedBy=*/nullptr, Loaded, 0, 0, |
| 3797 | ASTFileSignature(), ClientLoadCapabilities)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3798 | case Failure: |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3799 | case Missing: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3800 | case OutOfDate: |
| 3801 | case VersionMismatch: |
| 3802 | case ConfigurationMismatch: |
Ben Langmuir | 9801b25 | 2014-06-20 00:24:56 +0000 | [diff] [blame] | 3803 | case HadErrors: { |
| 3804 | llvm::SmallPtrSet<ModuleFile *, 4> LoadedSet; |
| 3805 | for (const ImportedModule &IM : Loaded) |
| 3806 | LoadedSet.insert(IM.Mod); |
| 3807 | |
Duncan P. N. Exon Smith | 8e6bc197 | 2017-01-28 23:02:12 +0000 | [diff] [blame] | 3808 | ModuleMgr.removeModules(ModuleMgr.begin() + NumModules, LoadedSet, |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3809 | PP.getLangOpts().Modules |
Duncan P. N. Exon Smith | 8e6bc197 | 2017-01-28 23:02:12 +0000 | [diff] [blame] | 3810 | ? &PP.getHeaderSearchInfo().getModuleMap() |
| 3811 | : nullptr); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3812 | |
| 3813 | // If we find that any modules are unusable, the global index is going |
| 3814 | // to be out-of-date. Just remove it. |
| 3815 | GlobalIndex.reset(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3816 | ModuleMgr.setGlobalIndex(nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3817 | return ReadResult; |
Ben Langmuir | 9801b25 | 2014-06-20 00:24:56 +0000 | [diff] [blame] | 3818 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3819 | case Success: |
| 3820 | break; |
| 3821 | } |
| 3822 | |
| 3823 | // Here comes stuff that we only do once the entire chain is loaded. |
| 3824 | |
| 3825 | // Load the AST blocks of all of the modules that we loaded. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3826 | for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(), |
| 3827 | MEnd = Loaded.end(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3828 | M != MEnd; ++M) { |
| 3829 | ModuleFile &F = *M->Mod; |
| 3830 | |
| 3831 | // Read the AST block. |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3832 | if (ASTReadResult Result = ReadASTBlock(F, ClientLoadCapabilities)) |
| 3833 | return Result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3834 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3835 | // Read the extension blocks. |
| 3836 | while (!SkipCursorToBlock(F.Stream, EXTENSION_BLOCK_ID)) { |
| 3837 | if (ASTReadResult Result = ReadExtensionBlock(F)) |
| 3838 | return Result; |
| 3839 | } |
| 3840 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3841 | // Once read, set the ModuleFile bit base offset and update the size in |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3842 | // bits of all files we've seen. |
| 3843 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 3844 | TotalModulesSizeInBits += F.SizeInBits; |
| 3845 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3846 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3847 | // Preload SLocEntries. |
| 3848 | for (unsigned I = 0, N = F.PreloadSLocEntries.size(); I != N; ++I) { |
| 3849 | int Index = int(F.PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
| 3850 | // Load it through the SourceManager and don't call ReadSLocEntry() |
| 3851 | // directly because the entry may have already been loaded in which case |
| 3852 | // calling ReadSLocEntry() directly would trigger an assertion in |
| 3853 | // SourceManager. |
| 3854 | SourceMgr.getLoadedSLocEntryByID(Index); |
| 3855 | } |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3856 | |
Richard Smith | ea74148 | 2017-05-01 22:10:47 +0000 | [diff] [blame] | 3857 | // Map the original source file ID into the ID space of the current |
| 3858 | // compilation. |
| 3859 | if (F.OriginalSourceFileID.isValid()) { |
| 3860 | F.OriginalSourceFileID = FileID::get( |
| 3861 | F.SLocEntryBaseID + F.OriginalSourceFileID.getOpaqueValue() - 1); |
| 3862 | } |
| 3863 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3864 | // Preload all the pending interesting identifiers by marking them out of |
| 3865 | // date. |
| 3866 | for (auto Offset : F.PreloadIdentifierOffsets) { |
| 3867 | const unsigned char *Data = reinterpret_cast<const unsigned char *>( |
| 3868 | F.IdentifierTableData + Offset); |
| 3869 | |
| 3870 | ASTIdentifierLookupTrait Trait(*this, F); |
| 3871 | auto KeyDataLen = Trait.ReadKeyDataLength(Data); |
| 3872 | auto Key = Trait.ReadKey(Data, KeyDataLen.first); |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 3873 | auto &II = PP.getIdentifierTable().getOwn(Key); |
| 3874 | II.setOutOfDate(true); |
| 3875 | |
| 3876 | // Mark this identifier as being from an AST file so that we can track |
| 3877 | // whether we need to serialize it. |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 3878 | markIdentifierFromAST(*this, II); |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 3879 | |
| 3880 | // Associate the ID with the identifier so that the writer can reuse it. |
| 3881 | auto ID = Trait.ReadIdentifierID(Data + KeyDataLen.first); |
| 3882 | SetIdentifierInfo(ID, &II); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3883 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3884 | } |
| 3885 | |
Douglas Gregor | 603cd86 | 2013-03-22 18:50:14 +0000 | [diff] [blame] | 3886 | // Setup the import locations and notify the module manager that we've |
| 3887 | // committed to these module files. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3888 | for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(), |
| 3889 | MEnd = Loaded.end(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3890 | M != MEnd; ++M) { |
| 3891 | ModuleFile &F = *M->Mod; |
Douglas Gregor | 603cd86 | 2013-03-22 18:50:14 +0000 | [diff] [blame] | 3892 | |
| 3893 | ModuleMgr.moduleFileAccepted(&F); |
| 3894 | |
| 3895 | // Set the import location. |
Argyrios Kyrtzidis | 71c1af8 | 2013-02-01 16:36:14 +0000 | [diff] [blame] | 3896 | F.DirectImportLoc = ImportLoc; |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 3897 | // FIXME: We assume that locations from PCH / preamble do not need |
| 3898 | // any translation. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3899 | if (!M->ImportedBy) |
| 3900 | F.ImportLoc = M->ImportLoc; |
| 3901 | else |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 3902 | F.ImportLoc = TranslateSourceLocation(*M->ImportedBy, M->ImportLoc); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3903 | } |
| 3904 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3905 | if (!PP.getLangOpts().CPlusPlus || |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 3906 | (Type != MK_ImplicitModule && Type != MK_ExplicitModule && |
| 3907 | Type != MK_PrebuiltModule)) { |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3908 | // Mark all of the identifiers in the identifier table as being out of date, |
| 3909 | // so that various accessors know to check the loaded modules when the |
| 3910 | // identifier is used. |
| 3911 | // |
| 3912 | // For C++ modules, we don't need information on many identifiers (just |
| 3913 | // those that provide macros or are poisoned), so we mark all of |
| 3914 | // the interesting ones via PreloadIdentifierOffsets. |
| 3915 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 3916 | IdEnd = PP.getIdentifierTable().end(); |
| 3917 | Id != IdEnd; ++Id) |
| 3918 | Id->second->setOutOfDate(true); |
| 3919 | } |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 3920 | // Mark selectors as out of date. |
| 3921 | for (auto Sel : SelectorGeneration) |
| 3922 | SelectorOutOfDate[Sel.first] = true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3923 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3924 | // Resolve any unresolved module exports. |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3925 | for (unsigned I = 0, N = UnresolvedModuleRefs.size(); I != N; ++I) { |
| 3926 | UnresolvedModuleRef &Unresolved = UnresolvedModuleRefs[I]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3927 | SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID); |
| 3928 | Module *ResolvedMod = getSubmodule(GlobalID); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3929 | |
| 3930 | switch (Unresolved.Kind) { |
| 3931 | case UnresolvedModuleRef::Conflict: |
| 3932 | if (ResolvedMod) { |
| 3933 | Module::Conflict Conflict; |
| 3934 | Conflict.Other = ResolvedMod; |
| 3935 | Conflict.Message = Unresolved.String.str(); |
| 3936 | Unresolved.Mod->Conflicts.push_back(Conflict); |
| 3937 | } |
| 3938 | continue; |
| 3939 | |
| 3940 | case UnresolvedModuleRef::Import: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3941 | if (ResolvedMod) |
Richard Smith | 38477db | 2015-05-02 00:45:56 +0000 | [diff] [blame] | 3942 | Unresolved.Mod->Imports.insert(ResolvedMod); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3943 | continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3944 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3945 | case UnresolvedModuleRef::Export: |
| 3946 | if (ResolvedMod || Unresolved.IsWildcard) |
| 3947 | Unresolved.Mod->Exports.push_back( |
| 3948 | Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard)); |
| 3949 | continue; |
| 3950 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3951 | } |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3952 | UnresolvedModuleRefs.clear(); |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 3953 | |
Graydon Hoare | e7196af | 2016-12-09 21:45:49 +0000 | [diff] [blame] | 3954 | if (Imported) |
| 3955 | Imported->append(ImportedModules.begin(), |
| 3956 | ImportedModules.end()); |
| 3957 | |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 3958 | // FIXME: How do we load the 'use'd modules? They may not be submodules. |
| 3959 | // Might be unnecessary as use declarations are only used to build the |
| 3960 | // module itself. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3961 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3962 | if (ContextObj) |
| 3963 | InitializeContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3964 | |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 3965 | if (SemaObj) |
| 3966 | UpdateSema(); |
| 3967 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3968 | if (DeserializationListener) |
| 3969 | DeserializationListener->ReaderInitialized(this); |
| 3970 | |
| 3971 | ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule(); |
Yaron Keren | 8b56366 | 2015-10-03 10:46:20 +0000 | [diff] [blame] | 3972 | if (PrimaryModule.OriginalSourceFileID.isValid()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3973 | // If this AST file is a precompiled preamble, then set the |
| 3974 | // preamble file ID of the source manager to the file source file |
| 3975 | // from which the preamble was built. |
| 3976 | if (Type == MK_Preamble) { |
| 3977 | SourceMgr.setPreambleFileID(PrimaryModule.OriginalSourceFileID); |
| 3978 | } else if (Type == MK_MainFile) { |
| 3979 | SourceMgr.setMainFileID(PrimaryModule.OriginalSourceFileID); |
| 3980 | } |
| 3981 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3982 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3983 | // For any Objective-C class definitions we have already loaded, make sure |
| 3984 | // that we load any additional categories. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3985 | if (ContextObj) { |
| 3986 | for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) { |
| 3987 | loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(), |
| 3988 | ObjCClassesLoaded[I], |
| 3989 | PreviousGeneration); |
| 3990 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3991 | } |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3992 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3993 | if (PP.getHeaderSearchInfo() |
| 3994 | .getHeaderSearchOpts() |
| 3995 | .ModulesValidateOncePerBuildSession) { |
| 3996 | // Now we are certain that the module and all modules it depends on are |
| 3997 | // up to date. Create or update timestamp files for modules that are |
| 3998 | // located in the module cache (not for PCH files that could be anywhere |
| 3999 | // in the filesystem). |
| 4000 | for (unsigned I = 0, N = Loaded.size(); I != N; ++I) { |
| 4001 | ImportedModule &M = Loaded[I]; |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 4002 | if (M.Mod->Kind == MK_ImplicitModule) { |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 4003 | updateModuleTimestamp(*M.Mod); |
| 4004 | } |
| 4005 | } |
| 4006 | } |
| 4007 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4008 | return Success; |
| 4009 | } |
| 4010 | |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4011 | static ASTFileSignature readASTFileSignature(StringRef PCH); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4012 | |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4013 | /// \brief Whether \p Stream starts with the AST/PCH file magic number 'CPCH'. |
| 4014 | static bool startsWithASTFileMagic(BitstreamCursor &Stream) { |
Peter Collingbourne | 028eb5a | 2016-11-02 00:08:19 +0000 | [diff] [blame] | 4015 | return Stream.canSkipToPos(4) && |
| 4016 | Stream.Read(8) == 'C' && |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4017 | Stream.Read(8) == 'P' && |
| 4018 | Stream.Read(8) == 'C' && |
| 4019 | Stream.Read(8) == 'H'; |
| 4020 | } |
| 4021 | |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4022 | static unsigned moduleKindForDiagnostic(ModuleKind Kind) { |
| 4023 | switch (Kind) { |
| 4024 | case MK_PCH: |
| 4025 | return 0; // PCH |
| 4026 | case MK_ImplicitModule: |
| 4027 | case MK_ExplicitModule: |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 4028 | case MK_PrebuiltModule: |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4029 | return 1; // module |
| 4030 | case MK_MainFile: |
| 4031 | case MK_Preamble: |
| 4032 | return 2; // main source file |
| 4033 | } |
| 4034 | llvm_unreachable("unknown module kind"); |
| 4035 | } |
| 4036 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4037 | ASTReader::ASTReadResult |
| 4038 | ASTReader::ReadASTCore(StringRef FileName, |
| 4039 | ModuleKind Type, |
| 4040 | SourceLocation ImportLoc, |
| 4041 | ModuleFile *ImportedBy, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4042 | SmallVectorImpl<ImportedModule> &Loaded, |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4043 | off_t ExpectedSize, time_t ExpectedModTime, |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4044 | ASTFileSignature ExpectedSignature, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4045 | unsigned ClientLoadCapabilities) { |
| 4046 | ModuleFile *M; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4047 | std::string ErrorStr; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4048 | ModuleManager::AddModuleResult AddResult |
| 4049 | = ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy, |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 4050 | getGeneration(), ExpectedSize, ExpectedModTime, |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4051 | ExpectedSignature, readASTFileSignature, |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4052 | M, ErrorStr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4053 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4054 | switch (AddResult) { |
| 4055 | case ModuleManager::AlreadyLoaded: |
| 4056 | return Success; |
| 4057 | |
| 4058 | case ModuleManager::NewlyLoaded: |
| 4059 | // Load module file below. |
| 4060 | break; |
| 4061 | |
| 4062 | case ModuleManager::Missing: |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 4063 | // The module file was missing; if the client can handle that, return |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4064 | // it. |
| 4065 | if (ClientLoadCapabilities & ARR_Missing) |
| 4066 | return Missing; |
| 4067 | |
| 4068 | // Otherwise, return an error. |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4069 | Diag(diag::err_module_file_not_found) << moduleKindForDiagnostic(Type) |
Adrian Prantl | b3b5a73 | 2016-08-29 20:46:59 +0000 | [diff] [blame] | 4070 | << FileName << !ErrorStr.empty() |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4071 | << ErrorStr; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4072 | return Failure; |
| 4073 | |
| 4074 | case ModuleManager::OutOfDate: |
| 4075 | // We couldn't load the module file because it is out-of-date. If the |
| 4076 | // client can handle out-of-date, return it. |
| 4077 | if (ClientLoadCapabilities & ARR_OutOfDate) |
| 4078 | return OutOfDate; |
| 4079 | |
| 4080 | // Otherwise, return an error. |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4081 | Diag(diag::err_module_file_out_of_date) << moduleKindForDiagnostic(Type) |
Adrian Prantl | 9a06a88 | 2016-08-29 20:46:56 +0000 | [diff] [blame] | 4082 | << FileName << !ErrorStr.empty() |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4083 | << ErrorStr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4084 | return Failure; |
| 4085 | } |
| 4086 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4087 | assert(M && "Missing module file"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4088 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4089 | ModuleFile &F = *M; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4090 | BitstreamCursor &Stream = F.Stream; |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4091 | Stream = BitstreamCursor(PCHContainerRdr.ExtractPCH(*F.Buffer)); |
Adrian Prantl | cbc368c | 2015-02-25 02:44:04 +0000 | [diff] [blame] | 4092 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4093 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4094 | // Sniff for the signature. |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4095 | if (!startsWithASTFileMagic(Stream)) { |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4096 | Diag(diag::err_module_file_invalid) << moduleKindForDiagnostic(Type) |
| 4097 | << FileName; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4098 | return Failure; |
| 4099 | } |
| 4100 | |
| 4101 | // This is used for compatibility with older PCH formats. |
| 4102 | bool HaveReadControlBlock = false; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4103 | while (true) { |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4104 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4105 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4106 | switch (Entry.Kind) { |
| 4107 | case llvm::BitstreamEntry::Error: |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4108 | case llvm::BitstreamEntry::Record: |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4109 | case llvm::BitstreamEntry::EndBlock: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4110 | Error("invalid record at top-level of AST file"); |
| 4111 | return Failure; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4112 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4113 | case llvm::BitstreamEntry::SubBlock: |
| 4114 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4115 | } |
| 4116 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4117 | switch (Entry.ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4118 | case CONTROL_BLOCK_ID: |
| 4119 | HaveReadControlBlock = true; |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4120 | switch (ReadControlBlock(F, Loaded, ImportedBy, ClientLoadCapabilities)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4121 | case Success: |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4122 | // Check that we didn't try to load a non-module AST file as a module. |
| 4123 | // |
| 4124 | // FIXME: Should we also perform the converse check? Loading a module as |
| 4125 | // a PCH file sort of works, but it's a bit wonky. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 4126 | if ((Type == MK_ImplicitModule || Type == MK_ExplicitModule || |
| 4127 | Type == MK_PrebuiltModule) && |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4128 | F.ModuleName.empty()) { |
| 4129 | auto Result = (Type == MK_ImplicitModule) ? OutOfDate : Failure; |
| 4130 | if (Result != OutOfDate || |
| 4131 | (ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 4132 | Diag(diag::err_module_file_not_module) << FileName; |
| 4133 | return Result; |
| 4134 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4135 | break; |
| 4136 | |
| 4137 | case Failure: return Failure; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4138 | case Missing: return Missing; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4139 | case OutOfDate: return OutOfDate; |
| 4140 | case VersionMismatch: return VersionMismatch; |
| 4141 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 4142 | case HadErrors: return HadErrors; |
| 4143 | } |
| 4144 | break; |
Richard Smith | f8c3255 | 2015-09-02 17:45:54 +0000 | [diff] [blame] | 4145 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4146 | case AST_BLOCK_ID: |
| 4147 | if (!HaveReadControlBlock) { |
| 4148 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 4149 | Diag(diag::err_pch_version_too_old); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4150 | return VersionMismatch; |
| 4151 | } |
| 4152 | |
| 4153 | // Record that we've loaded this module. |
| 4154 | Loaded.push_back(ImportedModule(M, ImportedBy, ImportLoc)); |
| 4155 | return Success; |
| 4156 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4157 | case UNHASHED_CONTROL_BLOCK_ID: |
| 4158 | // This block is handled using look-ahead during ReadControlBlock. We |
| 4159 | // shouldn't get here! |
| 4160 | Error("malformed block record in AST file"); |
| 4161 | return Failure; |
| 4162 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4163 | default: |
| 4164 | if (Stream.SkipBlock()) { |
| 4165 | Error("malformed block record in AST file"); |
| 4166 | return Failure; |
| 4167 | } |
| 4168 | break; |
| 4169 | } |
| 4170 | } |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4171 | |
| 4172 | return Success; |
| 4173 | } |
| 4174 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4175 | ASTReader::ASTReadResult |
| 4176 | ASTReader::readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy, |
| 4177 | unsigned ClientLoadCapabilities) { |
| 4178 | const HeaderSearchOptions &HSOpts = |
| 4179 | PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 4180 | bool AllowCompatibleConfigurationMismatch = |
| 4181 | F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule; |
| 4182 | |
| 4183 | ASTReadResult Result = readUnhashedControlBlockImpl( |
| 4184 | &F, F.Data, ClientLoadCapabilities, AllowCompatibleConfigurationMismatch, |
| 4185 | Listener.get(), |
| 4186 | WasImportedBy ? false : HSOpts.ModulesValidateDiagnosticOptions); |
| 4187 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4188 | // If F was directly imported by another module, it's implicitly validated by |
| 4189 | // the importing module. |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4190 | if (DisableValidation || WasImportedBy || |
| 4191 | (AllowConfigurationMismatch && Result == ConfigurationMismatch)) |
| 4192 | return Success; |
| 4193 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4194 | if (Result == Failure) { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4195 | Error("malformed block record in AST file"); |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4196 | return Failure; |
| 4197 | } |
| 4198 | |
| 4199 | if (Result == OutOfDate && F.Kind == MK_ImplicitModule) { |
| 4200 | // If this module has already been finalized in the PCMCache, we're stuck |
| 4201 | // with it; we can only load a single version of each module. |
| 4202 | // |
| 4203 | // This can happen when a module is imported in two contexts: in one, as a |
| 4204 | // user module; in another, as a system module (due to an import from |
| 4205 | // another module marked with the [system] flag). It usually indicates a |
| 4206 | // bug in the module map: this module should also be marked with [system]. |
| 4207 | // |
| 4208 | // If -Wno-system-headers (the default), and the first import is as a |
| 4209 | // system module, then validation will fail during the as-user import, |
| 4210 | // since -Werror flags won't have been validated. However, it's reasonable |
| 4211 | // to treat this consistently as a system module. |
| 4212 | // |
| 4213 | // If -Wsystem-headers, the PCM on disk was built with |
| 4214 | // -Wno-system-headers, and the first import is as a user module, then |
| 4215 | // validation will fail during the as-system import since the PCM on disk |
| 4216 | // doesn't guarantee that -Werror was respected. However, the -Werror |
| 4217 | // flags were checked during the initial as-user import. |
| 4218 | if (PCMCache.isBufferFinal(F.FileName)) { |
| 4219 | Diag(diag::warn_module_system_bit_conflict) << F.FileName; |
| 4220 | return Success; |
| 4221 | } |
| 4222 | } |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4223 | |
| 4224 | return Result; |
| 4225 | } |
| 4226 | |
| 4227 | ASTReader::ASTReadResult ASTReader::readUnhashedControlBlockImpl( |
| 4228 | ModuleFile *F, llvm::StringRef StreamData, unsigned ClientLoadCapabilities, |
| 4229 | bool AllowCompatibleConfigurationMismatch, ASTReaderListener *Listener, |
| 4230 | bool ValidateDiagnosticOptions) { |
| 4231 | // Initialize a stream. |
| 4232 | BitstreamCursor Stream(StreamData); |
| 4233 | |
| 4234 | // Sniff for the signature. |
| 4235 | if (!startsWithASTFileMagic(Stream)) |
| 4236 | return Failure; |
| 4237 | |
| 4238 | // Scan for the UNHASHED_CONTROL_BLOCK_ID block. |
| 4239 | if (SkipCursorToBlock(Stream, UNHASHED_CONTROL_BLOCK_ID)) |
| 4240 | return Failure; |
| 4241 | |
| 4242 | // Read all of the records in the options block. |
| 4243 | RecordData Record; |
| 4244 | ASTReadResult Result = Success; |
| 4245 | while (1) { |
| 4246 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4247 | |
| 4248 | switch (Entry.Kind) { |
| 4249 | case llvm::BitstreamEntry::Error: |
| 4250 | case llvm::BitstreamEntry::SubBlock: |
| 4251 | return Failure; |
| 4252 | |
| 4253 | case llvm::BitstreamEntry::EndBlock: |
| 4254 | return Result; |
| 4255 | |
| 4256 | case llvm::BitstreamEntry::Record: |
| 4257 | // The interesting case. |
| 4258 | break; |
| 4259 | } |
| 4260 | |
| 4261 | // Read and process a record. |
| 4262 | Record.clear(); |
| 4263 | switch ( |
| 4264 | (UnhashedControlBlockRecordTypes)Stream.readRecord(Entry.ID, Record)) { |
| 4265 | case SIGNATURE: { |
| 4266 | if (F) |
| 4267 | std::copy(Record.begin(), Record.end(), F->Signature.data()); |
| 4268 | break; |
| 4269 | } |
| 4270 | case DIAGNOSTIC_OPTIONS: { |
| 4271 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
| 4272 | if (Listener && ValidateDiagnosticOptions && |
| 4273 | !AllowCompatibleConfigurationMismatch && |
| 4274 | ParseDiagnosticOptions(Record, Complain, *Listener)) |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4275 | Result = OutOfDate; // Don't return early. Read the signature. |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4276 | break; |
| 4277 | } |
| 4278 | case DIAG_PRAGMA_MAPPINGS: |
| 4279 | if (!F) |
| 4280 | break; |
| 4281 | if (F->PragmaDiagMappings.empty()) |
| 4282 | F->PragmaDiagMappings.swap(Record); |
| 4283 | else |
| 4284 | F->PragmaDiagMappings.insert(F->PragmaDiagMappings.end(), |
| 4285 | Record.begin(), Record.end()); |
| 4286 | break; |
| 4287 | } |
| 4288 | } |
| 4289 | } |
| 4290 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4291 | /// Parse a record and blob containing module file extension metadata. |
| 4292 | static bool parseModuleFileExtensionMetadata( |
| 4293 | const SmallVectorImpl<uint64_t> &Record, |
| 4294 | StringRef Blob, |
| 4295 | ModuleFileExtensionMetadata &Metadata) { |
| 4296 | if (Record.size() < 4) return true; |
| 4297 | |
| 4298 | Metadata.MajorVersion = Record[0]; |
| 4299 | Metadata.MinorVersion = Record[1]; |
| 4300 | |
| 4301 | unsigned BlockNameLen = Record[2]; |
| 4302 | unsigned UserInfoLen = Record[3]; |
| 4303 | |
| 4304 | if (BlockNameLen + UserInfoLen > Blob.size()) return true; |
| 4305 | |
| 4306 | Metadata.BlockName = std::string(Blob.data(), Blob.data() + BlockNameLen); |
| 4307 | Metadata.UserInfo = std::string(Blob.data() + BlockNameLen, |
| 4308 | Blob.data() + BlockNameLen + UserInfoLen); |
| 4309 | return false; |
| 4310 | } |
| 4311 | |
| 4312 | ASTReader::ASTReadResult ASTReader::ReadExtensionBlock(ModuleFile &F) { |
| 4313 | BitstreamCursor &Stream = F.Stream; |
| 4314 | |
| 4315 | RecordData Record; |
| 4316 | while (true) { |
| 4317 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4318 | switch (Entry.Kind) { |
| 4319 | case llvm::BitstreamEntry::SubBlock: |
| 4320 | if (Stream.SkipBlock()) |
| 4321 | return Failure; |
| 4322 | |
| 4323 | continue; |
| 4324 | |
| 4325 | case llvm::BitstreamEntry::EndBlock: |
| 4326 | return Success; |
| 4327 | |
| 4328 | case llvm::BitstreamEntry::Error: |
| 4329 | return HadErrors; |
| 4330 | |
| 4331 | case llvm::BitstreamEntry::Record: |
| 4332 | break; |
| 4333 | } |
| 4334 | |
| 4335 | Record.clear(); |
| 4336 | StringRef Blob; |
| 4337 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
| 4338 | switch (RecCode) { |
| 4339 | case EXTENSION_METADATA: { |
| 4340 | ModuleFileExtensionMetadata Metadata; |
| 4341 | if (parseModuleFileExtensionMetadata(Record, Blob, Metadata)) |
| 4342 | return Failure; |
| 4343 | |
| 4344 | // Find a module file extension with this block name. |
| 4345 | auto Known = ModuleFileExtensions.find(Metadata.BlockName); |
| 4346 | if (Known == ModuleFileExtensions.end()) break; |
| 4347 | |
| 4348 | // Form a reader. |
| 4349 | if (auto Reader = Known->second->createExtensionReader(Metadata, *this, |
| 4350 | F, Stream)) { |
| 4351 | F.ExtensionReaders.push_back(std::move(Reader)); |
| 4352 | } |
| 4353 | |
| 4354 | break; |
| 4355 | } |
| 4356 | } |
| 4357 | } |
| 4358 | |
| 4359 | return Success; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4360 | } |
| 4361 | |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4362 | void ASTReader::InitializeContext() { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4363 | assert(ContextObj && "no context to initialize"); |
| 4364 | ASTContext &Context = *ContextObj; |
| 4365 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4366 | // If there's a listener, notify them that we "read" the translation unit. |
| 4367 | if (DeserializationListener) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4368 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4369 | Context.getTranslationUnitDecl()); |
| 4370 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4371 | // FIXME: Find a better way to deal with collisions between these |
| 4372 | // built-in types. Right now, we just ignore the problem. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4373 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4374 | // Load the special types. |
| 4375 | if (SpecialTypes.size() >= NumSpecialTypeIDs) { |
| 4376 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 4377 | if (!Context.CFConstantStringTypeDecl) |
| 4378 | Context.setCFConstantStringType(GetType(String)); |
| 4379 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4380 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4381 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 4382 | QualType FileType = GetType(File); |
| 4383 | if (FileType.isNull()) { |
| 4384 | Error("FILE type is NULL"); |
| 4385 | return; |
| 4386 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4387 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4388 | if (!Context.FILEDecl) { |
| 4389 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 4390 | Context.setFILEDecl(Typedef->getDecl()); |
| 4391 | else { |
| 4392 | const TagType *Tag = FileType->getAs<TagType>(); |
| 4393 | if (!Tag) { |
| 4394 | Error("Invalid FILE type in AST file"); |
| 4395 | return; |
| 4396 | } |
| 4397 | Context.setFILEDecl(Tag->getDecl()); |
| 4398 | } |
| 4399 | } |
| 4400 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4401 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4402 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) { |
| 4403 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 4404 | if (Jmp_bufType.isNull()) { |
| 4405 | Error("jmp_buf type is NULL"); |
| 4406 | return; |
| 4407 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4408 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4409 | if (!Context.jmp_bufDecl) { |
| 4410 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 4411 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 4412 | else { |
| 4413 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 4414 | if (!Tag) { |
| 4415 | Error("Invalid jmp_buf type in AST file"); |
| 4416 | return; |
| 4417 | } |
| 4418 | Context.setjmp_bufDecl(Tag->getDecl()); |
| 4419 | } |
| 4420 | } |
| 4421 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4422 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4423 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) { |
| 4424 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 4425 | if (Sigjmp_bufType.isNull()) { |
| 4426 | Error("sigjmp_buf type is NULL"); |
| 4427 | return; |
| 4428 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4429 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4430 | if (!Context.sigjmp_bufDecl) { |
| 4431 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 4432 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 4433 | else { |
| 4434 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 4435 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 4436 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 4437 | } |
| 4438 | } |
| 4439 | } |
| 4440 | |
| 4441 | if (unsigned ObjCIdRedef |
| 4442 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 4443 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 4444 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 4445 | } |
| 4446 | |
| 4447 | if (unsigned ObjCClassRedef |
| 4448 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 4449 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 4450 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 4451 | } |
| 4452 | |
| 4453 | if (unsigned ObjCSelRedef |
| 4454 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 4455 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 4456 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 4457 | } |
| 4458 | |
| 4459 | if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) { |
| 4460 | QualType Ucontext_tType = GetType(Ucontext_t); |
| 4461 | if (Ucontext_tType.isNull()) { |
| 4462 | Error("ucontext_t type is NULL"); |
| 4463 | return; |
| 4464 | } |
| 4465 | |
| 4466 | if (!Context.ucontext_tDecl) { |
| 4467 | if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>()) |
| 4468 | Context.setucontext_tDecl(Typedef->getDecl()); |
| 4469 | else { |
| 4470 | const TagType *Tag = Ucontext_tType->getAs<TagType>(); |
| 4471 | assert(Tag && "Invalid ucontext_t type in AST file"); |
| 4472 | Context.setucontext_tDecl(Tag->getDecl()); |
| 4473 | } |
| 4474 | } |
| 4475 | } |
| 4476 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4477 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4478 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
| 4479 | |
| 4480 | // If there were any CUDA special declarations, deserialize them. |
| 4481 | if (!CUDASpecialDeclRefs.empty()) { |
| 4482 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 4483 | Context.setcudaConfigureCallDecl( |
| 4484 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 4485 | } |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4486 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4487 | // Re-export any modules that were imported by a non-module AST file. |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4488 | // FIXME: This does not make macro-only imports visible again. |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4489 | for (auto &Import : ImportedModules) { |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4490 | if (Module *Imported = getSubmodule(Import.ID)) { |
Argyrios Kyrtzidis | 125df05 | 2013-02-01 16:36:12 +0000 | [diff] [blame] | 4491 | makeModuleVisible(Imported, Module::AllVisible, |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4492 | /*ImportLoc=*/Import.ImportLoc); |
Ben Langmuir | 6d25fdc | 2016-02-11 17:04:42 +0000 | [diff] [blame] | 4493 | if (Import.ImportLoc.isValid()) |
| 4494 | PP.makeModuleVisible(Imported, Import.ImportLoc); |
| 4495 | // FIXME: should we tell Sema to make the module visible too? |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4496 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4497 | } |
| 4498 | ImportedModules.clear(); |
| 4499 | } |
| 4500 | |
| 4501 | void ASTReader::finalizeForWriting() { |
Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 4502 | // Nothing to do for now. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4503 | } |
| 4504 | |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4505 | /// \brief Reads and return the signature record from \p PCH's control block, or |
| 4506 | /// else returns 0. |
| 4507 | static ASTFileSignature readASTFileSignature(StringRef PCH) { |
| 4508 | BitstreamCursor Stream(PCH); |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4509 | if (!startsWithASTFileMagic(Stream)) |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4510 | return ASTFileSignature(); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4511 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4512 | // Scan for the UNHASHED_CONTROL_BLOCK_ID block. |
| 4513 | if (SkipCursorToBlock(Stream, UNHASHED_CONTROL_BLOCK_ID)) |
| 4514 | return ASTFileSignature(); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4515 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4516 | // Scan for SIGNATURE inside the diagnostic options block. |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4517 | ASTReader::RecordData Record; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4518 | while (true) { |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4519 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
Simon Pilgrim | 0b33f11 | 2016-11-16 16:11:08 +0000 | [diff] [blame] | 4520 | if (Entry.Kind != llvm::BitstreamEntry::Record) |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4521 | return ASTFileSignature(); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4522 | |
| 4523 | Record.clear(); |
| 4524 | StringRef Blob; |
| 4525 | if (SIGNATURE == Stream.readRecord(Entry.ID, Record, &Blob)) |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4526 | return {{{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2], |
| 4527 | (uint32_t)Record[3], (uint32_t)Record[4]}}}; |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4528 | } |
| 4529 | } |
| 4530 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4531 | /// \brief Retrieve the name of the original source file name |
| 4532 | /// directly from the AST file, without actually loading the AST |
| 4533 | /// file. |
Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame] | 4534 | std::string ASTReader::getOriginalSourceFile( |
| 4535 | const std::string &ASTFileName, FileManager &FileMgr, |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 4536 | const PCHContainerReader &PCHContainerRdr, DiagnosticsEngine &Diags) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4537 | // Open the AST file. |
Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 4538 | auto Buffer = FileMgr.getBufferForFile(ASTFileName); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4539 | if (!Buffer) { |
Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 4540 | Diags.Report(diag::err_fe_unable_to_read_pch_file) |
| 4541 | << ASTFileName << Buffer.getError().message(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4542 | return std::string(); |
| 4543 | } |
| 4544 | |
| 4545 | // Initialize the stream |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4546 | BitstreamCursor Stream(PCHContainerRdr.ExtractPCH(**Buffer)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4547 | |
| 4548 | // Sniff for the signature. |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4549 | if (!startsWithASTFileMagic(Stream)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4550 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
| 4551 | return std::string(); |
| 4552 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4553 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4554 | // Scan for the CONTROL_BLOCK_ID block. |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4555 | if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4556 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
| 4557 | return std::string(); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4558 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4559 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4560 | // Scan for ORIGINAL_FILE inside the control block. |
| 4561 | RecordData Record; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4562 | while (true) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4563 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4564 | if (Entry.Kind == llvm::BitstreamEntry::EndBlock) |
| 4565 | return std::string(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4566 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4567 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| 4568 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
| 4569 | return std::string(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4570 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4571 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4572 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4573 | StringRef Blob; |
| 4574 | if (Stream.readRecord(Entry.ID, Record, &Blob) == ORIGINAL_FILE) |
| 4575 | return Blob.str(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4576 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4577 | } |
| 4578 | |
| 4579 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4580 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4581 | class SimplePCHValidator : public ASTReaderListener { |
| 4582 | const LangOptions &ExistingLangOpts; |
| 4583 | const TargetOptions &ExistingTargetOpts; |
| 4584 | const PreprocessorOptions &ExistingPPOpts; |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4585 | std::string ExistingModuleCachePath; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4586 | FileManager &FileMgr; |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4587 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4588 | public: |
| 4589 | SimplePCHValidator(const LangOptions &ExistingLangOpts, |
| 4590 | const TargetOptions &ExistingTargetOpts, |
| 4591 | const PreprocessorOptions &ExistingPPOpts, |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4592 | StringRef ExistingModuleCachePath, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4593 | FileManager &FileMgr) |
| 4594 | : ExistingLangOpts(ExistingLangOpts), |
| 4595 | ExistingTargetOpts(ExistingTargetOpts), |
| 4596 | ExistingPPOpts(ExistingPPOpts), |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4597 | ExistingModuleCachePath(ExistingModuleCachePath), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4598 | FileMgr(FileMgr) |
| 4599 | { |
| 4600 | } |
| 4601 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 4602 | bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, |
| 4603 | bool AllowCompatibleDifferences) override { |
| 4604 | return checkLanguageOptions(ExistingLangOpts, LangOpts, nullptr, |
| 4605 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4606 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4607 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 4608 | bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, |
| 4609 | bool AllowCompatibleDifferences) override { |
| 4610 | return checkTargetOptions(ExistingTargetOpts, TargetOpts, nullptr, |
| 4611 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4612 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4613 | |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4614 | bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 4615 | StringRef SpecificModuleCachePath, |
| 4616 | bool Complain) override { |
| 4617 | return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 4618 | ExistingModuleCachePath, |
| 4619 | nullptr, ExistingLangOpts); |
| 4620 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4621 | |
Craig Topper | 3e89dfe | 2014-03-13 02:13:41 +0000 | [diff] [blame] | 4622 | bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 4623 | bool Complain, |
| 4624 | std::string &SuggestedPredefines) override { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4625 | return checkPreprocessorOptions(ExistingPPOpts, PPOpts, nullptr, FileMgr, |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 4626 | SuggestedPredefines, ExistingLangOpts); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4627 | } |
| 4628 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4629 | |
| 4630 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4631 | |
Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame] | 4632 | bool ASTReader::readASTFileControlBlock( |
| 4633 | StringRef Filename, FileManager &FileMgr, |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 4634 | const PCHContainerReader &PCHContainerRdr, |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4635 | bool FindModuleFileExtensions, |
Manman Ren | 47a4445 | 2016-07-26 17:12:17 +0000 | [diff] [blame] | 4636 | ASTReaderListener &Listener, bool ValidateDiagnosticOptions) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4637 | // Open the AST file. |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 4638 | // FIXME: This allows use of the VFS; we do not allow use of the |
| 4639 | // VFS when actually loading a module. |
Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 4640 | auto Buffer = FileMgr.getBufferForFile(Filename); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4641 | if (!Buffer) { |
| 4642 | return true; |
| 4643 | } |
| 4644 | |
| 4645 | // Initialize the stream |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4646 | StringRef Bytes = PCHContainerRdr.ExtractPCH(**Buffer); |
| 4647 | BitstreamCursor Stream(Bytes); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4648 | |
| 4649 | // Sniff for the signature. |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4650 | if (!startsWithASTFileMagic(Stream)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4651 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4652 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4653 | // Scan for the CONTROL_BLOCK_ID block. |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4654 | if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4655 | return true; |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4656 | |
| 4657 | bool NeedsInputFiles = Listener.needsInputFileVisitation(); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 4658 | bool NeedsSystemInputFiles = Listener.needsSystemInputFileVisitation(); |
Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4659 | bool NeedsImports = Listener.needsImportVisitation(); |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4660 | BitstreamCursor InputFilesCursor; |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4661 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4662 | RecordData Record; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4663 | std::string ModuleDir; |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4664 | bool DoneWithControlBlock = false; |
| 4665 | while (!DoneWithControlBlock) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4666 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4667 | |
| 4668 | switch (Entry.Kind) { |
| 4669 | case llvm::BitstreamEntry::SubBlock: { |
| 4670 | switch (Entry.ID) { |
| 4671 | case OPTIONS_BLOCK_ID: { |
| 4672 | std::string IgnoredSuggestedPredefines; |
| 4673 | if (ReadOptionsBlock(Stream, ARR_ConfigurationMismatch | ARR_OutOfDate, |
| 4674 | /*AllowCompatibleConfigurationMismatch*/ false, |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4675 | Listener, IgnoredSuggestedPredefines) != Success) |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4676 | return true; |
| 4677 | break; |
| 4678 | } |
| 4679 | |
| 4680 | case INPUT_FILES_BLOCK_ID: |
| 4681 | InputFilesCursor = Stream; |
| 4682 | if (Stream.SkipBlock() || |
| 4683 | (NeedsInputFiles && |
| 4684 | ReadBlockAbbrevs(InputFilesCursor, INPUT_FILES_BLOCK_ID))) |
| 4685 | return true; |
| 4686 | break; |
| 4687 | |
| 4688 | default: |
| 4689 | if (Stream.SkipBlock()) |
| 4690 | return true; |
| 4691 | break; |
| 4692 | } |
| 4693 | |
| 4694 | continue; |
| 4695 | } |
| 4696 | |
| 4697 | case llvm::BitstreamEntry::EndBlock: |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4698 | DoneWithControlBlock = true; |
| 4699 | break; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4700 | |
| 4701 | case llvm::BitstreamEntry::Error: |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4702 | return true; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4703 | |
| 4704 | case llvm::BitstreamEntry::Record: |
| 4705 | break; |
| 4706 | } |
| 4707 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4708 | if (DoneWithControlBlock) break; |
| 4709 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4710 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4711 | StringRef Blob; |
| 4712 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4713 | switch ((ControlRecordTypes)RecCode) { |
| 4714 | case METADATA: { |
| 4715 | if (Record[0] != VERSION_MAJOR) |
| 4716 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4717 | |
Douglas Gregor | bf7fc9c | 2013-03-27 16:47:18 +0000 | [diff] [blame] | 4718 | if (Listener.ReadFullVersionInformation(Blob)) |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4719 | return true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4720 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4721 | break; |
| 4722 | } |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 4723 | case MODULE_NAME: |
| 4724 | Listener.ReadModuleName(Blob); |
| 4725 | break; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4726 | case MODULE_DIRECTORY: |
| 4727 | ModuleDir = Blob; |
| 4728 | break; |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 4729 | case MODULE_MAP_FILE: { |
| 4730 | unsigned Idx = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4731 | auto Path = ReadString(Record, Idx); |
| 4732 | ResolveImportedPath(Path, ModuleDir); |
| 4733 | Listener.ReadModuleMapFile(Path); |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 4734 | break; |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 4735 | } |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4736 | case INPUT_FILE_OFFSETS: { |
| 4737 | if (!NeedsInputFiles) |
| 4738 | break; |
| 4739 | |
| 4740 | unsigned NumInputFiles = Record[0]; |
| 4741 | unsigned NumUserFiles = Record[1]; |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 4742 | const uint64_t *InputFileOffs = (const uint64_t *)Blob.data(); |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4743 | for (unsigned I = 0; I != NumInputFiles; ++I) { |
| 4744 | // Go find this input file. |
| 4745 | bool isSystemFile = I >= NumUserFiles; |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 4746 | |
| 4747 | if (isSystemFile && !NeedsSystemInputFiles) |
| 4748 | break; // the rest are system input files |
| 4749 | |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4750 | BitstreamCursor &Cursor = InputFilesCursor; |
| 4751 | SavedStreamPosition SavedPosition(Cursor); |
| 4752 | Cursor.JumpToBit(InputFileOffs[I]); |
| 4753 | |
| 4754 | unsigned Code = Cursor.ReadCode(); |
| 4755 | RecordData Record; |
| 4756 | StringRef Blob; |
| 4757 | bool shouldContinue = false; |
| 4758 | switch ((InputFileRecordTypes)Cursor.readRecord(Code, Record, &Blob)) { |
| 4759 | case INPUT_FILE: |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 4760 | bool Overridden = static_cast<bool>(Record[3]); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4761 | std::string Filename = Blob; |
| 4762 | ResolveImportedPath(Filename, ModuleDir); |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 4763 | shouldContinue = Listener.visitInputFile( |
| 4764 | Filename, isSystemFile, Overridden, /*IsExplicitModule*/false); |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4765 | break; |
| 4766 | } |
| 4767 | if (!shouldContinue) |
| 4768 | break; |
| 4769 | } |
| 4770 | break; |
| 4771 | } |
| 4772 | |
Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4773 | case IMPORTS: { |
| 4774 | if (!NeedsImports) |
| 4775 | break; |
| 4776 | |
| 4777 | unsigned Idx = 0, N = Record.size(); |
| 4778 | while (Idx < N) { |
| 4779 | // Read information about the AST file. |
Richard Smith | 79c98cc | 2014-10-27 23:25:15 +0000 | [diff] [blame] | 4780 | Idx += 5; // ImportLoc, Size, ModTime, Signature |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 4781 | SkipString(Record, Idx); // Module name; FIXME: pass to listener? |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4782 | std::string Filename = ReadString(Record, Idx); |
| 4783 | ResolveImportedPath(Filename, ModuleDir); |
| 4784 | Listener.visitImport(Filename); |
Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4785 | } |
| 4786 | break; |
| 4787 | } |
| 4788 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4789 | default: |
| 4790 | // No other validation to perform. |
| 4791 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4792 | } |
| 4793 | } |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4794 | |
| 4795 | // Look for module file extension blocks, if requested. |
| 4796 | if (FindModuleFileExtensions) { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4797 | BitstreamCursor SavedStream = Stream; |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4798 | while (!SkipCursorToBlock(Stream, EXTENSION_BLOCK_ID)) { |
| 4799 | bool DoneWithExtensionBlock = false; |
| 4800 | while (!DoneWithExtensionBlock) { |
| 4801 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4802 | |
| 4803 | switch (Entry.Kind) { |
| 4804 | case llvm::BitstreamEntry::SubBlock: |
| 4805 | if (Stream.SkipBlock()) |
| 4806 | return true; |
| 4807 | |
| 4808 | continue; |
| 4809 | |
| 4810 | case llvm::BitstreamEntry::EndBlock: |
| 4811 | DoneWithExtensionBlock = true; |
| 4812 | continue; |
| 4813 | |
| 4814 | case llvm::BitstreamEntry::Error: |
| 4815 | return true; |
| 4816 | |
| 4817 | case llvm::BitstreamEntry::Record: |
| 4818 | break; |
| 4819 | } |
| 4820 | |
| 4821 | Record.clear(); |
| 4822 | StringRef Blob; |
| 4823 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
| 4824 | switch (RecCode) { |
| 4825 | case EXTENSION_METADATA: { |
| 4826 | ModuleFileExtensionMetadata Metadata; |
| 4827 | if (parseModuleFileExtensionMetadata(Record, Blob, Metadata)) |
| 4828 | return true; |
| 4829 | |
| 4830 | Listener.readModuleFileExtension(Metadata); |
| 4831 | break; |
| 4832 | } |
| 4833 | } |
| 4834 | } |
| 4835 | } |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4836 | Stream = SavedStream; |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4837 | } |
| 4838 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4839 | // Scan for the UNHASHED_CONTROL_BLOCK_ID block. |
| 4840 | if (readUnhashedControlBlockImpl( |
| 4841 | nullptr, Bytes, ARR_ConfigurationMismatch | ARR_OutOfDate, |
| 4842 | /*AllowCompatibleConfigurationMismatch*/ false, &Listener, |
| 4843 | ValidateDiagnosticOptions) != Success) |
| 4844 | return true; |
| 4845 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4846 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4847 | } |
| 4848 | |
Benjamin Kramer | f6021ec | 2017-03-21 21:35:04 +0000 | [diff] [blame] | 4849 | bool ASTReader::isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, |
| 4850 | const PCHContainerReader &PCHContainerRdr, |
| 4851 | const LangOptions &LangOpts, |
| 4852 | const TargetOptions &TargetOpts, |
| 4853 | const PreprocessorOptions &PPOpts, |
| 4854 | StringRef ExistingModuleCachePath) { |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4855 | SimplePCHValidator validator(LangOpts, TargetOpts, PPOpts, |
| 4856 | ExistingModuleCachePath, FileMgr); |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 4857 | return !readASTFileControlBlock(Filename, FileMgr, PCHContainerRdr, |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4858 | /*FindModuleFileExtensions=*/false, |
Manman Ren | 47a4445 | 2016-07-26 17:12:17 +0000 | [diff] [blame] | 4859 | validator, |
| 4860 | /*ValidateDiagnosticOptions=*/true); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4861 | } |
| 4862 | |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4863 | ASTReader::ASTReadResult |
| 4864 | ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4865 | // Enter the submodule block. |
| 4866 | if (F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) { |
| 4867 | Error("malformed submodule block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4868 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4869 | } |
| 4870 | |
| 4871 | ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap(); |
| 4872 | bool First = true; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4873 | Module *CurrentModule = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4874 | RecordData Record; |
| 4875 | while (true) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4876 | llvm::BitstreamEntry Entry = F.Stream.advanceSkippingSubblocks(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4877 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4878 | switch (Entry.Kind) { |
| 4879 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 4880 | case llvm::BitstreamEntry::Error: |
| 4881 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4882 | return Failure; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4883 | case llvm::BitstreamEntry::EndBlock: |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4884 | return Success; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4885 | case llvm::BitstreamEntry::Record: |
| 4886 | // The interesting case. |
| 4887 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4888 | } |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4889 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4890 | // Read a record. |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4891 | StringRef Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4892 | Record.clear(); |
Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4893 | auto Kind = F.Stream.readRecord(Entry.ID, Record, &Blob); |
| 4894 | |
| 4895 | if ((Kind == SUBMODULE_METADATA) != First) { |
| 4896 | Error("submodule metadata record should be at beginning of block"); |
| 4897 | return Failure; |
| 4898 | } |
| 4899 | First = false; |
| 4900 | |
| 4901 | // Submodule information is only valid if we have a current module. |
| 4902 | // FIXME: Should we error on these cases? |
| 4903 | if (!CurrentModule && Kind != SUBMODULE_METADATA && |
| 4904 | Kind != SUBMODULE_DEFINITION) |
| 4905 | continue; |
| 4906 | |
| 4907 | switch (Kind) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4908 | default: // Default behavior: ignore. |
| 4909 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4910 | |
Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4911 | case SUBMODULE_DEFINITION: { |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4912 | if (Record.size() < 8) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4913 | Error("malformed module definition"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4914 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4915 | } |
Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4916 | |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4917 | StringRef Name = Blob; |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 4918 | unsigned Idx = 0; |
| 4919 | SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[Idx++]); |
| 4920 | SubmoduleID Parent = getGlobalSubmoduleID(F, Record[Idx++]); |
Richard Smith | dd8b533 | 2017-09-04 05:37:53 +0000 | [diff] [blame] | 4921 | Module::ModuleKind Kind = (Module::ModuleKind)Record[Idx++]; |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 4922 | bool IsFramework = Record[Idx++]; |
| 4923 | bool IsExplicit = Record[Idx++]; |
| 4924 | bool IsSystem = Record[Idx++]; |
| 4925 | bool IsExternC = Record[Idx++]; |
| 4926 | bool InferSubmodules = Record[Idx++]; |
| 4927 | bool InferExplicitSubmodules = Record[Idx++]; |
| 4928 | bool InferExportWildcard = Record[Idx++]; |
| 4929 | bool ConfigMacrosExhaustive = Record[Idx++]; |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4930 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4931 | Module *ParentModule = nullptr; |
Ben Langmuir | 9d6448b | 2014-08-09 00:57:23 +0000 | [diff] [blame] | 4932 | if (Parent) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4933 | ParentModule = getSubmodule(Parent); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4934 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4935 | // Retrieve this (sub)module from the module map, creating it if |
| 4936 | // necessary. |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 4937 | CurrentModule = |
| 4938 | ModMap.findOrCreateModule(Name, ParentModule, IsFramework, IsExplicit) |
| 4939 | .first; |
Ben Langmuir | 9d6448b | 2014-08-09 00:57:23 +0000 | [diff] [blame] | 4940 | |
| 4941 | // FIXME: set the definition loc for CurrentModule, or call |
| 4942 | // ModMap.setInferredModuleAllowedBy() |
| 4943 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4944 | SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS; |
| 4945 | if (GlobalIndex >= SubmodulesLoaded.size() || |
| 4946 | SubmodulesLoaded[GlobalIndex]) { |
| 4947 | Error("too many submodules"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4948 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4949 | } |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4950 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4951 | if (!ParentModule) { |
| 4952 | if (const FileEntry *CurFile = CurrentModule->getASTFile()) { |
| 4953 | if (CurFile != F.File) { |
| 4954 | if (!Diags.isDiagnosticInFlight()) { |
| 4955 | Diag(diag::err_module_file_conflict) |
| 4956 | << CurrentModule->getTopLevelModuleName() |
| 4957 | << CurFile->getName() |
| 4958 | << F.File->getName(); |
| 4959 | } |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4960 | return Failure; |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4961 | } |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4962 | } |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4963 | |
| 4964 | CurrentModule->setASTFile(F.File); |
Richard Smith | ab75597 | 2017-06-05 18:10:11 +0000 | [diff] [blame] | 4965 | CurrentModule->PresumedModuleMapFile = F.ModuleMapPath; |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4966 | } |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4967 | |
Richard Smith | dd8b533 | 2017-09-04 05:37:53 +0000 | [diff] [blame] | 4968 | CurrentModule->Kind = Kind; |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 4969 | CurrentModule->Signature = F.Signature; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4970 | CurrentModule->IsFromModuleFile = true; |
| 4971 | CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem; |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 4972 | CurrentModule->IsExternC = IsExternC; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4973 | CurrentModule->InferSubmodules = InferSubmodules; |
| 4974 | CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules; |
| 4975 | CurrentModule->InferExportWildcard = InferExportWildcard; |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4976 | CurrentModule->ConfigMacrosExhaustive = ConfigMacrosExhaustive; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4977 | if (DeserializationListener) |
| 4978 | DeserializationListener->ModuleRead(GlobalID, CurrentModule); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4979 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4980 | SubmodulesLoaded[GlobalIndex] = CurrentModule; |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 4981 | |
Richard Smith | 8a3e39a | 2016-03-28 21:31:09 +0000 | [diff] [blame] | 4982 | // Clear out data that will be replaced by what is in the module file. |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 4983 | CurrentModule->LinkLibraries.clear(); |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4984 | CurrentModule->ConfigMacros.clear(); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4985 | CurrentModule->UnresolvedConflicts.clear(); |
| 4986 | CurrentModule->Conflicts.clear(); |
Richard Smith | 8a3e39a | 2016-03-28 21:31:09 +0000 | [diff] [blame] | 4987 | |
| 4988 | // The module is available unless it's missing a requirement; relevant |
| 4989 | // requirements will be (re-)added by SUBMODULE_REQUIRES records. |
| 4990 | // Missing headers that were present when the module was built do not |
| 4991 | // make it unavailable -- if we got this far, this must be an explicitly |
| 4992 | // imported module file. |
| 4993 | CurrentModule->Requirements.clear(); |
| 4994 | CurrentModule->MissingHeaders.clear(); |
| 4995 | CurrentModule->IsMissingRequirement = |
| 4996 | ParentModule && ParentModule->IsMissingRequirement; |
| 4997 | CurrentModule->IsAvailable = !CurrentModule->IsMissingRequirement; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4998 | break; |
| 4999 | } |
Richard Smith | 8a3e39a | 2016-03-28 21:31:09 +0000 | [diff] [blame] | 5000 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5001 | case SUBMODULE_UMBRELLA_HEADER: { |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 5002 | std::string Filename = Blob; |
| 5003 | ResolveImportedPath(F, Filename); |
| 5004 | if (auto *Umbrella = PP.getFileManager().getFile(Filename)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5005 | if (!CurrentModule->getUmbrellaHeader()) |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 5006 | ModMap.setUmbrellaHeader(CurrentModule, Umbrella, Blob); |
| 5007 | else if (CurrentModule->getUmbrellaHeader().Entry != Umbrella) { |
Bruno Cardoso Lopes | 573b13f | 2017-03-22 00:11:21 +0000 | [diff] [blame] | 5008 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 5009 | Error("mismatched umbrella headers in submodule"); |
| 5010 | return OutOfDate; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5011 | } |
| 5012 | } |
| 5013 | break; |
| 5014 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5015 | |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 5016 | case SUBMODULE_HEADER: |
| 5017 | case SUBMODULE_EXCLUDED_HEADER: |
| 5018 | case SUBMODULE_PRIVATE_HEADER: |
| 5019 | // We lazily associate headers with their modules via the HeaderInfo table. |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 5020 | // FIXME: Re-evaluate this section; maybe only store InputFile IDs instead |
| 5021 | // of complete filenames or remove it entirely. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 5022 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5023 | |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 5024 | case SUBMODULE_TEXTUAL_HEADER: |
| 5025 | case SUBMODULE_PRIVATE_TEXTUAL_HEADER: |
| 5026 | // FIXME: Textual headers are not marked in the HeaderInfo table. Load |
| 5027 | // them here. |
| 5028 | break; |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 5029 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5030 | case SUBMODULE_TOPHEADER: { |
Argyrios Kyrtzidis | 3c5305c | 2013-03-13 21:13:43 +0000 | [diff] [blame] | 5031 | CurrentModule->addTopHeaderFilename(Blob); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5032 | break; |
| 5033 | } |
| 5034 | |
| 5035 | case SUBMODULE_UMBRELLA_DIR: { |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 5036 | std::string Dirname = Blob; |
| 5037 | ResolveImportedPath(F, Dirname); |
| 5038 | if (auto *Umbrella = PP.getFileManager().getDirectory(Dirname)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5039 | if (!CurrentModule->getUmbrellaDir()) |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 5040 | ModMap.setUmbrellaDir(CurrentModule, Umbrella, Blob); |
| 5041 | else if (CurrentModule->getUmbrellaDir().Entry != Umbrella) { |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 5042 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 5043 | Error("mismatched umbrella directories in submodule"); |
| 5044 | return OutOfDate; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5045 | } |
| 5046 | } |
| 5047 | break; |
| 5048 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5049 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5050 | case SUBMODULE_METADATA: { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5051 | F.BaseSubmoduleID = getTotalNumSubmodules(); |
| 5052 | F.LocalNumSubmodules = Record[0]; |
| 5053 | unsigned LocalBaseSubmoduleID = Record[1]; |
| 5054 | if (F.LocalNumSubmodules > 0) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5055 | // Introduce the global -> local mapping for submodules within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5056 | // module. |
| 5057 | GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5058 | |
| 5059 | // Introduce the local -> global mapping for submodules within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5060 | // module. |
| 5061 | F.SubmoduleRemap.insertOrReplace( |
| 5062 | std::make_pair(LocalBaseSubmoduleID, |
| 5063 | F.BaseSubmoduleID - LocalBaseSubmoduleID)); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 5064 | |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 5065 | SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules); |
| 5066 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5067 | break; |
| 5068 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5069 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5070 | case SUBMODULE_IMPORTS: { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5071 | for (unsigned Idx = 0; Idx != Record.size(); ++Idx) { |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5072 | UnresolvedModuleRef Unresolved; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5073 | Unresolved.File = &F; |
| 5074 | Unresolved.Mod = CurrentModule; |
| 5075 | Unresolved.ID = Record[Idx]; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5076 | Unresolved.Kind = UnresolvedModuleRef::Import; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5077 | Unresolved.IsWildcard = false; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5078 | UnresolvedModuleRefs.push_back(Unresolved); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5079 | } |
| 5080 | break; |
| 5081 | } |
| 5082 | |
| 5083 | case SUBMODULE_EXPORTS: { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5084 | for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) { |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5085 | UnresolvedModuleRef Unresolved; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5086 | Unresolved.File = &F; |
| 5087 | Unresolved.Mod = CurrentModule; |
| 5088 | Unresolved.ID = Record[Idx]; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5089 | Unresolved.Kind = UnresolvedModuleRef::Export; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5090 | Unresolved.IsWildcard = Record[Idx + 1]; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5091 | UnresolvedModuleRefs.push_back(Unresolved); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5092 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5093 | |
| 5094 | // Once we've loaded the set of exports, there's no reason to keep |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5095 | // the parsed, unresolved exports around. |
| 5096 | CurrentModule->UnresolvedExports.clear(); |
| 5097 | break; |
| 5098 | } |
| 5099 | case SUBMODULE_REQUIRES: { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5100 | CurrentModule->addRequirement(Blob, Record[0], PP.getLangOpts(), |
| 5101 | PP.getTargetInfo()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5102 | break; |
| 5103 | } |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5104 | |
| 5105 | case SUBMODULE_LINK_LIBRARY: |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5106 | CurrentModule->LinkLibraries.push_back( |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5107 | Module::LinkLibrary(Blob, Record[0])); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5108 | break; |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 5109 | |
| 5110 | case SUBMODULE_CONFIG_MACRO: |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 5111 | CurrentModule->ConfigMacros.push_back(Blob.str()); |
| 5112 | break; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5113 | |
| 5114 | case SUBMODULE_CONFLICT: { |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5115 | UnresolvedModuleRef Unresolved; |
| 5116 | Unresolved.File = &F; |
| 5117 | Unresolved.Mod = CurrentModule; |
| 5118 | Unresolved.ID = Record[0]; |
| 5119 | Unresolved.Kind = UnresolvedModuleRef::Conflict; |
| 5120 | Unresolved.IsWildcard = false; |
| 5121 | Unresolved.String = Blob; |
| 5122 | UnresolvedModuleRefs.push_back(Unresolved); |
| 5123 | break; |
| 5124 | } |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 5125 | |
Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame^] | 5126 | case SUBMODULE_INITIALIZERS: { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5127 | if (!ContextObj) |
| 5128 | break; |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 5129 | SmallVector<uint32_t, 16> Inits; |
| 5130 | for (auto &ID : Record) |
| 5131 | Inits.push_back(getGlobalDeclID(F, ID)); |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5132 | ContextObj->addLazyModuleInitializers(CurrentModule, Inits); |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 5133 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5134 | } |
Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame^] | 5135 | |
| 5136 | case SUBMODULE_EXPORT_AS: |
| 5137 | CurrentModule->ExportAsModule = Blob.str(); |
| 5138 | break; |
| 5139 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5140 | } |
| 5141 | } |
| 5142 | |
| 5143 | /// \brief Parse the record that corresponds to a LangOptions data |
| 5144 | /// structure. |
| 5145 | /// |
| 5146 | /// This routine parses the language options from the AST file and then gives |
| 5147 | /// them to the AST listener if one is set. |
| 5148 | /// |
| 5149 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
| 5150 | bool ASTReader::ParseLanguageOptions(const RecordData &Record, |
| 5151 | bool Complain, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 5152 | ASTReaderListener &Listener, |
| 5153 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5154 | LangOptions LangOpts; |
| 5155 | unsigned Idx = 0; |
| 5156 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 5157 | LangOpts.Name = Record[Idx++]; |
| 5158 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 5159 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 5160 | #include "clang/Basic/LangOptions.def" |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 5161 | #define SANITIZER(NAME, ID) \ |
| 5162 | LangOpts.Sanitize.set(SanitizerKind::ID, Record[Idx++]); |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 5163 | #include "clang/Basic/Sanitizers.def" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5164 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 5165 | for (unsigned N = Record[Idx++]; N; --N) |
| 5166 | LangOpts.ModuleFeatures.push_back(ReadString(Record, Idx)); |
| 5167 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5168 | ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++]; |
| 5169 | VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx); |
| 5170 | LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 5171 | |
Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 5172 | LangOpts.CurrentModule = ReadString(Record, Idx); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 5173 | |
| 5174 | // Comment options. |
| 5175 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5176 | LangOpts.CommentOpts.BlockCommandNames.push_back( |
| 5177 | ReadString(Record, Idx)); |
| 5178 | } |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 5179 | LangOpts.CommentOpts.ParseAllComments = Record[Idx++]; |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 5180 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 5181 | // OpenMP offloading options. |
| 5182 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5183 | LangOpts.OMPTargetTriples.push_back(llvm::Triple(ReadString(Record, Idx))); |
| 5184 | } |
| 5185 | |
| 5186 | LangOpts.OMPHostIRFile = ReadString(Record, Idx); |
| 5187 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 5188 | return Listener.ReadLanguageOptions(LangOpts, Complain, |
| 5189 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5190 | } |
| 5191 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 5192 | bool ASTReader::ParseTargetOptions(const RecordData &Record, bool Complain, |
| 5193 | ASTReaderListener &Listener, |
| 5194 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5195 | unsigned Idx = 0; |
| 5196 | TargetOptions TargetOpts; |
| 5197 | TargetOpts.Triple = ReadString(Record, Idx); |
| 5198 | TargetOpts.CPU = ReadString(Record, Idx); |
| 5199 | TargetOpts.ABI = ReadString(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5200 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5201 | TargetOpts.FeaturesAsWritten.push_back(ReadString(Record, Idx)); |
| 5202 | } |
| 5203 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5204 | TargetOpts.Features.push_back(ReadString(Record, Idx)); |
| 5205 | } |
| 5206 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 5207 | return Listener.ReadTargetOptions(TargetOpts, Complain, |
| 5208 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5209 | } |
| 5210 | |
| 5211 | bool ASTReader::ParseDiagnosticOptions(const RecordData &Record, bool Complain, |
| 5212 | ASTReaderListener &Listener) { |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5213 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5214 | unsigned Idx = 0; |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5215 | #define DIAGOPT(Name, Bits, Default) DiagOpts->Name = Record[Idx++]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5216 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5217 | DiagOpts->set##Name(static_cast<Type>(Record[Idx++])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5218 | #include "clang/Basic/DiagnosticOptions.def" |
| 5219 | |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 5220 | for (unsigned N = Record[Idx++]; N; --N) |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5221 | DiagOpts->Warnings.push_back(ReadString(Record, Idx)); |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 5222 | for (unsigned N = Record[Idx++]; N; --N) |
| 5223 | DiagOpts->Remarks.push_back(ReadString(Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5224 | |
| 5225 | return Listener.ReadDiagnosticOptions(DiagOpts, Complain); |
| 5226 | } |
| 5227 | |
| 5228 | bool ASTReader::ParseFileSystemOptions(const RecordData &Record, bool Complain, |
| 5229 | ASTReaderListener &Listener) { |
| 5230 | FileSystemOptions FSOpts; |
| 5231 | unsigned Idx = 0; |
| 5232 | FSOpts.WorkingDir = ReadString(Record, Idx); |
| 5233 | return Listener.ReadFileSystemOptions(FSOpts, Complain); |
| 5234 | } |
| 5235 | |
| 5236 | bool ASTReader::ParseHeaderSearchOptions(const RecordData &Record, |
| 5237 | bool Complain, |
| 5238 | ASTReaderListener &Listener) { |
| 5239 | HeaderSearchOptions HSOpts; |
| 5240 | unsigned Idx = 0; |
| 5241 | HSOpts.Sysroot = ReadString(Record, Idx); |
| 5242 | |
| 5243 | // Include entries. |
| 5244 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5245 | std::string Path = ReadString(Record, Idx); |
| 5246 | frontend::IncludeDirGroup Group |
| 5247 | = static_cast<frontend::IncludeDirGroup>(Record[Idx++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5248 | bool IsFramework = Record[Idx++]; |
| 5249 | bool IgnoreSysRoot = Record[Idx++]; |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 5250 | HSOpts.UserEntries.emplace_back(std::move(Path), Group, IsFramework, |
| 5251 | IgnoreSysRoot); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5252 | } |
| 5253 | |
| 5254 | // System header prefixes. |
| 5255 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5256 | std::string Prefix = ReadString(Record, Idx); |
| 5257 | bool IsSystemHeader = Record[Idx++]; |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 5258 | HSOpts.SystemHeaderPrefixes.emplace_back(std::move(Prefix), IsSystemHeader); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5259 | } |
| 5260 | |
| 5261 | HSOpts.ResourceDir = ReadString(Record, Idx); |
| 5262 | HSOpts.ModuleCachePath = ReadString(Record, Idx); |
Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 5263 | HSOpts.ModuleUserBuildPath = ReadString(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5264 | HSOpts.DisableModuleHash = Record[Idx++]; |
Richard Smith | 1893475 | 2017-06-06 00:32:01 +0000 | [diff] [blame] | 5265 | HSOpts.ImplicitModuleMaps = Record[Idx++]; |
| 5266 | HSOpts.ModuleMapFileHomeIsCwd = Record[Idx++]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5267 | HSOpts.UseBuiltinIncludes = Record[Idx++]; |
| 5268 | HSOpts.UseStandardSystemIncludes = Record[Idx++]; |
| 5269 | HSOpts.UseStandardCXXIncludes = Record[Idx++]; |
| 5270 | HSOpts.UseLibcxx = Record[Idx++]; |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 5271 | std::string SpecificModuleCachePath = ReadString(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5272 | |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 5273 | return Listener.ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 5274 | Complain); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5275 | } |
| 5276 | |
| 5277 | bool ASTReader::ParsePreprocessorOptions(const RecordData &Record, |
| 5278 | bool Complain, |
| 5279 | ASTReaderListener &Listener, |
| 5280 | std::string &SuggestedPredefines) { |
| 5281 | PreprocessorOptions PPOpts; |
| 5282 | unsigned Idx = 0; |
| 5283 | |
| 5284 | // Macro definitions/undefs |
| 5285 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5286 | std::string Macro = ReadString(Record, Idx); |
| 5287 | bool IsUndef = Record[Idx++]; |
| 5288 | PPOpts.Macros.push_back(std::make_pair(Macro, IsUndef)); |
| 5289 | } |
| 5290 | |
| 5291 | // Includes |
| 5292 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5293 | PPOpts.Includes.push_back(ReadString(Record, Idx)); |
| 5294 | } |
| 5295 | |
| 5296 | // Macro Includes |
| 5297 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5298 | PPOpts.MacroIncludes.push_back(ReadString(Record, Idx)); |
| 5299 | } |
| 5300 | |
| 5301 | PPOpts.UsePredefines = Record[Idx++]; |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 5302 | PPOpts.DetailedRecord = Record[Idx++]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5303 | PPOpts.ImplicitPCHInclude = ReadString(Record, Idx); |
| 5304 | PPOpts.ImplicitPTHInclude = ReadString(Record, Idx); |
| 5305 | PPOpts.ObjCXXARCStandardLibrary = |
| 5306 | static_cast<ObjCXXARCStandardLibraryKind>(Record[Idx++]); |
| 5307 | SuggestedPredefines.clear(); |
| 5308 | return Listener.ReadPreprocessorOptions(PPOpts, Complain, |
| 5309 | SuggestedPredefines); |
| 5310 | } |
| 5311 | |
| 5312 | std::pair<ModuleFile *, unsigned> |
| 5313 | ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { |
| 5314 | GlobalPreprocessedEntityMapType::iterator |
| 5315 | I = GlobalPreprocessedEntityMap.find(GlobalIndex); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5316 | assert(I != GlobalPreprocessedEntityMap.end() && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5317 | "Corrupted global preprocessed entity map"); |
| 5318 | ModuleFile *M = I->second; |
| 5319 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; |
| 5320 | return std::make_pair(M, LocalIndex); |
| 5321 | } |
| 5322 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5323 | llvm::iterator_range<PreprocessingRecord::iterator> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5324 | ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const { |
| 5325 | if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord()) |
| 5326 | return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID, |
| 5327 | Mod.NumPreprocessedEntities); |
| 5328 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5329 | return llvm::make_range(PreprocessingRecord::iterator(), |
| 5330 | PreprocessingRecord::iterator()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5331 | } |
| 5332 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5333 | llvm::iterator_range<ASTReader::ModuleDeclIterator> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5334 | ASTReader::getModuleFileLevelDecls(ModuleFile &Mod) { |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5335 | return llvm::make_range( |
| 5336 | ModuleDeclIterator(this, &Mod, Mod.FileSortedDecls), |
| 5337 | ModuleDeclIterator(this, &Mod, |
| 5338 | Mod.FileSortedDecls + Mod.NumFileSortedDecls)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5339 | } |
| 5340 | |
| 5341 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { |
| 5342 | PreprocessedEntityID PPID = Index+1; |
| 5343 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 5344 | ModuleFile &M = *PPInfo.first; |
| 5345 | unsigned LocalIndex = PPInfo.second; |
| 5346 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 5347 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5348 | if (!PP.getPreprocessingRecord()) { |
| 5349 | Error("no preprocessing record"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5350 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5351 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5352 | |
| 5353 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5354 | M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset); |
| 5355 | |
| 5356 | llvm::BitstreamEntry Entry = |
| 5357 | M.PreprocessorDetailCursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd); |
| 5358 | if (Entry.Kind != llvm::BitstreamEntry::Record) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5359 | return nullptr; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5360 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5361 | // Read the record. |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 5362 | SourceRange Range(TranslateSourceLocation(M, PPOffs.getBegin()), |
| 5363 | TranslateSourceLocation(M, PPOffs.getEnd())); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5364 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5365 | StringRef Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5366 | RecordData Record; |
| 5367 | PreprocessorDetailRecordTypes RecType = |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5368 | (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.readRecord( |
| 5369 | Entry.ID, Record, &Blob); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5370 | switch (RecType) { |
| 5371 | case PPD_MACRO_EXPANSION: { |
| 5372 | bool isBuiltin = Record[0]; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5373 | IdentifierInfo *Name = nullptr; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5374 | MacroDefinitionRecord *Def = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5375 | if (isBuiltin) |
| 5376 | Name = getLocalIdentifier(M, Record[1]); |
| 5377 | else { |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5378 | PreprocessedEntityID GlobalID = |
| 5379 | getGlobalPreprocessedEntityID(M, Record[1]); |
| 5380 | Def = cast<MacroDefinitionRecord>( |
| 5381 | PPRec.getLoadedPreprocessedEntity(GlobalID - 1)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | MacroExpansion *ME; |
| 5385 | if (isBuiltin) |
| 5386 | ME = new (PPRec) MacroExpansion(Name, Range); |
| 5387 | else |
| 5388 | ME = new (PPRec) MacroExpansion(Def, Range); |
| 5389 | |
| 5390 | return ME; |
| 5391 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5392 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5393 | case PPD_MACRO_DEFINITION: { |
| 5394 | // Decode the identifier info and then check again; if the macro is |
| 5395 | // still defined and associated with the identifier, |
| 5396 | IdentifierInfo *II = getLocalIdentifier(M, Record[0]); |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5397 | MacroDefinitionRecord *MD = new (PPRec) MacroDefinitionRecord(II, Range); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5398 | |
| 5399 | if (DeserializationListener) |
| 5400 | DeserializationListener->MacroDefinitionRead(PPID, MD); |
| 5401 | |
| 5402 | return MD; |
| 5403 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5404 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5405 | case PPD_INCLUSION_DIRECTIVE: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5406 | const char *FullFileNameStart = Blob.data() + Record[0]; |
| 5407 | StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5408 | const FileEntry *File = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5409 | if (!FullFileName.empty()) |
| 5410 | File = PP.getFileManager().getFile(FullFileName); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5411 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5412 | // FIXME: Stable encoding |
| 5413 | InclusionDirective::InclusionKind Kind |
| 5414 | = static_cast<InclusionDirective::InclusionKind>(Record[2]); |
| 5415 | InclusionDirective *ID |
| 5416 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5417 | StringRef(Blob.data(), Record[0]), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5418 | Record[1], Record[3], |
| 5419 | File, |
| 5420 | Range); |
| 5421 | return ID; |
| 5422 | } |
| 5423 | } |
| 5424 | |
| 5425 | llvm_unreachable("Invalid PreprocessorDetailRecordTypes"); |
| 5426 | } |
| 5427 | |
| 5428 | /// \brief \arg SLocMapI points at a chunk of a module that contains no |
| 5429 | /// preprocessed entities or the entities it contains are not the ones we are |
| 5430 | /// looking for. Find the next module that contains entities and return the ID |
| 5431 | /// of the first entry. |
| 5432 | PreprocessedEntityID ASTReader::findNextPreprocessedEntity( |
| 5433 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const { |
| 5434 | ++SLocMapI; |
| 5435 | for (GlobalSLocOffsetMapType::const_iterator |
| 5436 | EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) { |
| 5437 | ModuleFile &M = *SLocMapI->second; |
| 5438 | if (M.NumPreprocessedEntities) |
| 5439 | return M.BasePreprocessedEntityID; |
| 5440 | } |
| 5441 | |
| 5442 | return getTotalNumPreprocessedEntities(); |
| 5443 | } |
| 5444 | |
| 5445 | namespace { |
| 5446 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5447 | struct PPEntityComp { |
| 5448 | const ASTReader &Reader; |
| 5449 | ModuleFile &M; |
| 5450 | |
| 5451 | PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) { } |
| 5452 | |
| 5453 | bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const { |
| 5454 | SourceLocation LHS = getLoc(L); |
| 5455 | SourceLocation RHS = getLoc(R); |
| 5456 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5457 | } |
| 5458 | |
| 5459 | bool operator()(const PPEntityOffset &L, SourceLocation RHS) const { |
| 5460 | SourceLocation LHS = getLoc(L); |
| 5461 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5462 | } |
| 5463 | |
| 5464 | bool operator()(SourceLocation LHS, const PPEntityOffset &R) const { |
| 5465 | SourceLocation RHS = getLoc(R); |
| 5466 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5467 | } |
| 5468 | |
| 5469 | SourceLocation getLoc(const PPEntityOffset &PPE) const { |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5470 | return Reader.TranslateSourceLocation(M, PPE.getBegin()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5471 | } |
| 5472 | }; |
| 5473 | |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5474 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5475 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5476 | PreprocessedEntityID ASTReader::findPreprocessedEntity(SourceLocation Loc, |
| 5477 | bool EndsAfter) const { |
| 5478 | if (SourceMgr.isLocalSourceLocation(Loc)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5479 | return getTotalNumPreprocessedEntities(); |
| 5480 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5481 | GlobalSLocOffsetMapType::const_iterator SLocMapI = GlobalSLocOffsetMap.find( |
| 5482 | SourceManager::MaxLoadedOffset - Loc.getOffset() - 1); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5483 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 5484 | "Corrupted global sloc offset map"); |
| 5485 | |
| 5486 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 5487 | return findNextPreprocessedEntity(SLocMapI); |
| 5488 | |
| 5489 | ModuleFile &M = *SLocMapI->second; |
| 5490 | typedef const PPEntityOffset *pp_iterator; |
| 5491 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 5492 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
| 5493 | |
| 5494 | size_t Count = M.NumPreprocessedEntities; |
| 5495 | size_t Half; |
| 5496 | pp_iterator First = pp_begin; |
| 5497 | pp_iterator PPI; |
| 5498 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5499 | if (EndsAfter) { |
| 5500 | PPI = std::upper_bound(pp_begin, pp_end, Loc, |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5501 | PPEntityComp(*this, M)); |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5502 | } else { |
| 5503 | // Do a binary search manually instead of using std::lower_bound because |
| 5504 | // The end locations of entities may be unordered (when a macro expansion |
| 5505 | // is inside another macro argument), but for this case it is not important |
| 5506 | // whether we get the first macro expansion or its containing macro. |
| 5507 | while (Count > 0) { |
| 5508 | Half = Count / 2; |
| 5509 | PPI = First; |
| 5510 | std::advance(PPI, Half); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5511 | if (SourceMgr.isBeforeInTranslationUnit( |
| 5512 | TranslateSourceLocation(M, PPI->getEnd()), Loc)) { |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5513 | First = PPI; |
| 5514 | ++First; |
| 5515 | Count = Count - Half - 1; |
| 5516 | } else |
| 5517 | Count = Half; |
| 5518 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5519 | } |
| 5520 | |
| 5521 | if (PPI == pp_end) |
| 5522 | return findNextPreprocessedEntity(SLocMapI); |
| 5523 | |
| 5524 | return M.BasePreprocessedEntityID + (PPI - pp_begin); |
| 5525 | } |
| 5526 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5527 | /// \brief Returns a pair of [Begin, End) indices of preallocated |
| 5528 | /// preprocessed entities that \arg Range encompasses. |
| 5529 | std::pair<unsigned, unsigned> |
| 5530 | ASTReader::findPreprocessedEntitiesInRange(SourceRange Range) { |
| 5531 | if (Range.isInvalid()) |
| 5532 | return std::make_pair(0,0); |
| 5533 | assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); |
| 5534 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5535 | PreprocessedEntityID BeginID = |
| 5536 | findPreprocessedEntity(Range.getBegin(), false); |
| 5537 | PreprocessedEntityID EndID = findPreprocessedEntity(Range.getEnd(), true); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5538 | return std::make_pair(BeginID, EndID); |
| 5539 | } |
| 5540 | |
| 5541 | /// \brief Optionally returns true or false if the preallocated preprocessed |
| 5542 | /// entity with index \arg Index came from file \arg FID. |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5543 | Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5544 | FileID FID) { |
| 5545 | if (FID.isInvalid()) |
| 5546 | return false; |
| 5547 | |
| 5548 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 5549 | ModuleFile &M = *PPInfo.first; |
| 5550 | unsigned LocalIndex = PPInfo.second; |
| 5551 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5552 | |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 5553 | SourceLocation Loc = TranslateSourceLocation(M, PPOffs.getBegin()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5554 | if (Loc.isInvalid()) |
| 5555 | return false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5556 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5557 | if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) |
| 5558 | return true; |
| 5559 | else |
| 5560 | return false; |
| 5561 | } |
| 5562 | |
| 5563 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5564 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5565 | /// \brief Visitor used to search for information about a header file. |
| 5566 | class HeaderFileInfoVisitor { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5567 | const FileEntry *FE; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5568 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5569 | Optional<HeaderFileInfo> HFI; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5570 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5571 | public: |
Argyrios Kyrtzidis | 61a3896 | 2013-03-06 18:12:44 +0000 | [diff] [blame] | 5572 | explicit HeaderFileInfoVisitor(const FileEntry *FE) |
| 5573 | : FE(FE) { } |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 5574 | |
| 5575 | bool operator()(ModuleFile &M) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5576 | HeaderFileInfoLookupTable *Table |
| 5577 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 5578 | if (!Table) |
| 5579 | return false; |
| 5580 | |
| 5581 | // Look in the on-disk hash table for an entry for this file name. |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 5582 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5583 | if (Pos == Table->end()) |
| 5584 | return false; |
| 5585 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 5586 | HFI = *Pos; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5587 | return true; |
| 5588 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5589 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5590 | Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5591 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5592 | |
| 5593 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5594 | |
| 5595 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Argyrios Kyrtzidis | 61a3896 | 2013-03-06 18:12:44 +0000 | [diff] [blame] | 5596 | HeaderFileInfoVisitor Visitor(FE); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 5597 | ModuleMgr.visit(Visitor); |
Argyrios Kyrtzidis | 1054bbf | 2013-05-08 23:46:55 +0000 | [diff] [blame] | 5598 | if (Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5599 | return *HFI; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5600 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5601 | return HeaderFileInfo(); |
| 5602 | } |
| 5603 | |
| 5604 | void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5605 | using DiagState = DiagnosticsEngine::DiagState; |
| 5606 | SmallVector<DiagState *, 32> DiagStates; |
| 5607 | |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 5608 | for (ModuleFile &F : ModuleMgr) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5609 | unsigned Idx = 0; |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5610 | auto &Record = F.PragmaDiagMappings; |
| 5611 | if (Record.empty()) |
| 5612 | continue; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5613 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5614 | DiagStates.clear(); |
| 5615 | |
| 5616 | auto ReadDiagState = |
| 5617 | [&](const DiagState &BasedOn, SourceLocation Loc, |
| 5618 | bool IncludeNonPragmaStates) -> DiagnosticsEngine::DiagState * { |
| 5619 | unsigned BackrefID = Record[Idx++]; |
| 5620 | if (BackrefID != 0) |
| 5621 | return DiagStates[BackrefID - 1]; |
| 5622 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5623 | // A new DiagState was created here. |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5624 | Diag.DiagStates.push_back(BasedOn); |
| 5625 | DiagState *NewState = &Diag.DiagStates.back(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5626 | DiagStates.push_back(NewState); |
Duncan P. N. Exon Smith | 3cb183b | 2017-03-14 19:31:27 +0000 | [diff] [blame] | 5627 | unsigned Size = Record[Idx++]; |
| 5628 | assert(Idx + Size * 2 <= Record.size() && |
| 5629 | "Invalid data, not enough diag/map pairs"); |
| 5630 | while (Size--) { |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5631 | unsigned DiagID = Record[Idx++]; |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5632 | DiagnosticMapping NewMapping = |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5633 | DiagnosticMapping::deserialize(Record[Idx++]); |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5634 | if (!NewMapping.isPragma() && !IncludeNonPragmaStates) |
| 5635 | continue; |
| 5636 | |
| 5637 | DiagnosticMapping &Mapping = NewState->getOrAddMapping(DiagID); |
| 5638 | |
| 5639 | // If this mapping was specified as a warning but the severity was |
| 5640 | // upgraded due to diagnostic settings, simulate the current diagnostic |
| 5641 | // settings (and use a warning). |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5642 | if (NewMapping.wasUpgradedFromWarning() && !Mapping.isErrorOrFatal()) { |
| 5643 | NewMapping.setSeverity(diag::Severity::Warning); |
| 5644 | NewMapping.setUpgradedFromWarning(false); |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5645 | } |
| 5646 | |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5647 | Mapping = NewMapping; |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5648 | } |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5649 | return NewState; |
| 5650 | }; |
| 5651 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5652 | // Read the first state. |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5653 | DiagState *FirstState; |
| 5654 | if (F.Kind == MK_ImplicitModule) { |
| 5655 | // Implicitly-built modules are reused with different diagnostic |
| 5656 | // settings. Use the initial diagnostic state from Diag to simulate this |
| 5657 | // compilation's diagnostic settings. |
| 5658 | FirstState = Diag.DiagStatesByLoc.FirstDiagState; |
| 5659 | DiagStates.push_back(FirstState); |
| 5660 | |
| 5661 | // Skip the initial diagnostic state from the serialized module. |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5662 | assert(Record[1] == 0 && |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5663 | "Invalid data, unexpected backref in initial state"); |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5664 | Idx = 3 + Record[2] * 2; |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5665 | assert(Idx < Record.size() && |
| 5666 | "Invalid data, not enough state change pairs in initial state"); |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5667 | } else if (F.isModule()) { |
| 5668 | // For an explicit module, preserve the flags from the module build |
| 5669 | // command line (-w, -Weverything, -Werror, ...) along with any explicit |
| 5670 | // -Wblah flags. |
| 5671 | unsigned Flags = Record[Idx++]; |
| 5672 | DiagState Initial; |
| 5673 | Initial.SuppressSystemWarnings = Flags & 1; Flags >>= 1; |
| 5674 | Initial.ErrorsAsFatal = Flags & 1; Flags >>= 1; |
| 5675 | Initial.WarningsAsErrors = Flags & 1; Flags >>= 1; |
| 5676 | Initial.EnableAllWarnings = Flags & 1; Flags >>= 1; |
| 5677 | Initial.IgnoreAllWarnings = Flags & 1; Flags >>= 1; |
| 5678 | Initial.ExtBehavior = (diag::Severity)Flags; |
| 5679 | FirstState = ReadDiagState(Initial, SourceLocation(), true); |
Richard Smith | ea74148 | 2017-05-01 22:10:47 +0000 | [diff] [blame] | 5680 | |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5681 | // Set up the root buffer of the module to start with the initial |
| 5682 | // diagnostic state of the module itself, to cover files that contain no |
| 5683 | // explicit transitions (for which we did not serialize anything). |
| 5684 | Diag.DiagStatesByLoc.Files[F.OriginalSourceFileID] |
| 5685 | .StateTransitions.push_back({FirstState, 0}); |
| 5686 | } else { |
| 5687 | // For prefix ASTs, start with whatever the user configured on the |
| 5688 | // command line. |
| 5689 | Idx++; // Skip flags. |
| 5690 | FirstState = ReadDiagState(*Diag.DiagStatesByLoc.CurDiagState, |
| 5691 | SourceLocation(), false); |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5692 | } |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5693 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5694 | // Read the state transitions. |
| 5695 | unsigned NumLocations = Record[Idx++]; |
| 5696 | while (NumLocations--) { |
| 5697 | assert(Idx < Record.size() && |
| 5698 | "Invalid data, missing pragma diagnostic states"); |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5699 | SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]); |
| 5700 | auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc); |
| 5701 | assert(IDAndOffset.second == 0 && "not a start location for a FileID"); |
| 5702 | unsigned Transitions = Record[Idx++]; |
| 5703 | |
| 5704 | // Note that we don't need to set up Parent/ParentOffset here, because |
| 5705 | // we won't be changing the diagnostic state within imported FileIDs |
| 5706 | // (other than perhaps appending to the main source file, which has no |
| 5707 | // parent). |
| 5708 | auto &F = Diag.DiagStatesByLoc.Files[IDAndOffset.first]; |
| 5709 | F.StateTransitions.reserve(F.StateTransitions.size() + Transitions); |
| 5710 | for (unsigned I = 0; I != Transitions; ++I) { |
| 5711 | unsigned Offset = Record[Idx++]; |
| 5712 | auto *State = |
| 5713 | ReadDiagState(*FirstState, Loc.getLocWithOffset(Offset), false); |
| 5714 | F.StateTransitions.push_back({State, Offset}); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5715 | } |
| 5716 | } |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5717 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5718 | // Read the final state. |
| 5719 | assert(Idx < Record.size() && |
| 5720 | "Invalid data, missing final pragma diagnostic state"); |
| 5721 | SourceLocation CurStateLoc = |
| 5722 | ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
| 5723 | auto *CurState = ReadDiagState(*FirstState, CurStateLoc, false); |
| 5724 | |
| 5725 | if (!F.isModule()) { |
| 5726 | Diag.DiagStatesByLoc.CurDiagState = CurState; |
| 5727 | Diag.DiagStatesByLoc.CurDiagStateLoc = CurStateLoc; |
| 5728 | |
| 5729 | // Preserve the property that the imaginary root file describes the |
| 5730 | // current state. |
| 5731 | auto &T = Diag.DiagStatesByLoc.Files[FileID()].StateTransitions; |
| 5732 | if (T.empty()) |
| 5733 | T.push_back({CurState, 0}); |
| 5734 | else |
| 5735 | T[0].State = CurState; |
| 5736 | } |
| 5737 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5738 | // Don't try to read these mappings again. |
| 5739 | Record.clear(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5740 | } |
| 5741 | } |
| 5742 | |
| 5743 | /// \brief Get the correct cursor and offset for loading a type. |
| 5744 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
| 5745 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
| 5746 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
| 5747 | ModuleFile *M = I->second; |
| 5748 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
| 5749 | } |
| 5750 | |
| 5751 | /// \brief Read and return the type with the given index.. |
| 5752 | /// |
| 5753 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 5754 | /// routine actually reads the record corresponding to the type at the given |
| 5755 | /// location. It is a helper routine for GetType, which deals with reading type |
| 5756 | /// IDs. |
| 5757 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5758 | assert(ContextObj && "reading type with no AST context"); |
| 5759 | ASTContext &Context = *ContextObj; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5760 | RecordLocation Loc = TypeCursorForIndex(Index); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5761 | BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5762 | |
| 5763 | // Keep track of where we are in the stream, then jump back there |
| 5764 | // after reading this type. |
| 5765 | SavedStreamPosition SavedPosition(DeclsCursor); |
| 5766 | |
| 5767 | ReadingKindTracker ReadingKind(Read_Type, *this); |
| 5768 | |
| 5769 | // Note that we are loading a type record. |
| 5770 | Deserializing AType(this); |
| 5771 | |
| 5772 | unsigned Idx = 0; |
| 5773 | DeclsCursor.JumpToBit(Loc.Offset); |
| 5774 | RecordData Record; |
| 5775 | unsigned Code = DeclsCursor.ReadCode(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5776 | switch ((TypeCode)DeclsCursor.readRecord(Code, Record)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5777 | case TYPE_EXT_QUAL: { |
| 5778 | if (Record.size() != 2) { |
| 5779 | Error("Incorrect encoding of extended qualifier type"); |
| 5780 | return QualType(); |
| 5781 | } |
| 5782 | QualType Base = readType(*Loc.F, Record, Idx); |
| 5783 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
| 5784 | return Context.getQualifiedType(Base, Quals); |
| 5785 | } |
| 5786 | |
| 5787 | case TYPE_COMPLEX: { |
| 5788 | if (Record.size() != 1) { |
| 5789 | Error("Incorrect encoding of complex type"); |
| 5790 | return QualType(); |
| 5791 | } |
| 5792 | QualType ElemType = readType(*Loc.F, Record, Idx); |
| 5793 | return Context.getComplexType(ElemType); |
| 5794 | } |
| 5795 | |
| 5796 | case TYPE_POINTER: { |
| 5797 | if (Record.size() != 1) { |
| 5798 | Error("Incorrect encoding of pointer type"); |
| 5799 | return QualType(); |
| 5800 | } |
| 5801 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5802 | return Context.getPointerType(PointeeType); |
| 5803 | } |
| 5804 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 5805 | case TYPE_DECAYED: { |
| 5806 | if (Record.size() != 1) { |
| 5807 | Error("Incorrect encoding of decayed type"); |
| 5808 | return QualType(); |
| 5809 | } |
| 5810 | QualType OriginalType = readType(*Loc.F, Record, Idx); |
| 5811 | QualType DT = Context.getAdjustedParameterType(OriginalType); |
| 5812 | if (!isa<DecayedType>(DT)) |
| 5813 | Error("Decayed type does not decay"); |
| 5814 | return DT; |
| 5815 | } |
| 5816 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 5817 | case TYPE_ADJUSTED: { |
| 5818 | if (Record.size() != 2) { |
| 5819 | Error("Incorrect encoding of adjusted type"); |
| 5820 | return QualType(); |
| 5821 | } |
| 5822 | QualType OriginalTy = readType(*Loc.F, Record, Idx); |
| 5823 | QualType AdjustedTy = readType(*Loc.F, Record, Idx); |
| 5824 | return Context.getAdjustedType(OriginalTy, AdjustedTy); |
| 5825 | } |
| 5826 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5827 | case TYPE_BLOCK_POINTER: { |
| 5828 | if (Record.size() != 1) { |
| 5829 | Error("Incorrect encoding of block pointer type"); |
| 5830 | return QualType(); |
| 5831 | } |
| 5832 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5833 | return Context.getBlockPointerType(PointeeType); |
| 5834 | } |
| 5835 | |
| 5836 | case TYPE_LVALUE_REFERENCE: { |
| 5837 | if (Record.size() != 2) { |
| 5838 | Error("Incorrect encoding of lvalue reference type"); |
| 5839 | return QualType(); |
| 5840 | } |
| 5841 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5842 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
| 5843 | } |
| 5844 | |
| 5845 | case TYPE_RVALUE_REFERENCE: { |
| 5846 | if (Record.size() != 1) { |
| 5847 | Error("Incorrect encoding of rvalue reference type"); |
| 5848 | return QualType(); |
| 5849 | } |
| 5850 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5851 | return Context.getRValueReferenceType(PointeeType); |
| 5852 | } |
| 5853 | |
| 5854 | case TYPE_MEMBER_POINTER: { |
| 5855 | if (Record.size() != 2) { |
| 5856 | Error("Incorrect encoding of member pointer type"); |
| 5857 | return QualType(); |
| 5858 | } |
| 5859 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5860 | QualType ClassType = readType(*Loc.F, Record, Idx); |
| 5861 | if (PointeeType.isNull() || ClassType.isNull()) |
| 5862 | return QualType(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5863 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5864 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
| 5865 | } |
| 5866 | |
| 5867 | case TYPE_CONSTANT_ARRAY: { |
| 5868 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5869 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 5870 | unsigned IndexTypeQuals = Record[2]; |
| 5871 | unsigned Idx = 3; |
| 5872 | llvm::APInt Size = ReadAPInt(Record, Idx); |
| 5873 | return Context.getConstantArrayType(ElementType, Size, |
| 5874 | ASM, IndexTypeQuals); |
| 5875 | } |
| 5876 | |
| 5877 | case TYPE_INCOMPLETE_ARRAY: { |
| 5878 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5879 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 5880 | unsigned IndexTypeQuals = Record[2]; |
| 5881 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
| 5882 | } |
| 5883 | |
| 5884 | case TYPE_VARIABLE_ARRAY: { |
| 5885 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5886 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 5887 | unsigned IndexTypeQuals = Record[2]; |
| 5888 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 5889 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 5890 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
| 5891 | ASM, IndexTypeQuals, |
| 5892 | SourceRange(LBLoc, RBLoc)); |
| 5893 | } |
| 5894 | |
| 5895 | case TYPE_VECTOR: { |
| 5896 | if (Record.size() != 3) { |
| 5897 | Error("incorrect encoding of vector type in AST file"); |
| 5898 | return QualType(); |
| 5899 | } |
| 5900 | |
| 5901 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5902 | unsigned NumElements = Record[1]; |
| 5903 | unsigned VecKind = Record[2]; |
| 5904 | return Context.getVectorType(ElementType, NumElements, |
| 5905 | (VectorType::VectorKind)VecKind); |
| 5906 | } |
| 5907 | |
| 5908 | case TYPE_EXT_VECTOR: { |
| 5909 | if (Record.size() != 3) { |
| 5910 | Error("incorrect encoding of extended vector type in AST file"); |
| 5911 | return QualType(); |
| 5912 | } |
| 5913 | |
| 5914 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5915 | unsigned NumElements = Record[1]; |
| 5916 | return Context.getExtVectorType(ElementType, NumElements); |
| 5917 | } |
| 5918 | |
| 5919 | case TYPE_FUNCTION_NO_PROTO: { |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5920 | if (Record.size() != 7) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5921 | Error("incorrect encoding of no-proto function type"); |
| 5922 | return QualType(); |
| 5923 | } |
| 5924 | QualType ResultType = readType(*Loc.F, Record, Idx); |
| 5925 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5926 | (CallingConv)Record[4], Record[5], Record[6]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5927 | return Context.getFunctionNoProtoType(ResultType, Info); |
| 5928 | } |
| 5929 | |
| 5930 | case TYPE_FUNCTION_PROTO: { |
| 5931 | QualType ResultType = readType(*Loc.F, Record, Idx); |
| 5932 | |
| 5933 | FunctionProtoType::ExtProtoInfo EPI; |
| 5934 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
| 5935 | /*hasregparm*/ Record[2], |
| 5936 | /*regparm*/ Record[3], |
| 5937 | static_cast<CallingConv>(Record[4]), |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5938 | /*produces*/ Record[5], |
| 5939 | /*nocallersavedregs*/ Record[6]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5940 | |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5941 | unsigned Idx = 7; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5942 | |
| 5943 | EPI.Variadic = Record[Idx++]; |
| 5944 | EPI.HasTrailingReturn = Record[Idx++]; |
| 5945 | EPI.TypeQuals = Record[Idx++]; |
| 5946 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5947 | SmallVector<QualType, 8> ExceptionStorage; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 5948 | readExceptionSpec(*Loc.F, ExceptionStorage, EPI.ExceptionSpec, Record, Idx); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 5949 | |
| 5950 | unsigned NumParams = Record[Idx++]; |
| 5951 | SmallVector<QualType, 16> ParamTypes; |
| 5952 | for (unsigned I = 0; I != NumParams; ++I) |
| 5953 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
| 5954 | |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 5955 | SmallVector<FunctionProtoType::ExtParameterInfo, 4> ExtParameterInfos; |
| 5956 | if (Idx != Record.size()) { |
| 5957 | for (unsigned I = 0; I != NumParams; ++I) |
| 5958 | ExtParameterInfos.push_back( |
| 5959 | FunctionProtoType::ExtParameterInfo |
| 5960 | ::getFromOpaqueValue(Record[Idx++])); |
| 5961 | EPI.ExtParameterInfos = ExtParameterInfos.data(); |
| 5962 | } |
| 5963 | |
| 5964 | assert(Idx == Record.size()); |
| 5965 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 5966 | return Context.getFunctionType(ResultType, ParamTypes, EPI); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5967 | } |
| 5968 | |
| 5969 | case TYPE_UNRESOLVED_USING: { |
| 5970 | unsigned Idx = 0; |
| 5971 | return Context.getTypeDeclType( |
| 5972 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 5973 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5974 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5975 | case TYPE_TYPEDEF: { |
| 5976 | if (Record.size() != 2) { |
| 5977 | Error("incorrect encoding of typedef type"); |
| 5978 | return QualType(); |
| 5979 | } |
| 5980 | unsigned Idx = 0; |
| 5981 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
| 5982 | QualType Canonical = readType(*Loc.F, Record, Idx); |
| 5983 | if (!Canonical.isNull()) |
| 5984 | Canonical = Context.getCanonicalType(Canonical); |
| 5985 | return Context.getTypedefType(Decl, Canonical); |
| 5986 | } |
| 5987 | |
| 5988 | case TYPE_TYPEOF_EXPR: |
| 5989 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
| 5990 | |
| 5991 | case TYPE_TYPEOF: { |
| 5992 | if (Record.size() != 1) { |
| 5993 | Error("incorrect encoding of typeof(type) in AST file"); |
| 5994 | return QualType(); |
| 5995 | } |
| 5996 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 5997 | return Context.getTypeOfType(UnderlyingType); |
| 5998 | } |
| 5999 | |
| 6000 | case TYPE_DECLTYPE: { |
| 6001 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 6002 | return Context.getDecltypeType(ReadExpr(*Loc.F), UnderlyingType); |
| 6003 | } |
| 6004 | |
| 6005 | case TYPE_UNARY_TRANSFORM: { |
| 6006 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 6007 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 6008 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
| 6009 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
| 6010 | } |
| 6011 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 6012 | case TYPE_AUTO: { |
| 6013 | QualType Deduced = readType(*Loc.F, Record, Idx); |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 6014 | AutoTypeKeyword Keyword = (AutoTypeKeyword)Record[Idx++]; |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 6015 | bool IsDependent = Deduced.isNull() ? Record[Idx++] : false; |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 6016 | return Context.getAutoType(Deduced, Keyword, IsDependent); |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 6017 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6018 | |
Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 6019 | case TYPE_DEDUCED_TEMPLATE_SPECIALIZATION: { |
| 6020 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
| 6021 | QualType Deduced = readType(*Loc.F, Record, Idx); |
| 6022 | bool IsDependent = Deduced.isNull() ? Record[Idx++] : false; |
| 6023 | return Context.getDeducedTemplateSpecializationType(Name, Deduced, |
| 6024 | IsDependent); |
| 6025 | } |
| 6026 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6027 | case TYPE_RECORD: { |
| 6028 | if (Record.size() != 2) { |
| 6029 | Error("incorrect encoding of record type"); |
| 6030 | return QualType(); |
| 6031 | } |
| 6032 | unsigned Idx = 0; |
| 6033 | bool IsDependent = Record[Idx++]; |
| 6034 | RecordDecl *RD = ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx); |
| 6035 | RD = cast_or_null<RecordDecl>(RD->getCanonicalDecl()); |
| 6036 | QualType T = Context.getRecordType(RD); |
| 6037 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 6038 | return T; |
| 6039 | } |
| 6040 | |
| 6041 | case TYPE_ENUM: { |
| 6042 | if (Record.size() != 2) { |
| 6043 | Error("incorrect encoding of enum type"); |
| 6044 | return QualType(); |
| 6045 | } |
| 6046 | unsigned Idx = 0; |
| 6047 | bool IsDependent = Record[Idx++]; |
| 6048 | QualType T |
| 6049 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
| 6050 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 6051 | return T; |
| 6052 | } |
| 6053 | |
| 6054 | case TYPE_ATTRIBUTED: { |
| 6055 | if (Record.size() != 3) { |
| 6056 | Error("incorrect encoding of attributed type"); |
| 6057 | return QualType(); |
| 6058 | } |
| 6059 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 6060 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
| 6061 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 6062 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
| 6063 | } |
| 6064 | |
| 6065 | case TYPE_PAREN: { |
| 6066 | if (Record.size() != 1) { |
| 6067 | Error("incorrect encoding of paren type"); |
| 6068 | return QualType(); |
| 6069 | } |
| 6070 | QualType InnerType = readType(*Loc.F, Record, Idx); |
| 6071 | return Context.getParenType(InnerType); |
| 6072 | } |
| 6073 | |
| 6074 | case TYPE_PACK_EXPANSION: { |
| 6075 | if (Record.size() != 2) { |
| 6076 | Error("incorrect encoding of pack expansion type"); |
| 6077 | return QualType(); |
| 6078 | } |
| 6079 | QualType Pattern = readType(*Loc.F, Record, Idx); |
| 6080 | if (Pattern.isNull()) |
| 6081 | return QualType(); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 6082 | Optional<unsigned> NumExpansions; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6083 | if (Record[1]) |
| 6084 | NumExpansions = Record[1] - 1; |
| 6085 | return Context.getPackExpansionType(Pattern, NumExpansions); |
| 6086 | } |
| 6087 | |
| 6088 | case TYPE_ELABORATED: { |
| 6089 | unsigned Idx = 0; |
| 6090 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 6091 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
| 6092 | QualType NamedType = readType(*Loc.F, Record, Idx); |
| 6093 | return Context.getElaboratedType(Keyword, NNS, NamedType); |
| 6094 | } |
| 6095 | |
| 6096 | case TYPE_OBJC_INTERFACE: { |
| 6097 | unsigned Idx = 0; |
| 6098 | ObjCInterfaceDecl *ItfD |
| 6099 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
| 6100 | return Context.getObjCInterfaceType(ItfD->getCanonicalDecl()); |
| 6101 | } |
| 6102 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6103 | case TYPE_OBJC_TYPE_PARAM: { |
| 6104 | unsigned Idx = 0; |
| 6105 | ObjCTypeParamDecl *Decl |
| 6106 | = ReadDeclAs<ObjCTypeParamDecl>(*Loc.F, Record, Idx); |
| 6107 | unsigned NumProtos = Record[Idx++]; |
| 6108 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 6109 | for (unsigned I = 0; I != NumProtos; ++I) |
| 6110 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
| 6111 | return Context.getObjCTypeParamType(Decl, Protos); |
| 6112 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6113 | case TYPE_OBJC_OBJECT: { |
| 6114 | unsigned Idx = 0; |
| 6115 | QualType Base = readType(*Loc.F, Record, Idx); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6116 | unsigned NumTypeArgs = Record[Idx++]; |
| 6117 | SmallVector<QualType, 4> TypeArgs; |
| 6118 | for (unsigned I = 0; I != NumTypeArgs; ++I) |
| 6119 | TypeArgs.push_back(readType(*Loc.F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6120 | unsigned NumProtos = Record[Idx++]; |
| 6121 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 6122 | for (unsigned I = 0; I != NumProtos; ++I) |
| 6123 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 6124 | bool IsKindOf = Record[Idx++]; |
| 6125 | return Context.getObjCObjectType(Base, TypeArgs, Protos, IsKindOf); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6126 | } |
| 6127 | |
| 6128 | case TYPE_OBJC_OBJECT_POINTER: { |
| 6129 | unsigned Idx = 0; |
| 6130 | QualType Pointee = readType(*Loc.F, Record, Idx); |
| 6131 | return Context.getObjCObjectPointerType(Pointee); |
| 6132 | } |
| 6133 | |
| 6134 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
| 6135 | unsigned Idx = 0; |
| 6136 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 6137 | QualType Replacement = readType(*Loc.F, Record, Idx); |
Stephan Tolksdorf | e96f8b3 | 2014-03-15 10:23:27 +0000 | [diff] [blame] | 6138 | return Context.getSubstTemplateTypeParmType( |
| 6139 | cast<TemplateTypeParmType>(Parm), |
| 6140 | Context.getCanonicalType(Replacement)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6141 | } |
| 6142 | |
| 6143 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 6144 | unsigned Idx = 0; |
| 6145 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 6146 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 6147 | return Context.getSubstTemplateTypeParmPackType( |
| 6148 | cast<TemplateTypeParmType>(Parm), |
| 6149 | ArgPack); |
| 6150 | } |
| 6151 | |
| 6152 | case TYPE_INJECTED_CLASS_NAME: { |
| 6153 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
| 6154 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
| 6155 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
| 6156 | // for AST reading, too much interdependencies. |
Richard Smith | 6377f8f | 2014-10-21 21:15:18 +0000 | [diff] [blame] | 6157 | const Type *T = nullptr; |
| 6158 | for (auto *DI = D; DI; DI = DI->getPreviousDecl()) { |
| 6159 | if (const Type *Existing = DI->getTypeForDecl()) { |
| 6160 | T = Existing; |
| 6161 | break; |
| 6162 | } |
| 6163 | } |
| 6164 | if (!T) { |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 6165 | T = new (Context, TypeAlignment) InjectedClassNameType(D, TST); |
Richard Smith | 6377f8f | 2014-10-21 21:15:18 +0000 | [diff] [blame] | 6166 | for (auto *DI = D; DI; DI = DI->getPreviousDecl()) |
| 6167 | DI->setTypeForDecl(T); |
| 6168 | } |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 6169 | return QualType(T, 0); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6170 | } |
| 6171 | |
| 6172 | case TYPE_TEMPLATE_TYPE_PARM: { |
| 6173 | unsigned Idx = 0; |
| 6174 | unsigned Depth = Record[Idx++]; |
| 6175 | unsigned Index = Record[Idx++]; |
| 6176 | bool Pack = Record[Idx++]; |
| 6177 | TemplateTypeParmDecl *D |
| 6178 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
| 6179 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
| 6180 | } |
| 6181 | |
| 6182 | case TYPE_DEPENDENT_NAME: { |
| 6183 | unsigned Idx = 0; |
| 6184 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 6185 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 6186 | const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6187 | QualType Canon = readType(*Loc.F, Record, Idx); |
| 6188 | if (!Canon.isNull()) |
| 6189 | Canon = Context.getCanonicalType(Canon); |
| 6190 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
| 6191 | } |
| 6192 | |
| 6193 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
| 6194 | unsigned Idx = 0; |
| 6195 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 6196 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 6197 | const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6198 | unsigned NumArgs = Record[Idx++]; |
| 6199 | SmallVector<TemplateArgument, 8> Args; |
| 6200 | Args.reserve(NumArgs); |
| 6201 | while (NumArgs--) |
| 6202 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
| 6203 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 6204 | Args); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6205 | } |
| 6206 | |
| 6207 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
| 6208 | unsigned Idx = 0; |
| 6209 | |
| 6210 | // ArrayType |
| 6211 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 6212 | ArrayType::ArraySizeModifier ASM |
| 6213 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 6214 | unsigned IndexTypeQuals = Record[Idx++]; |
| 6215 | |
| 6216 | // DependentSizedArrayType |
| 6217 | Expr *NumElts = ReadExpr(*Loc.F); |
| 6218 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
| 6219 | |
| 6220 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 6221 | IndexTypeQuals, Brackets); |
| 6222 | } |
| 6223 | |
| 6224 | case TYPE_TEMPLATE_SPECIALIZATION: { |
| 6225 | unsigned Idx = 0; |
| 6226 | bool IsDependent = Record[Idx++]; |
| 6227 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
| 6228 | SmallVector<TemplateArgument, 8> Args; |
| 6229 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
| 6230 | QualType Underlying = readType(*Loc.F, Record, Idx); |
| 6231 | QualType T; |
| 6232 | if (Underlying.isNull()) |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 6233 | T = Context.getCanonicalTemplateSpecializationType(Name, Args); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6234 | else |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 6235 | T = Context.getTemplateSpecializationType(Name, Args, Underlying); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6236 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 6237 | return T; |
| 6238 | } |
| 6239 | |
| 6240 | case TYPE_ATOMIC: { |
| 6241 | if (Record.size() != 1) { |
| 6242 | Error("Incorrect encoding of atomic type"); |
| 6243 | return QualType(); |
| 6244 | } |
| 6245 | QualType ValueType = readType(*Loc.F, Record, Idx); |
| 6246 | return Context.getAtomicType(ValueType); |
| 6247 | } |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6248 | |
Joey Gouly | e3c85de | 2016-12-01 11:30:49 +0000 | [diff] [blame] | 6249 | case TYPE_PIPE: { |
| 6250 | if (Record.size() != 2) { |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6251 | Error("Incorrect encoding of pipe type"); |
| 6252 | return QualType(); |
| 6253 | } |
| 6254 | |
| 6255 | // Reading the pipe element type. |
| 6256 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Joey Gouly | e3c85de | 2016-12-01 11:30:49 +0000 | [diff] [blame] | 6257 | unsigned ReadOnly = Record[1]; |
| 6258 | return Context.getPipeType(ElementType, ReadOnly); |
Joey Gouly | 5788b78 | 2016-11-18 14:10:54 +0000 | [diff] [blame] | 6259 | } |
| 6260 | |
Alex Lorenz | 00aee43 | 2017-03-22 10:04:48 +0000 | [diff] [blame] | 6261 | case TYPE_DEPENDENT_SIZED_EXT_VECTOR: { |
| 6262 | unsigned Idx = 0; |
| 6263 | |
| 6264 | // DependentSizedExtVectorType |
| 6265 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 6266 | Expr *SizeExpr = ReadExpr(*Loc.F); |
| 6267 | SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx); |
| 6268 | |
| 6269 | return Context.getDependentSizedExtVectorType(ElementType, SizeExpr, |
| 6270 | AttrLoc); |
| 6271 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6272 | } |
| 6273 | llvm_unreachable("Invalid TypeCode!"); |
| 6274 | } |
| 6275 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6276 | void ASTReader::readExceptionSpec(ModuleFile &ModuleFile, |
| 6277 | SmallVectorImpl<QualType> &Exceptions, |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6278 | FunctionProtoType::ExceptionSpecInfo &ESI, |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6279 | const RecordData &Record, unsigned &Idx) { |
| 6280 | ExceptionSpecificationType EST = |
| 6281 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6282 | ESI.Type = EST; |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6283 | if (EST == EST_Dynamic) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6284 | for (unsigned I = 0, N = Record[Idx++]; I != N; ++I) |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6285 | Exceptions.push_back(readType(ModuleFile, Record, Idx)); |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6286 | ESI.Exceptions = Exceptions; |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6287 | } else if (EST == EST_ComputedNoexcept) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6288 | ESI.NoexceptExpr = ReadExpr(ModuleFile); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6289 | } else if (EST == EST_Uninstantiated) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6290 | ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
| 6291 | ESI.SourceTemplate = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6292 | } else if (EST == EST_Unevaluated) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6293 | ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6294 | } |
| 6295 | } |
| 6296 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6297 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6298 | ModuleFile *F; |
| 6299 | ASTReader *Reader; |
| 6300 | const ASTReader::RecordData &Record; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6301 | unsigned &Idx; |
| 6302 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6303 | SourceLocation ReadSourceLocation() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6304 | return Reader->ReadSourceLocation(*F, Record, Idx); |
| 6305 | } |
| 6306 | |
| 6307 | TypeSourceInfo *GetTypeSourceInfo() { |
| 6308 | return Reader->GetTypeSourceInfo(*F, Record, Idx); |
| 6309 | } |
| 6310 | |
| 6311 | NestedNameSpecifierLoc ReadNestedNameSpecifierLoc() { |
| 6312 | return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6313 | } |
| 6314 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6315 | public: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6316 | TypeLocReader(ModuleFile &F, ASTReader &Reader, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6317 | const ASTReader::RecordData &Record, unsigned &Idx) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6318 | : F(&F), Reader(&Reader), Record(Record), Idx(Idx) {} |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6319 | |
| 6320 | // We want compile-time assurance that we've enumerated all of |
| 6321 | // these, so unfortunately we have to declare them first, then |
| 6322 | // define them out-of-line. |
| 6323 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 6324 | #define TYPELOC(CLASS, PARENT) \ |
| 6325 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
| 6326 | #include "clang/AST/TypeLocNodes.def" |
| 6327 | |
| 6328 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 6329 | void VisitArrayTypeLoc(ArrayTypeLoc); |
| 6330 | }; |
| 6331 | |
| 6332 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 6333 | // nothing to do |
| 6334 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6335 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6336 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6337 | TL.setBuiltinLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6338 | if (TL.needsExtraLocalData()) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6339 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 6340 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 6341 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 6342 | TL.setModeAttr(Record[Idx++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6343 | } |
| 6344 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6345 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6346 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6347 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6348 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6349 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6350 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6351 | TL.setStarLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6352 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6353 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 6354 | void TypeLocReader::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 6355 | // nothing to do |
| 6356 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6357 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 6358 | void TypeLocReader::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 6359 | // nothing to do |
| 6360 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6361 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6362 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6363 | TL.setCaretLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6364 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6365 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6366 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6367 | TL.setAmpLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6368 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6369 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6370 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6371 | TL.setAmpAmpLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6372 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6373 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6374 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6375 | TL.setStarLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6376 | TL.setClassTInfo(GetTypeSourceInfo()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6377 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6378 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6379 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6380 | TL.setLBracketLoc(ReadSourceLocation()); |
| 6381 | TL.setRBracketLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6382 | if (Record[Idx++]) |
| 6383 | TL.setSizeExpr(Reader->ReadExpr(*F)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6384 | else |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6385 | TL.setSizeExpr(nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6386 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6387 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6388 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 6389 | VisitArrayTypeLoc(TL); |
| 6390 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6391 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6392 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 6393 | VisitArrayTypeLoc(TL); |
| 6394 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6395 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6396 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 6397 | VisitArrayTypeLoc(TL); |
| 6398 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6399 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6400 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 6401 | DependentSizedArrayTypeLoc TL) { |
| 6402 | VisitArrayTypeLoc(TL); |
| 6403 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6404 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6405 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 6406 | DependentSizedExtVectorTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6407 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6408 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6409 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6410 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6411 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6412 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6413 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6414 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6415 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6416 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6417 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6418 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6419 | TL.setLocalRangeBegin(ReadSourceLocation()); |
| 6420 | TL.setLParenLoc(ReadSourceLocation()); |
| 6421 | TL.setRParenLoc(ReadSourceLocation()); |
Malcolm Parsons | a3220ce | 2017-01-12 16:11:28 +0000 | [diff] [blame] | 6422 | TL.setExceptionSpecRange(SourceRange(Reader->ReadSourceLocation(*F, Record, Idx), |
| 6423 | Reader->ReadSourceLocation(*F, Record, Idx))); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6424 | TL.setLocalRangeEnd(ReadSourceLocation()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 6425 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6426 | TL.setParam(i, Reader->ReadDeclAs<ParmVarDecl>(*F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6427 | } |
| 6428 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6429 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6430 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 6431 | VisitFunctionTypeLoc(TL); |
| 6432 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6433 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6434 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 6435 | VisitFunctionTypeLoc(TL); |
| 6436 | } |
| 6437 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6438 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6439 | } |
| 6440 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6441 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6442 | } |
| 6443 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6444 | TL.setTypeofLoc(ReadSourceLocation()); |
| 6445 | TL.setLParenLoc(ReadSourceLocation()); |
| 6446 | TL.setRParenLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6447 | } |
| 6448 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6449 | TL.setTypeofLoc(ReadSourceLocation()); |
| 6450 | TL.setLParenLoc(ReadSourceLocation()); |
| 6451 | TL.setRParenLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6452 | TL.setUnderlyingTInfo(GetTypeSourceInfo()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6453 | } |
| 6454 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6455 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6456 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6457 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6458 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6459 | TL.setKWLoc(ReadSourceLocation()); |
| 6460 | TL.setLParenLoc(ReadSourceLocation()); |
| 6461 | TL.setRParenLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6462 | TL.setUnderlyingTInfo(GetTypeSourceInfo()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6463 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6464 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6465 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6466 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6467 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6468 | |
Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 6469 | void TypeLocReader::VisitDeducedTemplateSpecializationTypeLoc( |
| 6470 | DeducedTemplateSpecializationTypeLoc TL) { |
| 6471 | TL.setTemplateNameLoc(ReadSourceLocation()); |
| 6472 | } |
| 6473 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6474 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6475 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6476 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6477 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6478 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6479 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6480 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6481 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6482 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6483 | TL.setAttrNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6484 | if (TL.hasAttrOperand()) { |
| 6485 | SourceRange range; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6486 | range.setBegin(ReadSourceLocation()); |
| 6487 | range.setEnd(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6488 | TL.setAttrOperandParensRange(range); |
| 6489 | } |
| 6490 | if (TL.hasAttrExprOperand()) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6491 | if (Record[Idx++]) |
| 6492 | TL.setAttrExprOperand(Reader->ReadExpr(*F)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6493 | else |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6494 | TL.setAttrExprOperand(nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6495 | } else if (TL.hasAttrEnumOperand()) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6496 | TL.setAttrEnumOperandLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6497 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6498 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6499 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6500 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6501 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6502 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6503 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 6504 | SubstTemplateTypeParmTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6505 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6506 | } |
| 6507 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 6508 | SubstTemplateTypeParmPackTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6509 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6510 | } |
| 6511 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 6512 | TemplateSpecializationTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6513 | TL.setTemplateKeywordLoc(ReadSourceLocation()); |
| 6514 | TL.setTemplateNameLoc(ReadSourceLocation()); |
| 6515 | TL.setLAngleLoc(ReadSourceLocation()); |
| 6516 | TL.setRAngleLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6517 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6518 | TL.setArgLocInfo( |
| 6519 | i, |
| 6520 | Reader->GetTemplateArgumentLocInfo( |
| 6521 | *F, TL.getTypePtr()->getArg(i).getKind(), Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6522 | } |
| 6523 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6524 | TL.setLParenLoc(ReadSourceLocation()); |
| 6525 | TL.setRParenLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6526 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6527 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6528 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6529 | TL.setElaboratedKeywordLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6530 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6531 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6532 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6533 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6534 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6535 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6536 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6537 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6538 | TL.setElaboratedKeywordLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6539 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6540 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6541 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6542 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6543 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 6544 | DependentTemplateSpecializationTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6545 | TL.setElaboratedKeywordLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6546 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6547 | TL.setTemplateKeywordLoc(ReadSourceLocation()); |
| 6548 | TL.setTemplateNameLoc(ReadSourceLocation()); |
| 6549 | TL.setLAngleLoc(ReadSourceLocation()); |
| 6550 | TL.setRAngleLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6551 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6552 | TL.setArgLocInfo( |
| 6553 | I, |
| 6554 | Reader->GetTemplateArgumentLocInfo( |
| 6555 | *F, TL.getTypePtr()->getArg(I).getKind(), Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6556 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6557 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6558 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6559 | TL.setEllipsisLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6560 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6561 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6562 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6563 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6564 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6565 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6566 | void TypeLocReader::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { |
| 6567 | if (TL.getNumProtocols()) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6568 | TL.setProtocolLAngleLoc(ReadSourceLocation()); |
| 6569 | TL.setProtocolRAngleLoc(ReadSourceLocation()); |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6570 | } |
| 6571 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6572 | TL.setProtocolLoc(i, ReadSourceLocation()); |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6573 | } |
| 6574 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6575 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6576 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6577 | TL.setTypeArgsLAngleLoc(ReadSourceLocation()); |
| 6578 | TL.setTypeArgsRAngleLoc(ReadSourceLocation()); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6579 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6580 | TL.setTypeArgTInfo(i, GetTypeSourceInfo()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6581 | TL.setProtocolLAngleLoc(ReadSourceLocation()); |
| 6582 | TL.setProtocolRAngleLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6583 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6584 | TL.setProtocolLoc(i, ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6585 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6586 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6587 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6588 | TL.setStarLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6589 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6590 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6591 | void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6592 | TL.setKWLoc(ReadSourceLocation()); |
| 6593 | TL.setLParenLoc(ReadSourceLocation()); |
| 6594 | TL.setRParenLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6595 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6596 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6597 | void TypeLocReader::VisitPipeTypeLoc(PipeTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6598 | TL.setKWLoc(ReadSourceLocation()); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6599 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6600 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6601 | TypeSourceInfo * |
| 6602 | ASTReader::GetTypeSourceInfo(ModuleFile &F, const ASTReader::RecordData &Record, |
| 6603 | unsigned &Idx) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6604 | QualType InfoTy = readType(F, Record, Idx); |
| 6605 | if (InfoTy.isNull()) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6606 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6607 | |
| 6608 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6609 | TypeLocReader TLR(F, *this, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6610 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
| 6611 | TLR.Visit(TL); |
| 6612 | return TInfo; |
| 6613 | } |
| 6614 | |
| 6615 | QualType ASTReader::GetType(TypeID ID) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 6616 | assert(ContextObj && "reading type with no AST context"); |
| 6617 | ASTContext &Context = *ContextObj; |
| 6618 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6619 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 6620 | unsigned Index = ID >> Qualifiers::FastWidth; |
| 6621 | |
| 6622 | if (Index < NUM_PREDEF_TYPE_IDS) { |
| 6623 | QualType T; |
| 6624 | switch ((PredefinedTypeIDs)Index) { |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6625 | case PREDEF_TYPE_NULL_ID: |
| 6626 | return QualType(); |
| 6627 | case PREDEF_TYPE_VOID_ID: |
| 6628 | T = Context.VoidTy; |
| 6629 | break; |
| 6630 | case PREDEF_TYPE_BOOL_ID: |
| 6631 | T = Context.BoolTy; |
| 6632 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6633 | |
| 6634 | case PREDEF_TYPE_CHAR_U_ID: |
| 6635 | case PREDEF_TYPE_CHAR_S_ID: |
| 6636 | // FIXME: Check that the signedness of CharTy is correct! |
| 6637 | T = Context.CharTy; |
| 6638 | break; |
| 6639 | |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6640 | case PREDEF_TYPE_UCHAR_ID: |
| 6641 | T = Context.UnsignedCharTy; |
| 6642 | break; |
| 6643 | case PREDEF_TYPE_USHORT_ID: |
| 6644 | T = Context.UnsignedShortTy; |
| 6645 | break; |
| 6646 | case PREDEF_TYPE_UINT_ID: |
| 6647 | T = Context.UnsignedIntTy; |
| 6648 | break; |
| 6649 | case PREDEF_TYPE_ULONG_ID: |
| 6650 | T = Context.UnsignedLongTy; |
| 6651 | break; |
| 6652 | case PREDEF_TYPE_ULONGLONG_ID: |
| 6653 | T = Context.UnsignedLongLongTy; |
| 6654 | break; |
| 6655 | case PREDEF_TYPE_UINT128_ID: |
| 6656 | T = Context.UnsignedInt128Ty; |
| 6657 | break; |
| 6658 | case PREDEF_TYPE_SCHAR_ID: |
| 6659 | T = Context.SignedCharTy; |
| 6660 | break; |
| 6661 | case PREDEF_TYPE_WCHAR_ID: |
| 6662 | T = Context.WCharTy; |
| 6663 | break; |
| 6664 | case PREDEF_TYPE_SHORT_ID: |
| 6665 | T = Context.ShortTy; |
| 6666 | break; |
| 6667 | case PREDEF_TYPE_INT_ID: |
| 6668 | T = Context.IntTy; |
| 6669 | break; |
| 6670 | case PREDEF_TYPE_LONG_ID: |
| 6671 | T = Context.LongTy; |
| 6672 | break; |
| 6673 | case PREDEF_TYPE_LONGLONG_ID: |
| 6674 | T = Context.LongLongTy; |
| 6675 | break; |
| 6676 | case PREDEF_TYPE_INT128_ID: |
| 6677 | T = Context.Int128Ty; |
| 6678 | break; |
| 6679 | case PREDEF_TYPE_HALF_ID: |
| 6680 | T = Context.HalfTy; |
| 6681 | break; |
| 6682 | case PREDEF_TYPE_FLOAT_ID: |
| 6683 | T = Context.FloatTy; |
| 6684 | break; |
| 6685 | case PREDEF_TYPE_DOUBLE_ID: |
| 6686 | T = Context.DoubleTy; |
| 6687 | break; |
| 6688 | case PREDEF_TYPE_LONGDOUBLE_ID: |
| 6689 | T = Context.LongDoubleTy; |
| 6690 | break; |
Sjoerd Meijer | cc623ad | 2017-09-08 15:15:00 +0000 | [diff] [blame] | 6691 | case PREDEF_TYPE_FLOAT16_ID: |
| 6692 | T = Context.Float16Ty; |
| 6693 | break; |
Nemanja Ivanovic | bb1ea2d | 2016-05-09 08:52:33 +0000 | [diff] [blame] | 6694 | case PREDEF_TYPE_FLOAT128_ID: |
| 6695 | T = Context.Float128Ty; |
| 6696 | break; |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6697 | case PREDEF_TYPE_OVERLOAD_ID: |
| 6698 | T = Context.OverloadTy; |
| 6699 | break; |
| 6700 | case PREDEF_TYPE_BOUND_MEMBER: |
| 6701 | T = Context.BoundMemberTy; |
| 6702 | break; |
| 6703 | case PREDEF_TYPE_PSEUDO_OBJECT: |
| 6704 | T = Context.PseudoObjectTy; |
| 6705 | break; |
| 6706 | case PREDEF_TYPE_DEPENDENT_ID: |
| 6707 | T = Context.DependentTy; |
| 6708 | break; |
| 6709 | case PREDEF_TYPE_UNKNOWN_ANY: |
| 6710 | T = Context.UnknownAnyTy; |
| 6711 | break; |
| 6712 | case PREDEF_TYPE_NULLPTR_ID: |
| 6713 | T = Context.NullPtrTy; |
| 6714 | break; |
| 6715 | case PREDEF_TYPE_CHAR16_ID: |
| 6716 | T = Context.Char16Ty; |
| 6717 | break; |
| 6718 | case PREDEF_TYPE_CHAR32_ID: |
| 6719 | T = Context.Char32Ty; |
| 6720 | break; |
| 6721 | case PREDEF_TYPE_OBJC_ID: |
| 6722 | T = Context.ObjCBuiltinIdTy; |
| 6723 | break; |
| 6724 | case PREDEF_TYPE_OBJC_CLASS: |
| 6725 | T = Context.ObjCBuiltinClassTy; |
| 6726 | break; |
| 6727 | case PREDEF_TYPE_OBJC_SEL: |
| 6728 | T = Context.ObjCBuiltinSelTy; |
| 6729 | break; |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 6730 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 6731 | case PREDEF_TYPE_##Id##_ID: \ |
| 6732 | T = Context.SingletonId; \ |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6733 | break; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 6734 | #include "clang/Basic/OpenCLImageTypes.def" |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6735 | case PREDEF_TYPE_SAMPLER_ID: |
| 6736 | T = Context.OCLSamplerTy; |
| 6737 | break; |
| 6738 | case PREDEF_TYPE_EVENT_ID: |
| 6739 | T = Context.OCLEventTy; |
| 6740 | break; |
Alexey Bader | 9c8453f | 2015-09-15 11:18:52 +0000 | [diff] [blame] | 6741 | case PREDEF_TYPE_CLK_EVENT_ID: |
| 6742 | T = Context.OCLClkEventTy; |
| 6743 | break; |
| 6744 | case PREDEF_TYPE_QUEUE_ID: |
| 6745 | T = Context.OCLQueueTy; |
| 6746 | break; |
Alexey Bader | 9c8453f | 2015-09-15 11:18:52 +0000 | [diff] [blame] | 6747 | case PREDEF_TYPE_RESERVE_ID_ID: |
| 6748 | T = Context.OCLReserveIDTy; |
| 6749 | break; |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6750 | case PREDEF_TYPE_AUTO_DEDUCT: |
| 6751 | T = Context.getAutoDeductType(); |
| 6752 | break; |
| 6753 | |
| 6754 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
| 6755 | T = Context.getAutoRRefDeductType(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6756 | break; |
| 6757 | |
| 6758 | case PREDEF_TYPE_ARC_UNBRIDGED_CAST: |
| 6759 | T = Context.ARCUnbridgedCastTy; |
| 6760 | break; |
| 6761 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6762 | case PREDEF_TYPE_BUILTIN_FN: |
| 6763 | T = Context.BuiltinFnTy; |
| 6764 | break; |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 6765 | |
| 6766 | case PREDEF_TYPE_OMP_ARRAY_SECTION: |
| 6767 | T = Context.OMPArraySectionTy; |
| 6768 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6769 | } |
| 6770 | |
| 6771 | assert(!T.isNull() && "Unknown predefined type"); |
| 6772 | return T.withFastQualifiers(FastQuals); |
| 6773 | } |
| 6774 | |
| 6775 | Index -= NUM_PREDEF_TYPE_IDS; |
| 6776 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
| 6777 | if (TypesLoaded[Index].isNull()) { |
| 6778 | TypesLoaded[Index] = readTypeRecord(Index); |
| 6779 | if (TypesLoaded[Index].isNull()) |
| 6780 | return QualType(); |
| 6781 | |
| 6782 | TypesLoaded[Index]->setFromAST(); |
| 6783 | if (DeserializationListener) |
| 6784 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
| 6785 | TypesLoaded[Index]); |
| 6786 | } |
| 6787 | |
| 6788 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
| 6789 | } |
| 6790 | |
| 6791 | QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) { |
| 6792 | return GetType(getGlobalTypeID(F, LocalID)); |
| 6793 | } |
| 6794 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6795 | serialization::TypeID |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6796 | ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const { |
| 6797 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 6798 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6799 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6800 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 6801 | return LocalID; |
| 6802 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 6803 | if (!F.ModuleOffsetMap.empty()) |
| 6804 | ReadModuleOffsetMap(F); |
| 6805 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6806 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6807 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 6808 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6809 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6810 | unsigned GlobalIndex = LocalIndex + I->second; |
| 6811 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 6812 | } |
| 6813 | |
| 6814 | TemplateArgumentLocInfo |
| 6815 | ASTReader::GetTemplateArgumentLocInfo(ModuleFile &F, |
| 6816 | TemplateArgument::ArgKind Kind, |
| 6817 | const RecordData &Record, |
| 6818 | unsigned &Index) { |
| 6819 | switch (Kind) { |
| 6820 | case TemplateArgument::Expression: |
| 6821 | return ReadExpr(F); |
| 6822 | case TemplateArgument::Type: |
| 6823 | return GetTypeSourceInfo(F, Record, Index); |
| 6824 | case TemplateArgument::Template: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6825 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6826 | Index); |
| 6827 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
| 6828 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
| 6829 | SourceLocation()); |
| 6830 | } |
| 6831 | case TemplateArgument::TemplateExpansion: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6832 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6833 | Index); |
| 6834 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
| 6835 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6836 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6837 | EllipsisLoc); |
| 6838 | } |
| 6839 | case TemplateArgument::Null: |
| 6840 | case TemplateArgument::Integral: |
| 6841 | case TemplateArgument::Declaration: |
| 6842 | case TemplateArgument::NullPtr: |
| 6843 | case TemplateArgument::Pack: |
| 6844 | // FIXME: Is this right? |
| 6845 | return TemplateArgumentLocInfo(); |
| 6846 | } |
| 6847 | llvm_unreachable("unexpected template argument loc"); |
| 6848 | } |
| 6849 | |
| 6850 | TemplateArgumentLoc |
| 6851 | ASTReader::ReadTemplateArgumentLoc(ModuleFile &F, |
| 6852 | const RecordData &Record, unsigned &Index) { |
| 6853 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
| 6854 | |
| 6855 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 6856 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 6857 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 6858 | } |
| 6859 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
| 6860 | Record, Index)); |
| 6861 | } |
| 6862 | |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 6863 | const ASTTemplateArgumentListInfo* |
| 6864 | ASTReader::ReadASTTemplateArgumentListInfo(ModuleFile &F, |
| 6865 | const RecordData &Record, |
| 6866 | unsigned &Index) { |
| 6867 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Index); |
| 6868 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Index); |
| 6869 | unsigned NumArgsAsWritten = Record[Index++]; |
| 6870 | TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); |
| 6871 | for (unsigned i = 0; i != NumArgsAsWritten; ++i) |
| 6872 | TemplArgsInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Index)); |
| 6873 | return ASTTemplateArgumentListInfo::Create(getContext(), TemplArgsInfo); |
| 6874 | } |
| 6875 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6876 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
| 6877 | return GetDecl(ID); |
| 6878 | } |
| 6879 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6880 | void ASTReader::CompleteRedeclChain(const Decl *D) { |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 6881 | if (NumCurrentElementsDeserializing) { |
| 6882 | // We arrange to not care about the complete redeclaration chain while we're |
| 6883 | // deserializing. Just remember that the AST has marked this one as complete |
| 6884 | // but that it's not actually complete yet, so we know we still need to |
| 6885 | // complete it later. |
| 6886 | PendingIncompleteDeclChains.push_back(const_cast<Decl*>(D)); |
| 6887 | return; |
| 6888 | } |
| 6889 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6890 | const DeclContext *DC = D->getDeclContext()->getRedeclContext(); |
| 6891 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6892 | // If this is a named declaration, complete it by looking it up |
| 6893 | // within its context. |
| 6894 | // |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 6895 | // FIXME: Merging a function definition should merge |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6896 | // all mergeable entities within it. |
| 6897 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC) || |
| 6898 | isa<CXXRecordDecl>(DC) || isa<EnumDecl>(DC)) { |
| 6899 | if (DeclarationName Name = cast<NamedDecl>(D)->getDeclName()) { |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 6900 | if (!getContext().getLangOpts().CPlusPlus && |
| 6901 | isa<TranslationUnitDecl>(DC)) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6902 | // Outside of C++, we don't have a lookup table for the TU, so update |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 6903 | // the identifier instead. (For C++ modules, we don't store decls |
| 6904 | // in the serialized identifier table, so we do the lookup in the TU.) |
| 6905 | auto *II = Name.getAsIdentifierInfo(); |
| 6906 | assert(II && "non-identifier name in C?"); |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6907 | if (II->isOutOfDate()) |
| 6908 | updateOutOfDateIdentifier(*II); |
| 6909 | } else |
| 6910 | DC->lookup(Name); |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 6911 | } else if (needsAnonymousDeclarationNumber(cast<NamedDecl>(D))) { |
Richard Smith | 3cb1572 | 2015-08-05 22:41:45 +0000 | [diff] [blame] | 6912 | // Find all declarations of this kind from the relevant context. |
| 6913 | for (auto *DCDecl : cast<Decl>(D->getLexicalDeclContext())->redecls()) { |
| 6914 | auto *DC = cast<DeclContext>(DCDecl); |
| 6915 | SmallVector<Decl*, 8> Decls; |
| 6916 | FindExternalLexicalDecls( |
| 6917 | DC, [&](Decl::Kind K) { return K == D->getKind(); }, Decls); |
| 6918 | } |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6919 | } |
| 6920 | } |
Richard Smith | 5089542 | 2015-01-31 03:04:55 +0000 | [diff] [blame] | 6921 | |
| 6922 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D)) |
| 6923 | CTSD->getSpecializedTemplate()->LoadLazySpecializations(); |
| 6924 | if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) |
| 6925 | VTSD->getSpecializedTemplate()->LoadLazySpecializations(); |
| 6926 | if (auto *FD = dyn_cast<FunctionDecl>(D)) { |
| 6927 | if (auto *Template = FD->getPrimaryTemplate()) |
| 6928 | Template->LoadLazySpecializations(); |
| 6929 | } |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6930 | } |
| 6931 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 6932 | CXXCtorInitializer ** |
| 6933 | ASTReader::GetExternalCXXCtorInitializers(uint64_t Offset) { |
| 6934 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 6935 | BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
| 6936 | SavedStreamPosition SavedPosition(Cursor); |
| 6937 | Cursor.JumpToBit(Loc.Offset); |
| 6938 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 6939 | |
| 6940 | RecordData Record; |
| 6941 | unsigned Code = Cursor.ReadCode(); |
| 6942 | unsigned RecCode = Cursor.readRecord(Code, Record); |
| 6943 | if (RecCode != DECL_CXX_CTOR_INITIALIZERS) { |
| 6944 | Error("malformed AST file: missing C++ ctor initializers"); |
| 6945 | return nullptr; |
| 6946 | } |
| 6947 | |
| 6948 | unsigned Idx = 0; |
| 6949 | return ReadCXXCtorInitializers(*Loc.F, Record, Idx); |
| 6950 | } |
| 6951 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6952 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 6953 | assert(ContextObj && "reading base specifiers with no AST context"); |
| 6954 | ASTContext &Context = *ContextObj; |
| 6955 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6956 | RecordLocation Loc = getLocalBitOffset(Offset); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 6957 | BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6958 | SavedStreamPosition SavedPosition(Cursor); |
| 6959 | Cursor.JumpToBit(Loc.Offset); |
| 6960 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 6961 | RecordData Record; |
| 6962 | unsigned Code = Cursor.ReadCode(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 6963 | unsigned RecCode = Cursor.readRecord(Code, Record); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6964 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6965 | Error("malformed AST file: missing C++ base specifiers"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6966 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6967 | } |
| 6968 | |
| 6969 | unsigned Idx = 0; |
| 6970 | unsigned NumBases = Record[Idx++]; |
| 6971 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 6972 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 6973 | for (unsigned I = 0; I != NumBases; ++I) |
| 6974 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
| 6975 | return Bases; |
| 6976 | } |
| 6977 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6978 | serialization::DeclID |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6979 | ASTReader::getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const { |
| 6980 | if (LocalID < NUM_PREDEF_DECL_IDS) |
| 6981 | return LocalID; |
| 6982 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 6983 | if (!F.ModuleOffsetMap.empty()) |
| 6984 | ReadModuleOffsetMap(F); |
| 6985 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6986 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6987 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
| 6988 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6989 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6990 | return LocalID + I->second; |
| 6991 | } |
| 6992 | |
| 6993 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
| 6994 | ModuleFile &M) const { |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 6995 | // Predefined decls aren't from any module. |
| 6996 | if (ID < NUM_PREDEF_DECL_IDS) |
| 6997 | return false; |
| 6998 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6999 | return ID - NUM_PREDEF_DECL_IDS >= M.BaseDeclID && |
Richard Smith | bcda1a9 | 2015-07-12 23:51:20 +0000 | [diff] [blame] | 7000 | ID - NUM_PREDEF_DECL_IDS < M.BaseDeclID + M.LocalNumDecls; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7001 | } |
| 7002 | |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 7003 | ModuleFile *ASTReader::getOwningModuleFile(const Decl *D) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7004 | if (!D->isFromASTFile()) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7005 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7006 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID()); |
| 7007 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 7008 | return I->second; |
| 7009 | } |
| 7010 | |
| 7011 | SourceLocation ASTReader::getSourceLocationForDeclID(GlobalDeclID ID) { |
| 7012 | if (ID < NUM_PREDEF_DECL_IDS) |
| 7013 | return SourceLocation(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7014 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7015 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 7016 | |
| 7017 | if (Index > DeclsLoaded.size()) { |
| 7018 | Error("declaration ID out-of-range for AST file"); |
| 7019 | return SourceLocation(); |
| 7020 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7021 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7022 | if (Decl *D = DeclsLoaded[Index]) |
| 7023 | return D->getLocation(); |
| 7024 | |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 7025 | SourceLocation Loc; |
| 7026 | DeclCursorForID(ID, Loc); |
| 7027 | return Loc; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7028 | } |
| 7029 | |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7030 | static Decl *getPredefinedDecl(ASTContext &Context, PredefinedDeclIDs ID) { |
| 7031 | switch (ID) { |
| 7032 | case PREDEF_DECL_NULL_ID: |
| 7033 | return nullptr; |
| 7034 | |
| 7035 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
| 7036 | return Context.getTranslationUnitDecl(); |
| 7037 | |
| 7038 | case PREDEF_DECL_OBJC_ID_ID: |
| 7039 | return Context.getObjCIdDecl(); |
| 7040 | |
| 7041 | case PREDEF_DECL_OBJC_SEL_ID: |
| 7042 | return Context.getObjCSelDecl(); |
| 7043 | |
| 7044 | case PREDEF_DECL_OBJC_CLASS_ID: |
| 7045 | return Context.getObjCClassDecl(); |
| 7046 | |
| 7047 | case PREDEF_DECL_OBJC_PROTOCOL_ID: |
| 7048 | return Context.getObjCProtocolDecl(); |
| 7049 | |
| 7050 | case PREDEF_DECL_INT_128_ID: |
| 7051 | return Context.getInt128Decl(); |
| 7052 | |
| 7053 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
| 7054 | return Context.getUInt128Decl(); |
| 7055 | |
| 7056 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
| 7057 | return Context.getObjCInstanceTypeDecl(); |
| 7058 | |
| 7059 | case PREDEF_DECL_BUILTIN_VA_LIST_ID: |
| 7060 | return Context.getBuiltinVaListDecl(); |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 7061 | |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 7062 | case PREDEF_DECL_VA_LIST_TAG: |
| 7063 | return Context.getVaListTagDecl(); |
| 7064 | |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 7065 | case PREDEF_DECL_BUILTIN_MS_VA_LIST_ID: |
| 7066 | return Context.getBuiltinMSVaListDecl(); |
| 7067 | |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 7068 | case PREDEF_DECL_EXTERN_C_CONTEXT_ID: |
| 7069 | return Context.getExternCContextDecl(); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 7070 | |
| 7071 | case PREDEF_DECL_MAKE_INTEGER_SEQ_ID: |
| 7072 | return Context.getMakeIntegerSeqDecl(); |
Quentin Colombet | 043406b | 2016-02-03 22:41:00 +0000 | [diff] [blame] | 7073 | |
| 7074 | case PREDEF_DECL_CF_CONSTANT_STRING_ID: |
| 7075 | return Context.getCFConstantStringDecl(); |
Ben Langmuir | f541674 | 2016-02-04 00:55:24 +0000 | [diff] [blame] | 7076 | |
| 7077 | case PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID: |
| 7078 | return Context.getCFConstantStringTagDecl(); |
Eric Fiselier | 6ad6855 | 2016-07-01 01:24:09 +0000 | [diff] [blame] | 7079 | |
| 7080 | case PREDEF_DECL_TYPE_PACK_ELEMENT_ID: |
| 7081 | return Context.getTypePackElementDecl(); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7082 | } |
Yaron Keren | 322bdad | 2015-03-06 07:49:14 +0000 | [diff] [blame] | 7083 | llvm_unreachable("PredefinedDeclIDs unknown enum value"); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7084 | } |
| 7085 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7086 | Decl *ASTReader::GetExistingDecl(DeclID ID) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 7087 | assert(ContextObj && "reading decl with no AST context"); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7088 | if (ID < NUM_PREDEF_DECL_IDS) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 7089 | Decl *D = getPredefinedDecl(*ContextObj, (PredefinedDeclIDs)ID); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7090 | if (D) { |
| 7091 | // Track that we have merged the declaration with ID \p ID into the |
| 7092 | // pre-existing predefined declaration \p D. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 7093 | auto &Merged = KeyDecls[D->getCanonicalDecl()]; |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7094 | if (Merged.empty()) |
| 7095 | Merged.push_back(ID); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7096 | } |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7097 | return D; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7098 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7099 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7100 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 7101 | |
| 7102 | if (Index >= DeclsLoaded.size()) { |
| 7103 | assert(0 && "declaration ID out-of-range for AST file"); |
| 7104 | Error("declaration ID out-of-range for AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7105 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7106 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7107 | |
| 7108 | return DeclsLoaded[Index]; |
| 7109 | } |
| 7110 | |
| 7111 | Decl *ASTReader::GetDecl(DeclID ID) { |
| 7112 | if (ID < NUM_PREDEF_DECL_IDS) |
| 7113 | return GetExistingDecl(ID); |
| 7114 | |
| 7115 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 7116 | |
| 7117 | if (Index >= DeclsLoaded.size()) { |
| 7118 | assert(0 && "declaration ID out-of-range for AST file"); |
| 7119 | Error("declaration ID out-of-range for AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7120 | return nullptr; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7121 | } |
| 7122 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7123 | if (!DeclsLoaded[Index]) { |
| 7124 | ReadDeclRecord(ID); |
| 7125 | if (DeserializationListener) |
| 7126 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 7127 | } |
| 7128 | |
| 7129 | return DeclsLoaded[Index]; |
| 7130 | } |
| 7131 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7132 | DeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile &M, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7133 | DeclID GlobalID) { |
| 7134 | if (GlobalID < NUM_PREDEF_DECL_IDS) |
| 7135 | return GlobalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7136 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7137 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID); |
| 7138 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 7139 | ModuleFile *Owner = I->second; |
| 7140 | |
| 7141 | llvm::DenseMap<ModuleFile *, serialization::DeclID>::iterator Pos |
| 7142 | = M.GlobalToLocalDeclIDs.find(Owner); |
| 7143 | if (Pos == M.GlobalToLocalDeclIDs.end()) |
| 7144 | return 0; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7145 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7146 | return GlobalID - Owner->BaseDeclID + Pos->second; |
| 7147 | } |
| 7148 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7149 | serialization::DeclID ASTReader::ReadDeclID(ModuleFile &F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7150 | const RecordData &Record, |
| 7151 | unsigned &Idx) { |
| 7152 | if (Idx >= Record.size()) { |
| 7153 | Error("Corrupted AST file"); |
| 7154 | return 0; |
| 7155 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7156 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7157 | return getGlobalDeclID(F, Record[Idx++]); |
| 7158 | } |
| 7159 | |
| 7160 | /// \brief Resolve the offset of a statement into a statement. |
| 7161 | /// |
| 7162 | /// This operation will read a new statement from the external |
| 7163 | /// source each time it is called, and is meant to be used via a |
| 7164 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
| 7165 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
| 7166 | // Switch case IDs are per Decl. |
| 7167 | ClearSwitchCaseIDs(); |
| 7168 | |
| 7169 | // Offset here is a global offset across the entire chain. |
| 7170 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 7171 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
David Blaikie | 9fd16f8 | 2017-03-08 23:57:08 +0000 | [diff] [blame] | 7172 | assert(NumCurrentElementsDeserializing == 0 && |
| 7173 | "should not be called while already deserializing"); |
| 7174 | Deserializing D(this); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7175 | return ReadStmtFromStream(*Loc.F); |
| 7176 | } |
| 7177 | |
Richard Smith | 3cb1572 | 2015-08-05 22:41:45 +0000 | [diff] [blame] | 7178 | void ASTReader::FindExternalLexicalDecls( |
| 7179 | const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, |
| 7180 | SmallVectorImpl<Decl *> &Decls) { |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7181 | bool PredefsVisited[NUM_PREDEF_DECL_IDS] = {}; |
| 7182 | |
Richard Smith | 9ccdd93 | 2015-08-06 22:14:12 +0000 | [diff] [blame] | 7183 | auto Visit = [&] (ModuleFile *M, LexicalContents LexicalDecls) { |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7184 | assert(LexicalDecls.size() % 2 == 0 && "expected an even number of entries"); |
| 7185 | for (int I = 0, N = LexicalDecls.size(); I != N; I += 2) { |
| 7186 | auto K = (Decl::Kind)+LexicalDecls[I]; |
| 7187 | if (!IsKindWeWant(K)) |
| 7188 | continue; |
| 7189 | |
| 7190 | auto ID = (serialization::DeclID)+LexicalDecls[I + 1]; |
| 7191 | |
| 7192 | // Don't add predefined declarations to the lexical context more |
| 7193 | // than once. |
| 7194 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 7195 | if (PredefsVisited[ID]) |
| 7196 | continue; |
| 7197 | |
| 7198 | PredefsVisited[ID] = true; |
| 7199 | } |
| 7200 | |
| 7201 | if (Decl *D = GetLocalDecl(*M, ID)) { |
Richard Smith | 2317a3e | 2015-08-11 21:21:20 +0000 | [diff] [blame] | 7202 | assert(D->getKind() == K && "wrong kind for lexical decl"); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7203 | if (!DC->isDeclInLexicalTraversal(D)) |
| 7204 | Decls.push_back(D); |
| 7205 | } |
| 7206 | } |
| 7207 | }; |
| 7208 | |
| 7209 | if (isa<TranslationUnitDecl>(DC)) { |
| 7210 | for (auto Lexical : TULexicalDecls) |
| 7211 | Visit(Lexical.first, Lexical.second); |
| 7212 | } else { |
| 7213 | auto I = LexicalDecls.find(DC); |
| 7214 | if (I != LexicalDecls.end()) |
Richard Smith | 9c9173d | 2015-08-11 22:00:24 +0000 | [diff] [blame] | 7215 | Visit(I->second.first, I->second.second); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7216 | } |
| 7217 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7218 | ++NumLexicalDeclContextsRead; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7219 | } |
| 7220 | |
| 7221 | namespace { |
| 7222 | |
| 7223 | class DeclIDComp { |
| 7224 | ASTReader &Reader; |
| 7225 | ModuleFile &Mod; |
| 7226 | |
| 7227 | public: |
| 7228 | DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {} |
| 7229 | |
| 7230 | bool operator()(LocalDeclID L, LocalDeclID R) const { |
| 7231 | SourceLocation LHS = getLocation(L); |
| 7232 | SourceLocation RHS = getLocation(R); |
| 7233 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7234 | } |
| 7235 | |
| 7236 | bool operator()(SourceLocation LHS, LocalDeclID R) const { |
| 7237 | SourceLocation RHS = getLocation(R); |
| 7238 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7239 | } |
| 7240 | |
| 7241 | bool operator()(LocalDeclID L, SourceLocation RHS) const { |
| 7242 | SourceLocation LHS = getLocation(L); |
| 7243 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7244 | } |
| 7245 | |
| 7246 | SourceLocation getLocation(LocalDeclID ID) const { |
| 7247 | return Reader.getSourceManager().getFileLoc( |
| 7248 | Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID))); |
| 7249 | } |
| 7250 | }; |
| 7251 | |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7252 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7253 | |
| 7254 | void ASTReader::FindFileRegionDecls(FileID File, |
| 7255 | unsigned Offset, unsigned Length, |
| 7256 | SmallVectorImpl<Decl *> &Decls) { |
| 7257 | SourceManager &SM = getSourceManager(); |
| 7258 | |
| 7259 | llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File); |
| 7260 | if (I == FileDeclIDs.end()) |
| 7261 | return; |
| 7262 | |
| 7263 | FileDeclsInfo &DInfo = I->second; |
| 7264 | if (DInfo.Decls.empty()) |
| 7265 | return; |
| 7266 | |
| 7267 | SourceLocation |
| 7268 | BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset); |
| 7269 | SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length); |
| 7270 | |
| 7271 | DeclIDComp DIDComp(*this, *DInfo.Mod); |
| 7272 | ArrayRef<serialization::LocalDeclID>::iterator |
| 7273 | BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 7274 | BeginLoc, DIDComp); |
| 7275 | if (BeginIt != DInfo.Decls.begin()) |
| 7276 | --BeginIt; |
| 7277 | |
| 7278 | // If we are pointing at a top-level decl inside an objc container, we need |
| 7279 | // to backtrack until we find it otherwise we will fail to report that the |
| 7280 | // region overlaps with an objc container. |
| 7281 | while (BeginIt != DInfo.Decls.begin() && |
| 7282 | GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt)) |
| 7283 | ->isTopLevelDeclInObjCContainer()) |
| 7284 | --BeginIt; |
| 7285 | |
| 7286 | ArrayRef<serialization::LocalDeclID>::iterator |
| 7287 | EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 7288 | EndLoc, DIDComp); |
| 7289 | if (EndIt != DInfo.Decls.end()) |
| 7290 | ++EndIt; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7291 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7292 | for (ArrayRef<serialization::LocalDeclID>::iterator |
| 7293 | DIt = BeginIt; DIt != EndIt; ++DIt) |
| 7294 | Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt))); |
| 7295 | } |
| 7296 | |
Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 7297 | bool |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7298 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
| 7299 | DeclarationName Name) { |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7300 | assert(DC->hasExternalVisibleStorage() && DC == DC->getPrimaryContext() && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7301 | "DeclContext has no visible decls in storage"); |
| 7302 | if (!Name) |
Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 7303 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7304 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7305 | auto It = Lookups.find(DC); |
| 7306 | if (It == Lookups.end()) |
| 7307 | return false; |
| 7308 | |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 7309 | Deserializing LookupResults(this); |
| 7310 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7311 | // Load the list of declarations. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7312 | SmallVector<NamedDecl *, 64> Decls; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7313 | for (DeclID ID : It->second.Table.find(Name)) { |
| 7314 | NamedDecl *ND = cast<NamedDecl>(GetDecl(ID)); |
| 7315 | if (ND->getDeclName() == Name) |
| 7316 | Decls.push_back(ND); |
| 7317 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7318 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7319 | ++NumVisibleDeclContextsRead; |
| 7320 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 7321 | return !Decls.empty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7322 | } |
| 7323 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7324 | void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) { |
| 7325 | if (!DC->hasExternalVisibleStorage()) |
| 7326 | return; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7327 | |
| 7328 | auto It = Lookups.find(DC); |
| 7329 | assert(It != Lookups.end() && |
| 7330 | "have external visible storage but no lookup tables"); |
| 7331 | |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 7332 | DeclsMap Decls; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7333 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7334 | for (DeclID ID : It->second.Table.findAll()) { |
| 7335 | NamedDecl *ND = cast<NamedDecl>(GetDecl(ID)); |
| 7336 | Decls[ND->getDeclName()].push_back(ND); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7337 | } |
| 7338 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7339 | ++NumVisibleDeclContextsRead; |
| 7340 | |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 7341 | for (DeclsMap::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7342 | SetExternalVisibleDeclsForName(DC, I->first, I->second); |
| 7343 | } |
| 7344 | const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false); |
| 7345 | } |
| 7346 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7347 | const serialization::reader::DeclContextLookupTable * |
| 7348 | ASTReader::getLoadedLookupTables(DeclContext *Primary) const { |
| 7349 | auto I = Lookups.find(Primary); |
| 7350 | return I == Lookups.end() ? nullptr : &I->second; |
| 7351 | } |
| 7352 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7353 | /// \brief Under non-PCH compilation the consumer receives the objc methods |
| 7354 | /// before receiving the implementation, and codegen depends on this. |
| 7355 | /// We simulate this by deserializing and passing to consumer the methods of the |
| 7356 | /// implementation before passing the deserialized implementation decl. |
| 7357 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 7358 | ASTConsumer *Consumer) { |
| 7359 | assert(ImplD && Consumer); |
| 7360 | |
Aaron Ballman | aff18c0 | 2014-03-13 19:03:34 +0000 | [diff] [blame] | 7361 | for (auto *I : ImplD->methods()) |
| 7362 | Consumer->HandleInterestingDecl(DeclGroupRef(I)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7363 | |
| 7364 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 7365 | } |
| 7366 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7367 | void ASTReader::PassInterestingDeclToConsumer(Decl *D) { |
| 7368 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 7369 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 7370 | else |
| 7371 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
| 7372 | } |
| 7373 | |
| 7374 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
| 7375 | this->Consumer = Consumer; |
| 7376 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 7377 | if (Consumer) |
| 7378 | PassInterestingDeclsToConsumer(); |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 7379 | |
| 7380 | if (DeserializationListener) |
| 7381 | DeserializationListener->ReaderInitialized(this); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7382 | } |
| 7383 | |
| 7384 | void ASTReader::PrintStats() { |
| 7385 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
| 7386 | |
| 7387 | unsigned NumTypesLoaded |
| 7388 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
| 7389 | QualType()); |
| 7390 | unsigned NumDeclsLoaded |
| 7391 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7392 | (Decl *)nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7393 | unsigned NumIdentifiersLoaded |
| 7394 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 7395 | IdentifiersLoaded.end(), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7396 | (IdentifierInfo *)nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7397 | unsigned NumMacrosLoaded |
| 7398 | = MacrosLoaded.size() - std::count(MacrosLoaded.begin(), |
| 7399 | MacrosLoaded.end(), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7400 | (MacroInfo *)nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7401 | unsigned NumSelectorsLoaded |
| 7402 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 7403 | SelectorsLoaded.end(), |
| 7404 | Selector()); |
| 7405 | |
| 7406 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
| 7407 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 7408 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 7409 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
| 7410 | if (!TypesLoaded.empty()) |
| 7411 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
| 7412 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 7413 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 7414 | if (!DeclsLoaded.empty()) |
| 7415 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
| 7416 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 7417 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
| 7418 | if (!IdentifiersLoaded.empty()) |
| 7419 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
| 7420 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 7421 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
| 7422 | if (!MacrosLoaded.empty()) |
| 7423 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 7424 | NumMacrosLoaded, (unsigned)MacrosLoaded.size(), |
| 7425 | ((float)NumMacrosLoaded/MacrosLoaded.size() * 100)); |
| 7426 | if (!SelectorsLoaded.empty()) |
| 7427 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
| 7428 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 7429 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
| 7430 | if (TotalNumStatements) |
| 7431 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 7432 | NumStatementsRead, TotalNumStatements, |
| 7433 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 7434 | if (TotalNumMacros) |
| 7435 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 7436 | NumMacrosRead, TotalNumMacros, |
| 7437 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 7438 | if (TotalLexicalDeclContexts) |
| 7439 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 7440 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 7441 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 7442 | * 100)); |
| 7443 | if (TotalVisibleDeclContexts) |
| 7444 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 7445 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 7446 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 7447 | * 100)); |
| 7448 | if (TotalNumMethodPoolEntries) { |
| 7449 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
| 7450 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 7451 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
| 7452 | * 100)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7453 | } |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7454 | if (NumMethodPoolLookups) { |
| 7455 | std::fprintf(stderr, " %u/%u method pool lookups succeeded (%f%%)\n", |
| 7456 | NumMethodPoolHits, NumMethodPoolLookups, |
| 7457 | ((float)NumMethodPoolHits/NumMethodPoolLookups * 100.0)); |
| 7458 | } |
| 7459 | if (NumMethodPoolTableLookups) { |
| 7460 | std::fprintf(stderr, " %u/%u method pool table lookups succeeded (%f%%)\n", |
| 7461 | NumMethodPoolTableHits, NumMethodPoolTableLookups, |
| 7462 | ((float)NumMethodPoolTableHits/NumMethodPoolTableLookups |
| 7463 | * 100.0)); |
| 7464 | } |
| 7465 | |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 7466 | if (NumIdentifierLookupHits) { |
| 7467 | std::fprintf(stderr, |
| 7468 | " %u / %u identifier table lookups succeeded (%f%%)\n", |
| 7469 | NumIdentifierLookupHits, NumIdentifierLookups, |
| 7470 | (double)NumIdentifierLookupHits*100.0/NumIdentifierLookups); |
| 7471 | } |
| 7472 | |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 7473 | if (GlobalIndex) { |
| 7474 | std::fprintf(stderr, "\n"); |
| 7475 | GlobalIndex->printStats(); |
| 7476 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7477 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7478 | std::fprintf(stderr, "\n"); |
| 7479 | dump(); |
| 7480 | std::fprintf(stderr, "\n"); |
| 7481 | } |
| 7482 | |
| 7483 | template<typename Key, typename ModuleFile, unsigned InitialCapacity> |
Vassil Vassilev | b271068 | 2017-03-02 18:13:19 +0000 | [diff] [blame] | 7484 | LLVM_DUMP_METHOD static void |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7485 | dumpModuleIDMap(StringRef Name, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7486 | const ContinuousRangeMap<Key, ModuleFile *, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7487 | InitialCapacity> &Map) { |
| 7488 | if (Map.begin() == Map.end()) |
| 7489 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7490 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7491 | typedef ContinuousRangeMap<Key, ModuleFile *, InitialCapacity> MapType; |
| 7492 | llvm::errs() << Name << ":\n"; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7493 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7494 | I != IEnd; ++I) { |
| 7495 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 7496 | << "\n"; |
| 7497 | } |
| 7498 | } |
| 7499 | |
Yaron Keren | cdae941 | 2016-01-29 19:38:18 +0000 | [diff] [blame] | 7500 | LLVM_DUMP_METHOD void ASTReader::dump() { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7501 | llvm::errs() << "*** PCH/ModuleFile Remappings:\n"; |
| 7502 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
| 7503 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
| 7504 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
| 7505 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
| 7506 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
| 7507 | dumpModuleIDMap("Global macro map", GlobalMacroMap); |
| 7508 | dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap); |
| 7509 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7510 | dumpModuleIDMap("Global preprocessed entity map", |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7511 | GlobalPreprocessedEntityMap); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7512 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7513 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 7514 | for (ModuleFile &M : ModuleMgr) |
| 7515 | M.dump(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7516 | } |
| 7517 | |
| 7518 | /// Return the amount of memory used by memory buffers, breaking down |
| 7519 | /// by heap-backed versus mmap'ed memory. |
| 7520 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 7521 | for (ModuleFile &I : ModuleMgr) { |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 7522 | if (llvm::MemoryBuffer *buf = I.Buffer) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7523 | size_t bytes = buf->getBufferSize(); |
| 7524 | switch (buf->getBufferKind()) { |
| 7525 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 7526 | sizes.malloc_bytes += bytes; |
| 7527 | break; |
| 7528 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 7529 | sizes.mmap_bytes += bytes; |
| 7530 | break; |
| 7531 | } |
| 7532 | } |
| 7533 | } |
| 7534 | } |
| 7535 | |
| 7536 | void ASTReader::InitializeSema(Sema &S) { |
| 7537 | SemaObj = &S; |
| 7538 | S.addExternalSource(this); |
| 7539 | |
| 7540 | // Makes sure any declarations that were deserialized "too early" |
| 7541 | // still get added to the identifier's declaration chains. |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7542 | for (uint64_t ID : PreloadedDeclIDs) { |
| 7543 | NamedDecl *D = cast<NamedDecl>(GetDecl(ID)); |
| 7544 | pushExternalDeclIntoScope(D, D->getDeclName()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7545 | } |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7546 | PreloadedDeclIDs.clear(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7547 | |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7548 | // FIXME: What happens if these are changed by a module import? |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7549 | if (!FPPragmaOptions.empty()) { |
| 7550 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 7551 | SemaObj->FPFeatures = FPOptions(FPPragmaOptions[0]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7552 | } |
| 7553 | |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 7554 | SemaObj->OpenCLFeatures.copy(OpenCLExtensions); |
| 7555 | SemaObj->OpenCLTypeExtMap = OpenCLTypeExtMap; |
| 7556 | SemaObj->OpenCLDeclExtMap = OpenCLDeclExtMap; |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7557 | |
| 7558 | UpdateSema(); |
| 7559 | } |
| 7560 | |
| 7561 | void ASTReader::UpdateSema() { |
| 7562 | assert(SemaObj && "no Sema to update"); |
| 7563 | |
| 7564 | // Load the offsets of the declarations that Sema references. |
| 7565 | // They will be lazily deserialized when needed. |
| 7566 | if (!SemaDeclRefs.empty()) { |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 7567 | assert(SemaDeclRefs.size() % 3 == 0); |
| 7568 | for (unsigned I = 0; I != SemaDeclRefs.size(); I += 3) { |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7569 | if (!SemaObj->StdNamespace) |
| 7570 | SemaObj->StdNamespace = SemaDeclRefs[I]; |
| 7571 | if (!SemaObj->StdBadAlloc) |
| 7572 | SemaObj->StdBadAlloc = SemaDeclRefs[I+1]; |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 7573 | if (!SemaObj->StdAlignValT) |
| 7574 | SemaObj->StdAlignValT = SemaDeclRefs[I+2]; |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7575 | } |
| 7576 | SemaDeclRefs.clear(); |
| 7577 | } |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 7578 | |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 7579 | // Update the state of pragmas. Use the same API as if we had encountered the |
| 7580 | // pragma in the source. |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 7581 | if(OptimizeOffPragmaLocation.isValid()) |
| 7582 | SemaObj->ActOnPragmaOptimize(/* IsOn = */ false, OptimizeOffPragmaLocation); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 7583 | if (PragmaMSStructState != -1) |
| 7584 | SemaObj->ActOnPragmaMSStruct((PragmaMSStructKind)PragmaMSStructState); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 7585 | if (PointersToMembersPragmaLocation.isValid()) { |
| 7586 | SemaObj->ActOnPragmaMSPointersToMembers( |
| 7587 | (LangOptions::PragmaMSPointersToMembersKind) |
| 7588 | PragmaMSPointersToMembersState, |
| 7589 | PointersToMembersPragmaLocation); |
| 7590 | } |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 7591 | SemaObj->ForceCUDAHostDeviceDepth = ForceCUDAHostDeviceDepth; |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 7592 | |
| 7593 | if (PragmaPackCurrentValue) { |
| 7594 | // The bottom of the stack might have a default value. It must be adjusted |
| 7595 | // to the current value to ensure that the packing state is preserved after |
| 7596 | // popping entries that were included/imported from a PCH/module. |
| 7597 | bool DropFirst = false; |
| 7598 | if (!PragmaPackStack.empty() && |
| 7599 | PragmaPackStack.front().Location.isInvalid()) { |
| 7600 | assert(PragmaPackStack.front().Value == SemaObj->PackStack.DefaultValue && |
| 7601 | "Expected a default alignment value"); |
| 7602 | SemaObj->PackStack.Stack.emplace_back( |
| 7603 | PragmaPackStack.front().SlotLabel, SemaObj->PackStack.CurrentValue, |
Alex Lorenz | 45b4014 | 2017-07-28 14:41:21 +0000 | [diff] [blame] | 7604 | SemaObj->PackStack.CurrentPragmaLocation, |
| 7605 | PragmaPackStack.front().PushLocation); |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 7606 | DropFirst = true; |
| 7607 | } |
| 7608 | for (const auto &Entry : |
| 7609 | llvm::makeArrayRef(PragmaPackStack).drop_front(DropFirst ? 1 : 0)) |
| 7610 | SemaObj->PackStack.Stack.emplace_back(Entry.SlotLabel, Entry.Value, |
Alex Lorenz | 45b4014 | 2017-07-28 14:41:21 +0000 | [diff] [blame] | 7611 | Entry.Location, Entry.PushLocation); |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 7612 | if (PragmaPackCurrentLocation.isInvalid()) { |
| 7613 | assert(*PragmaPackCurrentValue == SemaObj->PackStack.DefaultValue && |
| 7614 | "Expected a default alignment value"); |
| 7615 | // Keep the current values. |
| 7616 | } else { |
| 7617 | SemaObj->PackStack.CurrentValue = *PragmaPackCurrentValue; |
| 7618 | SemaObj->PackStack.CurrentPragmaLocation = PragmaPackCurrentLocation; |
| 7619 | } |
| 7620 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7621 | } |
| 7622 | |
Richard Smith | a8d5b6a | 2015-07-17 19:51:03 +0000 | [diff] [blame] | 7623 | IdentifierInfo *ASTReader::get(StringRef Name) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7624 | // Note that we are loading an identifier. |
| 7625 | Deserializing AnIdentifier(this); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 7626 | |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 7627 | IdentifierLookupVisitor Visitor(Name, /*PriorGeneration=*/0, |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 7628 | NumIdentifierLookups, |
| 7629 | NumIdentifierLookupHits); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7630 | |
| 7631 | // We don't need to do identifier table lookups in C++ modules (we preload |
| 7632 | // all interesting declarations, and don't need to use the scope for name |
| 7633 | // lookups). Perform the lookup in PCH files, though, since we don't build |
| 7634 | // a complete initial identifier table if we're carrying on from a PCH. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 7635 | if (PP.getLangOpts().CPlusPlus) { |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7636 | for (auto F : ModuleMgr.pch_modules()) |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7637 | if (Visitor(*F)) |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7638 | break; |
| 7639 | } else { |
| 7640 | // If there is a global index, look there first to determine which modules |
| 7641 | // provably do not have any results for this identifier. |
| 7642 | GlobalModuleIndex::HitSet Hits; |
| 7643 | GlobalModuleIndex::HitSet *HitsPtr = nullptr; |
| 7644 | if (!loadGlobalIndex()) { |
| 7645 | if (GlobalIndex->lookupIdentifier(Name, Hits)) { |
| 7646 | HitsPtr = &Hits; |
| 7647 | } |
| 7648 | } |
| 7649 | |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7650 | ModuleMgr.visit(Visitor, HitsPtr); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7651 | } |
| 7652 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7653 | IdentifierInfo *II = Visitor.getIdentifierInfo(); |
| 7654 | markIdentifierUpToDate(II); |
| 7655 | return II; |
| 7656 | } |
| 7657 | |
| 7658 | namespace clang { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7659 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7660 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 7661 | /// identifiers stored within a set of AST files. |
| 7662 | class ASTIdentifierIterator : public IdentifierIterator { |
| 7663 | /// \brief The AST reader whose identifiers are being enumerated. |
| 7664 | const ASTReader &Reader; |
| 7665 | |
| 7666 | /// \brief The current index into the chain of AST files stored in |
| 7667 | /// the AST reader. |
| 7668 | unsigned Index; |
| 7669 | |
| 7670 | /// \brief The current position within the identifier lookup table |
| 7671 | /// of the current AST file. |
| 7672 | ASTIdentifierLookupTable::key_iterator Current; |
| 7673 | |
| 7674 | /// \brief The end position within the identifier lookup table of |
| 7675 | /// the current AST file. |
| 7676 | ASTIdentifierLookupTable::key_iterator End; |
| 7677 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7678 | /// \brief Whether to skip any modules in the ASTReader. |
| 7679 | bool SkipModules; |
| 7680 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7681 | public: |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7682 | explicit ASTIdentifierIterator(const ASTReader &Reader, |
| 7683 | bool SkipModules = false); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7684 | |
Craig Topper | 3e89dfe | 2014-03-13 02:13:41 +0000 | [diff] [blame] | 7685 | StringRef Next() override; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7686 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7687 | |
| 7688 | } // end namespace clang |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7689 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7690 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader, |
| 7691 | bool SkipModules) |
| 7692 | : Reader(Reader), Index(Reader.ModuleMgr.size()), SkipModules(SkipModules) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7693 | } |
| 7694 | |
| 7695 | StringRef ASTIdentifierIterator::Next() { |
| 7696 | while (Current == End) { |
| 7697 | // If we have exhausted all of our AST files, we're done. |
| 7698 | if (Index == 0) |
| 7699 | return StringRef(); |
| 7700 | |
| 7701 | --Index; |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7702 | ModuleFile &F = Reader.ModuleMgr[Index]; |
| 7703 | if (SkipModules && F.isModule()) |
| 7704 | continue; |
| 7705 | |
| 7706 | ASTIdentifierLookupTable *IdTable = |
| 7707 | (ASTIdentifierLookupTable *)F.IdentifierLookupTable; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7708 | Current = IdTable->key_begin(); |
| 7709 | End = IdTable->key_end(); |
| 7710 | } |
| 7711 | |
| 7712 | // We have any identifiers remaining in the current AST file; return |
| 7713 | // the next one. |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 7714 | StringRef Result = *Current; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7715 | ++Current; |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 7716 | return Result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7717 | } |
| 7718 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7719 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7720 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7721 | /// A utility for appending two IdentifierIterators. |
| 7722 | class ChainedIdentifierIterator : public IdentifierIterator { |
| 7723 | std::unique_ptr<IdentifierIterator> Current; |
| 7724 | std::unique_ptr<IdentifierIterator> Queued; |
| 7725 | |
| 7726 | public: |
| 7727 | ChainedIdentifierIterator(std::unique_ptr<IdentifierIterator> First, |
| 7728 | std::unique_ptr<IdentifierIterator> Second) |
| 7729 | : Current(std::move(First)), Queued(std::move(Second)) {} |
| 7730 | |
| 7731 | StringRef Next() override { |
| 7732 | if (!Current) |
| 7733 | return StringRef(); |
| 7734 | |
| 7735 | StringRef result = Current->Next(); |
| 7736 | if (!result.empty()) |
| 7737 | return result; |
| 7738 | |
| 7739 | // Try the queued iterator, which may itself be empty. |
| 7740 | Current.reset(); |
| 7741 | std::swap(Current, Queued); |
| 7742 | return Next(); |
| 7743 | } |
| 7744 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7745 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7746 | } // end anonymous namespace. |
| 7747 | |
Argyrios Kyrtzidis | 9aca3c6 | 2013-04-17 22:10:55 +0000 | [diff] [blame] | 7748 | IdentifierIterator *ASTReader::getIdentifiers() { |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7749 | if (!loadGlobalIndex()) { |
| 7750 | std::unique_ptr<IdentifierIterator> ReaderIter( |
| 7751 | new ASTIdentifierIterator(*this, /*SkipModules=*/true)); |
| 7752 | std::unique_ptr<IdentifierIterator> ModulesIter( |
| 7753 | GlobalIndex->createIdentifierIterator()); |
| 7754 | return new ChainedIdentifierIterator(std::move(ReaderIter), |
| 7755 | std::move(ModulesIter)); |
| 7756 | } |
Argyrios Kyrtzidis | 9aca3c6 | 2013-04-17 22:10:55 +0000 | [diff] [blame] | 7757 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7758 | return new ASTIdentifierIterator(*this); |
| 7759 | } |
| 7760 | |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7761 | namespace clang { |
| 7762 | namespace serialization { |
| 7763 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7764 | class ReadMethodPoolVisitor { |
| 7765 | ASTReader &Reader; |
| 7766 | Selector Sel; |
| 7767 | unsigned PriorGeneration; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7768 | unsigned InstanceBits; |
| 7769 | unsigned FactoryBits; |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7770 | bool InstanceHasMoreThanOneDecl; |
| 7771 | bool FactoryHasMoreThanOneDecl; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 7772 | SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 7773 | SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7774 | |
| 7775 | public: |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 7776 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7777 | unsigned PriorGeneration) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 7778 | : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration), |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7779 | InstanceBits(0), FactoryBits(0), InstanceHasMoreThanOneDecl(false), |
| 7780 | FactoryHasMoreThanOneDecl(false) {} |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 7781 | |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7782 | bool operator()(ModuleFile &M) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7783 | if (!M.SelectorLookupTable) |
| 7784 | return false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7785 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7786 | // If we've already searched this module file, skip it now. |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7787 | if (M.Generation <= PriorGeneration) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7788 | return true; |
| 7789 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7790 | ++Reader.NumMethodPoolTableLookups; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7791 | ASTSelectorLookupTable *PoolTable |
| 7792 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7793 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7794 | if (Pos == PoolTable->end()) |
| 7795 | return false; |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7796 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7797 | ++Reader.NumMethodPoolTableHits; |
| 7798 | ++Reader.NumSelectorsRead; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7799 | // FIXME: Not quite happy with the statistics here. We probably should |
| 7800 | // disable this tracking when called via LoadSelector. |
| 7801 | // Also, should entries without methods count as misses? |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7802 | ++Reader.NumMethodPoolEntriesRead; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7803 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7804 | if (Reader.DeserializationListener) |
| 7805 | Reader.DeserializationListener->SelectorRead(Data.ID, Sel); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7806 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7807 | InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 7808 | FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 7809 | InstanceBits = Data.InstanceBits; |
| 7810 | FactoryBits = Data.FactoryBits; |
| 7811 | InstanceHasMoreThanOneDecl = Data.InstanceHasMoreThanOneDecl; |
| 7812 | FactoryHasMoreThanOneDecl = Data.FactoryHasMoreThanOneDecl; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7813 | return true; |
| 7814 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7815 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7816 | /// \brief Retrieve the instance methods found by this visitor. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7817 | ArrayRef<ObjCMethodDecl *> getInstanceMethods() const { |
| 7818 | return InstanceMethods; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7819 | } |
| 7820 | |
| 7821 | /// \brief Retrieve the instance methods found by this visitor. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7822 | ArrayRef<ObjCMethodDecl *> getFactoryMethods() const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7823 | return FactoryMethods; |
| 7824 | } |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7825 | |
| 7826 | unsigned getInstanceBits() const { return InstanceBits; } |
| 7827 | unsigned getFactoryBits() const { return FactoryBits; } |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7828 | bool instanceHasMoreThanOneDecl() const { |
| 7829 | return InstanceHasMoreThanOneDecl; |
| 7830 | } |
| 7831 | bool factoryHasMoreThanOneDecl() const { return FactoryHasMoreThanOneDecl; } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7832 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7833 | |
| 7834 | } // end namespace serialization |
| 7835 | } // end namespace clang |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7836 | |
| 7837 | /// \brief Add the given set of methods to the method list. |
| 7838 | static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods, |
| 7839 | ObjCMethodList &List) { |
| 7840 | for (unsigned I = 0, N = Methods.size(); I != N; ++I) { |
| 7841 | S.addMethodToGlobalList(&List, Methods[I]); |
| 7842 | } |
| 7843 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7844 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7845 | void ASTReader::ReadMethodPool(Selector Sel) { |
| 7846 | // Get the selector generation and update it to the current generation. |
| 7847 | unsigned &Generation = SelectorGeneration[Sel]; |
| 7848 | unsigned PriorGeneration = Generation; |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 7849 | Generation = getGeneration(); |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 7850 | SelectorOutOfDate[Sel] = false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7851 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7852 | // Search for methods defined with this selector. |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7853 | ++NumMethodPoolLookups; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7854 | ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7855 | ModuleMgr.visit(Visitor); |
| 7856 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7857 | if (Visitor.getInstanceMethods().empty() && |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7858 | Visitor.getFactoryMethods().empty()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7859 | return; |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7860 | |
| 7861 | ++NumMethodPoolHits; |
| 7862 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7863 | if (!getSema()) |
| 7864 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7865 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7866 | Sema &S = *getSema(); |
| 7867 | Sema::GlobalMethodPool::iterator Pos |
| 7868 | = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first; |
Ben Langmuir | a0c32e9 | 2015-01-12 19:27:00 +0000 | [diff] [blame] | 7869 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7870 | Pos->second.first.setBits(Visitor.getInstanceBits()); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7871 | Pos->second.first.setHasMoreThanOneDecl(Visitor.instanceHasMoreThanOneDecl()); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7872 | Pos->second.second.setBits(Visitor.getFactoryBits()); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7873 | Pos->second.second.setHasMoreThanOneDecl(Visitor.factoryHasMoreThanOneDecl()); |
Ben Langmuir | a0c32e9 | 2015-01-12 19:27:00 +0000 | [diff] [blame] | 7874 | |
| 7875 | // Add methods to the global pool *after* setting hasMoreThanOneDecl, since |
| 7876 | // when building a module we keep every method individually and may need to |
| 7877 | // update hasMoreThanOneDecl as we add the methods. |
| 7878 | addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first); |
| 7879 | addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7880 | } |
| 7881 | |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 7882 | void ASTReader::updateOutOfDateSelector(Selector Sel) { |
| 7883 | if (SelectorOutOfDate[Sel]) |
| 7884 | ReadMethodPool(Sel); |
| 7885 | } |
| 7886 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7887 | void ASTReader::ReadKnownNamespaces( |
| 7888 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
| 7889 | Namespaces.clear(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7890 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7891 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7892 | if (NamespaceDecl *Namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7893 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 7894 | Namespaces.push_back(Namespace); |
| 7895 | } |
| 7896 | } |
| 7897 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 7898 | void ASTReader::ReadUndefinedButUsed( |
Richard Smith | d6a04d7 | 2016-03-25 21:49:43 +0000 | [diff] [blame] | 7899 | llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 7900 | for (unsigned Idx = 0, N = UndefinedButUsed.size(); Idx != N;) { |
| 7901 | NamedDecl *D = cast<NamedDecl>(GetDecl(UndefinedButUsed[Idx++])); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 7902 | SourceLocation Loc = |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 7903 | SourceLocation::getFromRawEncoding(UndefinedButUsed[Idx++]); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 7904 | Undefined.insert(std::make_pair(D, Loc)); |
| 7905 | } |
| 7906 | } |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 7907 | |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 7908 | void ASTReader::ReadMismatchingDeleteExpressions(llvm::MapVector< |
| 7909 | FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> & |
| 7910 | Exprs) { |
| 7911 | for (unsigned Idx = 0, N = DelayedDeleteExprs.size(); Idx != N;) { |
| 7912 | FieldDecl *FD = cast<FieldDecl>(GetDecl(DelayedDeleteExprs[Idx++])); |
| 7913 | uint64_t Count = DelayedDeleteExprs[Idx++]; |
| 7914 | for (uint64_t C = 0; C < Count; ++C) { |
| 7915 | SourceLocation DeleteLoc = |
| 7916 | SourceLocation::getFromRawEncoding(DelayedDeleteExprs[Idx++]); |
| 7917 | const bool IsArrayForm = DelayedDeleteExprs[Idx++]; |
| 7918 | Exprs[FD].push_back(std::make_pair(DeleteLoc, IsArrayForm)); |
| 7919 | } |
| 7920 | } |
| 7921 | } |
| 7922 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7923 | void ASTReader::ReadTentativeDefinitions( |
| 7924 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 7925 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 7926 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 7927 | if (Var) |
| 7928 | TentativeDefs.push_back(Var); |
| 7929 | } |
| 7930 | TentativeDefinitions.clear(); |
| 7931 | } |
| 7932 | |
| 7933 | void ASTReader::ReadUnusedFileScopedDecls( |
| 7934 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 7935 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 7936 | DeclaratorDecl *D |
| 7937 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 7938 | if (D) |
| 7939 | Decls.push_back(D); |
| 7940 | } |
| 7941 | UnusedFileScopedDecls.clear(); |
| 7942 | } |
| 7943 | |
| 7944 | void ASTReader::ReadDelegatingConstructors( |
| 7945 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 7946 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 7947 | CXXConstructorDecl *D |
| 7948 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 7949 | if (D) |
| 7950 | Decls.push_back(D); |
| 7951 | } |
| 7952 | DelegatingCtorDecls.clear(); |
| 7953 | } |
| 7954 | |
| 7955 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 7956 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 7957 | TypedefNameDecl *D |
| 7958 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 7959 | if (D) |
| 7960 | Decls.push_back(D); |
| 7961 | } |
| 7962 | ExtVectorDecls.clear(); |
| 7963 | } |
| 7964 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 7965 | void ASTReader::ReadUnusedLocalTypedefNameCandidates( |
| 7966 | llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) { |
| 7967 | for (unsigned I = 0, N = UnusedLocalTypedefNameCandidates.size(); I != N; |
| 7968 | ++I) { |
| 7969 | TypedefNameDecl *D = dyn_cast_or_null<TypedefNameDecl>( |
| 7970 | GetDecl(UnusedLocalTypedefNameCandidates[I])); |
| 7971 | if (D) |
| 7972 | Decls.insert(D); |
| 7973 | } |
| 7974 | UnusedLocalTypedefNameCandidates.clear(); |
| 7975 | } |
| 7976 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7977 | void ASTReader::ReadReferencedSelectors( |
| 7978 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 7979 | if (ReferencedSelectorsData.empty()) |
| 7980 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7981 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7982 | // If there are @selector references added them to its pool. This is for |
| 7983 | // implementation of -Wselector. |
| 7984 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 7985 | unsigned I = 0; |
| 7986 | while (I < DataSize) { |
| 7987 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 7988 | SourceLocation SelLoc |
| 7989 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 7990 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 7991 | } |
| 7992 | ReferencedSelectorsData.clear(); |
| 7993 | } |
| 7994 | |
| 7995 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 7996 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 7997 | if (WeakUndeclaredIdentifiers.empty()) |
| 7998 | return; |
| 7999 | |
| 8000 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8001 | IdentifierInfo *WeakId |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8002 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8003 | IdentifierInfo *AliasId |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8004 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 8005 | SourceLocation Loc |
| 8006 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 8007 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 8008 | WeakInfo WI(AliasId, Loc); |
| 8009 | WI.setUsed(Used); |
| 8010 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 8011 | } |
| 8012 | WeakUndeclaredIdentifiers.clear(); |
| 8013 | } |
| 8014 | |
| 8015 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 8016 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 8017 | ExternalVTableUse VT; |
| 8018 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 8019 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 8020 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 8021 | VTables.push_back(VT); |
| 8022 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8023 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8024 | VTableUses.clear(); |
| 8025 | } |
| 8026 | |
| 8027 | void ASTReader::ReadPendingInstantiations( |
| 8028 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 8029 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 8030 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 8031 | SourceLocation Loc |
| 8032 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 8033 | |
| 8034 | Pending.push_back(std::make_pair(D, Loc)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8035 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8036 | PendingInstantiations.clear(); |
| 8037 | } |
| 8038 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8039 | void ASTReader::ReadLateParsedTemplates( |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 8040 | llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> |
| 8041 | &LPTMap) { |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8042 | for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N; |
| 8043 | /* In loop */) { |
| 8044 | FunctionDecl *FD = cast<FunctionDecl>(GetDecl(LateParsedTemplates[Idx++])); |
| 8045 | |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 8046 | auto LT = llvm::make_unique<LateParsedTemplate>(); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8047 | LT->D = GetDecl(LateParsedTemplates[Idx++]); |
| 8048 | |
| 8049 | ModuleFile *F = getOwningModuleFile(LT->D); |
| 8050 | assert(F && "No module"); |
| 8051 | |
| 8052 | unsigned TokN = LateParsedTemplates[Idx++]; |
| 8053 | LT->Toks.reserve(TokN); |
| 8054 | for (unsigned T = 0; T < TokN; ++T) |
| 8055 | LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx)); |
| 8056 | |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 8057 | LPTMap.insert(std::make_pair(FD, std::move(LT))); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8058 | } |
| 8059 | |
| 8060 | LateParsedTemplates.clear(); |
| 8061 | } |
| 8062 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8063 | void ASTReader::LoadSelector(Selector Sel) { |
| 8064 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 8065 | ReadMethodPool(Sel); |
| 8066 | } |
| 8067 | |
| 8068 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
| 8069 | assert(ID && "Non-zero identifier ID required"); |
| 8070 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
| 8071 | IdentifiersLoaded[ID - 1] = II; |
| 8072 | if (DeserializationListener) |
| 8073 | DeserializationListener->IdentifierRead(ID, II); |
| 8074 | } |
| 8075 | |
| 8076 | /// \brief Set the globally-visible declarations associated with the given |
| 8077 | /// identifier. |
| 8078 | /// |
| 8079 | /// If the AST reader is currently in a state where the given declaration IDs |
| 8080 | /// cannot safely be resolved, they are queued until it is safe to resolve |
| 8081 | /// them. |
| 8082 | /// |
| 8083 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 8084 | /// declarations. |
| 8085 | /// |
| 8086 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 8087 | /// visible at global scope. |
| 8088 | /// |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8089 | /// \param Decls if non-null, this vector will be populated with the set of |
| 8090 | /// deserialized declarations. These declarations will not be pushed into |
| 8091 | /// scope. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8092 | void |
| 8093 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
| 8094 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8095 | SmallVectorImpl<Decl *> *Decls) { |
| 8096 | if (NumCurrentElementsDeserializing && !Decls) { |
| 8097 | PendingIdentifierInfos[II].append(DeclIDs.begin(), DeclIDs.end()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8098 | return; |
| 8099 | } |
| 8100 | |
| 8101 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 8102 | if (!SemaObj) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8103 | // Queue this declaration so that it will be added to the |
| 8104 | // translation unit scope and identifier's declaration chain |
| 8105 | // once a Sema object is known. |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 8106 | PreloadedDeclIDs.push_back(DeclIDs[I]); |
| 8107 | continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8108 | } |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 8109 | |
| 8110 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 8111 | |
| 8112 | // If we're simply supposed to record the declarations, do so now. |
| 8113 | if (Decls) { |
| 8114 | Decls->push_back(D); |
| 8115 | continue; |
| 8116 | } |
| 8117 | |
| 8118 | // Introduce this declaration into the translation-unit scope |
| 8119 | // and add it to the declaration chain for this identifier, so |
| 8120 | // that (unqualified) name lookup will find it. |
| 8121 | pushExternalDeclIntoScope(D, II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8122 | } |
| 8123 | } |
| 8124 | |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 8125 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8126 | if (ID == 0) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8127 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8128 | |
| 8129 | if (IdentifiersLoaded.empty()) { |
| 8130 | Error("no identifier table in AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8131 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8132 | } |
| 8133 | |
| 8134 | ID -= 1; |
| 8135 | if (!IdentifiersLoaded[ID]) { |
| 8136 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 8137 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
| 8138 | ModuleFile *M = I->second; |
| 8139 | unsigned Index = ID - M->BaseIdentifierID; |
| 8140 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
| 8141 | |
| 8142 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 8143 | // Extract that 16-bit length to avoid having to execute strlen(). |
| 8144 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 8145 | // unsigned integers. This is important to avoid integer overflow when |
| 8146 | // we cast them to 'unsigned'. |
| 8147 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
| 8148 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 8149 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 8150 | auto &II = PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
| 8151 | IdentifiersLoaded[ID] = &II; |
| 8152 | markIdentifierFromAST(*this, II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8153 | if (DeserializationListener) |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 8154 | DeserializationListener->IdentifierRead(ID + 1, &II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8155 | } |
| 8156 | |
| 8157 | return IdentifiersLoaded[ID]; |
| 8158 | } |
| 8159 | |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 8160 | IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) { |
| 8161 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8162 | } |
| 8163 | |
| 8164 | IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) { |
| 8165 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 8166 | return LocalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8167 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8168 | if (!M.ModuleOffsetMap.empty()) |
| 8169 | ReadModuleOffsetMap(M); |
| 8170 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8171 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8172 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8173 | assert(I != M.IdentifierRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8174 | && "Invalid index into identifier index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8175 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8176 | return LocalID + I->second; |
| 8177 | } |
| 8178 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8179 | MacroInfo *ASTReader::getMacro(MacroID ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8180 | if (ID == 0) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8181 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8182 | |
| 8183 | if (MacrosLoaded.empty()) { |
| 8184 | Error("no macro table in AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8185 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8186 | } |
| 8187 | |
| 8188 | ID -= NUM_PREDEF_MACRO_IDS; |
| 8189 | if (!MacrosLoaded[ID]) { |
| 8190 | GlobalMacroMapType::iterator I |
| 8191 | = GlobalMacroMap.find(ID + NUM_PREDEF_MACRO_IDS); |
| 8192 | assert(I != GlobalMacroMap.end() && "Corrupted global macro map"); |
| 8193 | ModuleFile *M = I->second; |
| 8194 | unsigned Index = ID - M->BaseMacroID; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8195 | MacrosLoaded[ID] = ReadMacroRecord(*M, M->MacroOffsets[Index]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8196 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8197 | if (DeserializationListener) |
| 8198 | DeserializationListener->MacroRead(ID + NUM_PREDEF_MACRO_IDS, |
| 8199 | MacrosLoaded[ID]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8200 | } |
| 8201 | |
| 8202 | return MacrosLoaded[ID]; |
| 8203 | } |
| 8204 | |
| 8205 | MacroID ASTReader::getGlobalMacroID(ModuleFile &M, unsigned LocalID) { |
| 8206 | if (LocalID < NUM_PREDEF_MACRO_IDS) |
| 8207 | return LocalID; |
| 8208 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8209 | if (!M.ModuleOffsetMap.empty()) |
| 8210 | ReadModuleOffsetMap(M); |
| 8211 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8212 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8213 | = M.MacroRemap.find(LocalID - NUM_PREDEF_MACRO_IDS); |
| 8214 | assert(I != M.MacroRemap.end() && "Invalid index into macro index remap"); |
| 8215 | |
| 8216 | return LocalID + I->second; |
| 8217 | } |
| 8218 | |
| 8219 | serialization::SubmoduleID |
| 8220 | ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) { |
| 8221 | if (LocalID < NUM_PREDEF_SUBMODULE_IDS) |
| 8222 | return LocalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8223 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8224 | if (!M.ModuleOffsetMap.empty()) |
| 8225 | ReadModuleOffsetMap(M); |
| 8226 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8227 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8228 | = M.SubmoduleRemap.find(LocalID - NUM_PREDEF_SUBMODULE_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8229 | assert(I != M.SubmoduleRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8230 | && "Invalid index into submodule index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8231 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8232 | return LocalID + I->second; |
| 8233 | } |
| 8234 | |
| 8235 | Module *ASTReader::getSubmodule(SubmoduleID GlobalID) { |
| 8236 | if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) { |
| 8237 | assert(GlobalID == 0 && "Unhandled global submodule ID"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8238 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8239 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8240 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8241 | if (GlobalID > SubmodulesLoaded.size()) { |
| 8242 | Error("submodule ID out of range in AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8243 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8244 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8245 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8246 | return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS]; |
| 8247 | } |
Douglas Gregor | c147b0b | 2013-01-12 01:29:50 +0000 | [diff] [blame] | 8248 | |
| 8249 | Module *ASTReader::getModule(unsigned ID) { |
| 8250 | return getSubmodule(ID); |
| 8251 | } |
| 8252 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 8253 | ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &F, unsigned ID) { |
| 8254 | if (ID & 1) { |
| 8255 | // It's a module, look it up by submodule ID. |
| 8256 | auto I = GlobalSubmoduleMap.find(getGlobalSubmoduleID(F, ID >> 1)); |
| 8257 | return I == GlobalSubmoduleMap.end() ? nullptr : I->second; |
| 8258 | } else { |
| 8259 | // It's a prefix (preamble, PCH, ...). Look it up by index. |
| 8260 | unsigned IndexFromEnd = ID >> 1; |
| 8261 | assert(IndexFromEnd && "got reference to unknown module file"); |
| 8262 | return getModuleManager().pch_modules().end()[-IndexFromEnd]; |
| 8263 | } |
| 8264 | } |
| 8265 | |
| 8266 | unsigned ASTReader::getModuleFileID(ModuleFile *F) { |
| 8267 | if (!F) |
| 8268 | return 1; |
| 8269 | |
| 8270 | // For a file representing a module, use the submodule ID of the top-level |
| 8271 | // module as the file ID. For any other kind of file, the number of such |
| 8272 | // files loaded beforehand will be the same on reload. |
| 8273 | // FIXME: Is this true even if we have an explicit module file and a PCH? |
| 8274 | if (F->isModule()) |
| 8275 | return ((F->BaseSubmoduleID + NUM_PREDEF_SUBMODULE_IDS) << 1) | 1; |
| 8276 | |
| 8277 | auto PCHModules = getModuleManager().pch_modules(); |
| 8278 | auto I = std::find(PCHModules.begin(), PCHModules.end(), F); |
| 8279 | assert(I != PCHModules.end() && "emitting reference to unknown file"); |
| 8280 | return (I - PCHModules.end()) << 1; |
| 8281 | } |
| 8282 | |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8283 | llvm::Optional<ExternalASTSource::ASTSourceDescriptor> |
| 8284 | ASTReader::getSourceDescriptor(unsigned ID) { |
| 8285 | if (const Module *M = getSubmodule(ID)) |
Adrian Prantl | c6458d6 | 2015-09-19 00:10:32 +0000 | [diff] [blame] | 8286 | return ExternalASTSource::ASTSourceDescriptor(*M); |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8287 | |
| 8288 | // If there is only a single PCH, return it instead. |
Hiroshi Inoue | 3170de0 | 2017-07-01 08:46:43 +0000 | [diff] [blame] | 8289 | // Chained PCH are not supported. |
Saleem Abdulrasool | 97d2555 | 2017-03-02 17:37:11 +0000 | [diff] [blame] | 8290 | const auto &PCHChain = ModuleMgr.pch_modules(); |
| 8291 | if (std::distance(std::begin(PCHChain), std::end(PCHChain))) { |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8292 | ModuleFile &MF = ModuleMgr.getPrimaryModule(); |
Adrian Prantl | 3a2d494 | 2016-01-22 23:30:56 +0000 | [diff] [blame] | 8293 | StringRef ModuleName = llvm::sys::path::filename(MF.OriginalSourceFileName); |
Adrian Prantl | 9bc3c4f | 2016-04-27 17:06:22 +0000 | [diff] [blame] | 8294 | StringRef FileName = llvm::sys::path::filename(MF.FileName); |
| 8295 | return ASTReader::ASTSourceDescriptor(ModuleName, MF.OriginalDir, FileName, |
| 8296 | MF.Signature); |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8297 | } |
| 8298 | return None; |
| 8299 | } |
| 8300 | |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 8301 | ExternalASTSource::ExtKind ASTReader::hasExternalDefinitions(const Decl *FD) { |
Richard Smith | a465362 | 2017-09-06 20:01:14 +0000 | [diff] [blame] | 8302 | auto I = DefinitionSource.find(FD); |
| 8303 | if (I == DefinitionSource.end()) |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 8304 | return EK_ReplyHazy; |
David Blaikie | e6b7c28 | 2017-04-11 20:46:34 +0000 | [diff] [blame] | 8305 | return I->second ? EK_Never : EK_Always; |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 8306 | } |
| 8307 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8308 | Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) { |
| 8309 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 8310 | } |
| 8311 | |
| 8312 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
| 8313 | if (ID == 0) |
| 8314 | return Selector(); |
| 8315 | |
| 8316 | if (ID > SelectorsLoaded.size()) { |
| 8317 | Error("selector ID out of range in AST file"); |
| 8318 | return Selector(); |
| 8319 | } |
| 8320 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8321 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == nullptr) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8322 | // Load this selector from the selector table. |
| 8323 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 8324 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
| 8325 | ModuleFile &M = *I->second; |
| 8326 | ASTSelectorLookupTrait Trait(*this, M); |
| 8327 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
| 8328 | SelectorsLoaded[ID - 1] = |
| 8329 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
| 8330 | if (DeserializationListener) |
| 8331 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 8332 | } |
| 8333 | |
| 8334 | return SelectorsLoaded[ID - 1]; |
| 8335 | } |
| 8336 | |
| 8337 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
| 8338 | return DecodeSelector(ID); |
| 8339 | } |
| 8340 | |
| 8341 | uint32_t ASTReader::GetNumExternalSelectors() { |
| 8342 | // ID 0 (the null selector) is considered an external selector. |
| 8343 | return getTotalNumSelectors() + 1; |
| 8344 | } |
| 8345 | |
| 8346 | serialization::SelectorID |
| 8347 | ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const { |
| 8348 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 8349 | return LocalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8350 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8351 | if (!M.ModuleOffsetMap.empty()) |
| 8352 | ReadModuleOffsetMap(M); |
| 8353 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8354 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8355 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8356 | assert(I != M.SelectorRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8357 | && "Invalid index into selector index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8358 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8359 | return LocalID + I->second; |
| 8360 | } |
| 8361 | |
| 8362 | DeclarationName |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8363 | ASTReader::ReadDeclarationName(ModuleFile &F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8364 | const RecordData &Record, unsigned &Idx) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8365 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8366 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 8367 | switch (Kind) { |
| 8368 | case DeclarationName::Identifier: |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 8369 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8370 | |
| 8371 | case DeclarationName::ObjCZeroArgSelector: |
| 8372 | case DeclarationName::ObjCOneArgSelector: |
| 8373 | case DeclarationName::ObjCMultiArgSelector: |
| 8374 | return DeclarationName(ReadSelector(F, Record, Idx)); |
| 8375 | |
| 8376 | case DeclarationName::CXXConstructorName: |
| 8377 | return Context.DeclarationNames.getCXXConstructorName( |
| 8378 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 8379 | |
| 8380 | case DeclarationName::CXXDestructorName: |
| 8381 | return Context.DeclarationNames.getCXXDestructorName( |
| 8382 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 8383 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8384 | case DeclarationName::CXXDeductionGuideName: |
| 8385 | return Context.DeclarationNames.getCXXDeductionGuideName( |
| 8386 | ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
| 8387 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8388 | case DeclarationName::CXXConversionFunctionName: |
| 8389 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 8390 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 8391 | |
| 8392 | case DeclarationName::CXXOperatorName: |
| 8393 | return Context.DeclarationNames.getCXXOperatorName( |
| 8394 | (OverloadedOperatorKind)Record[Idx++]); |
| 8395 | |
| 8396 | case DeclarationName::CXXLiteralOperatorName: |
| 8397 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
| 8398 | GetIdentifierInfo(F, Record, Idx)); |
| 8399 | |
| 8400 | case DeclarationName::CXXUsingDirective: |
| 8401 | return DeclarationName::getUsingDirectiveName(); |
| 8402 | } |
| 8403 | |
| 8404 | llvm_unreachable("Invalid NameKind!"); |
| 8405 | } |
| 8406 | |
| 8407 | void ASTReader::ReadDeclarationNameLoc(ModuleFile &F, |
| 8408 | DeclarationNameLoc &DNLoc, |
| 8409 | DeclarationName Name, |
| 8410 | const RecordData &Record, unsigned &Idx) { |
| 8411 | switch (Name.getNameKind()) { |
| 8412 | case DeclarationName::CXXConstructorName: |
| 8413 | case DeclarationName::CXXDestructorName: |
| 8414 | case DeclarationName::CXXConversionFunctionName: |
| 8415 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8416 | break; |
| 8417 | |
| 8418 | case DeclarationName::CXXOperatorName: |
| 8419 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 8420 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 8421 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 8422 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 8423 | break; |
| 8424 | |
| 8425 | case DeclarationName::CXXLiteralOperatorName: |
| 8426 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 8427 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 8428 | break; |
| 8429 | |
| 8430 | case DeclarationName::Identifier: |
| 8431 | case DeclarationName::ObjCZeroArgSelector: |
| 8432 | case DeclarationName::ObjCOneArgSelector: |
| 8433 | case DeclarationName::ObjCMultiArgSelector: |
| 8434 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8435 | case DeclarationName::CXXDeductionGuideName: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8436 | break; |
| 8437 | } |
| 8438 | } |
| 8439 | |
| 8440 | void ASTReader::ReadDeclarationNameInfo(ModuleFile &F, |
| 8441 | DeclarationNameInfo &NameInfo, |
| 8442 | const RecordData &Record, unsigned &Idx) { |
| 8443 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
| 8444 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 8445 | DeclarationNameLoc DNLoc; |
| 8446 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 8447 | NameInfo.setInfo(DNLoc); |
| 8448 | } |
| 8449 | |
| 8450 | void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, |
| 8451 | const RecordData &Record, unsigned &Idx) { |
| 8452 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
| 8453 | unsigned NumTPLists = Record[Idx++]; |
| 8454 | Info.NumTemplParamLists = NumTPLists; |
| 8455 | if (NumTPLists) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8456 | Info.TemplParamLists = |
| 8457 | new (getContext()) TemplateParameterList *[NumTPLists]; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 8458 | for (unsigned i = 0; i != NumTPLists; ++i) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8459 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 8460 | } |
| 8461 | } |
| 8462 | |
| 8463 | TemplateName |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8464 | ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8465 | unsigned &Idx) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8466 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8467 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
| 8468 | switch (Kind) { |
| 8469 | case TemplateName::Template: |
| 8470 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
| 8471 | |
| 8472 | case TemplateName::OverloadedTemplate: { |
| 8473 | unsigned size = Record[Idx++]; |
| 8474 | UnresolvedSet<8> Decls; |
| 8475 | while (size--) |
| 8476 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
| 8477 | |
| 8478 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 8479 | } |
| 8480 | |
| 8481 | case TemplateName::QualifiedTemplate: { |
| 8482 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
| 8483 | bool hasTemplKeyword = Record[Idx++]; |
| 8484 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
| 8485 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 8486 | } |
| 8487 | |
| 8488 | case TemplateName::DependentTemplate: { |
| 8489 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
| 8490 | if (Record[Idx++]) // isIdentifier |
| 8491 | return Context.getDependentTemplateName(NNS, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8492 | GetIdentifierInfo(F, Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8493 | Idx)); |
| 8494 | return Context.getDependentTemplateName(NNS, |
| 8495 | (OverloadedOperatorKind)Record[Idx++]); |
| 8496 | } |
| 8497 | |
| 8498 | case TemplateName::SubstTemplateTemplateParm: { |
| 8499 | TemplateTemplateParmDecl *param |
| 8500 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
| 8501 | if (!param) return TemplateName(); |
| 8502 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
| 8503 | return Context.getSubstTemplateTemplateParm(param, replacement); |
| 8504 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8505 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8506 | case TemplateName::SubstTemplateTemplateParmPack: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8507 | TemplateTemplateParmDecl *Param |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8508 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
| 8509 | if (!Param) |
| 8510 | return TemplateName(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8511 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8512 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 8513 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 8514 | return TemplateName(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8515 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8516 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 8517 | } |
| 8518 | } |
| 8519 | |
| 8520 | llvm_unreachable("Unhandled template name kind!"); |
| 8521 | } |
| 8522 | |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8523 | TemplateArgument ASTReader::ReadTemplateArgument(ModuleFile &F, |
| 8524 | const RecordData &Record, |
| 8525 | unsigned &Idx, |
| 8526 | bool Canonicalize) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8527 | ASTContext &Context = getContext(); |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8528 | if (Canonicalize) { |
| 8529 | // The caller wants a canonical template argument. Sometimes the AST only |
| 8530 | // wants template arguments in canonical form (particularly as the template |
| 8531 | // argument lists of template specializations) so ensure we preserve that |
| 8532 | // canonical form across serialization. |
| 8533 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Idx, false); |
| 8534 | return Context.getCanonicalTemplateArgument(Arg); |
| 8535 | } |
| 8536 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8537 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 8538 | switch (Kind) { |
| 8539 | case TemplateArgument::Null: |
| 8540 | return TemplateArgument(); |
| 8541 | case TemplateArgument::Type: |
| 8542 | return TemplateArgument(readType(F, Record, Idx)); |
| 8543 | case TemplateArgument::Declaration: { |
| 8544 | ValueDecl *D = ReadDeclAs<ValueDecl>(F, Record, Idx); |
David Blaikie | 0f62c8d | 2014-10-16 04:21:25 +0000 | [diff] [blame] | 8545 | return TemplateArgument(D, readType(F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8546 | } |
| 8547 | case TemplateArgument::NullPtr: |
| 8548 | return TemplateArgument(readType(F, Record, Idx), /*isNullPtr*/true); |
| 8549 | case TemplateArgument::Integral: { |
| 8550 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 8551 | QualType T = readType(F, Record, Idx); |
| 8552 | return TemplateArgument(Context, Value, T); |
| 8553 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8554 | case TemplateArgument::Template: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8555 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
| 8556 | case TemplateArgument::TemplateExpansion: { |
| 8557 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8558 | Optional<unsigned> NumTemplateExpansions; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8559 | if (unsigned NumExpansions = Record[Idx++]) |
| 8560 | NumTemplateExpansions = NumExpansions - 1; |
| 8561 | return TemplateArgument(Name, NumTemplateExpansions); |
| 8562 | } |
| 8563 | case TemplateArgument::Expression: |
| 8564 | return TemplateArgument(ReadExpr(F)); |
| 8565 | case TemplateArgument::Pack: { |
| 8566 | unsigned NumArgs = Record[Idx++]; |
| 8567 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
| 8568 | for (unsigned I = 0; I != NumArgs; ++I) |
| 8569 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 8570 | return TemplateArgument(llvm::makeArrayRef(Args, NumArgs)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8571 | } |
| 8572 | } |
| 8573 | |
| 8574 | llvm_unreachable("Unhandled template argument kind!"); |
| 8575 | } |
| 8576 | |
| 8577 | TemplateParameterList * |
| 8578 | ASTReader::ReadTemplateParameterList(ModuleFile &F, |
| 8579 | const RecordData &Record, unsigned &Idx) { |
| 8580 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 8581 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 8582 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 8583 | |
| 8584 | unsigned NumParams = Record[Idx++]; |
| 8585 | SmallVector<NamedDecl *, 16> Params; |
| 8586 | Params.reserve(NumParams); |
| 8587 | while (NumParams--) |
| 8588 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
| 8589 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 8590 | // TODO: Concepts |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8591 | TemplateParameterList *TemplateParams = TemplateParameterList::Create( |
| 8592 | getContext(), TemplateLoc, LAngleLoc, Params, RAngleLoc, nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8593 | return TemplateParams; |
| 8594 | } |
| 8595 | |
| 8596 | void |
| 8597 | ASTReader:: |
Craig Topper | 5603df4 | 2013-07-05 19:34:19 +0000 | [diff] [blame] | 8598 | ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8599 | ModuleFile &F, const RecordData &Record, |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8600 | unsigned &Idx, bool Canonicalize) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8601 | unsigned NumTemplateArgs = Record[Idx++]; |
| 8602 | TemplArgs.reserve(NumTemplateArgs); |
| 8603 | while (NumTemplateArgs--) |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8604 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx, Canonicalize)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8605 | } |
| 8606 | |
| 8607 | /// \brief Read a UnresolvedSet structure. |
Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 8608 | void ASTReader::ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8609 | const RecordData &Record, unsigned &Idx) { |
| 8610 | unsigned NumDecls = Record[Idx++]; |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8611 | Set.reserve(getContext(), NumDecls); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8612 | while (NumDecls--) { |
Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 8613 | DeclID ID = ReadDeclID(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8614 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8615 | Set.addLazyDecl(getContext(), ID, AS); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8616 | } |
| 8617 | } |
| 8618 | |
| 8619 | CXXBaseSpecifier |
| 8620 | ASTReader::ReadCXXBaseSpecifier(ModuleFile &F, |
| 8621 | const RecordData &Record, unsigned &Idx) { |
| 8622 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 8623 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 8624 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
| 8625 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
| 8626 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8627 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8628 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8629 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8630 | EllipsisLoc); |
| 8631 | Result.setInheritConstructors(inheritConstructors); |
| 8632 | return Result; |
| 8633 | } |
| 8634 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8635 | CXXCtorInitializer ** |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8636 | ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, |
| 8637 | unsigned &Idx) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8638 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8639 | unsigned NumInitializers = Record[Idx++]; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8640 | assert(NumInitializers && "wrote ctor initializers but have no inits"); |
| 8641 | auto **CtorInitializers = new (Context) CXXCtorInitializer*[NumInitializers]; |
| 8642 | for (unsigned i = 0; i != NumInitializers; ++i) { |
| 8643 | TypeSourceInfo *TInfo = nullptr; |
| 8644 | bool IsBaseVirtual = false; |
| 8645 | FieldDecl *Member = nullptr; |
| 8646 | IndirectFieldDecl *IndirectMember = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8647 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8648 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 8649 | switch (Type) { |
| 8650 | case CTOR_INITIALIZER_BASE: |
| 8651 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8652 | IsBaseVirtual = Record[Idx++]; |
| 8653 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8654 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8655 | case CTOR_INITIALIZER_DELEGATING: |
| 8656 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8657 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8658 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8659 | case CTOR_INITIALIZER_MEMBER: |
| 8660 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
| 8661 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8662 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8663 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
| 8664 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
| 8665 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8666 | } |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8667 | |
| 8668 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
| 8669 | Expr *Init = ReadExpr(F); |
| 8670 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 8671 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8672 | |
| 8673 | CXXCtorInitializer *BOMInit; |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8674 | if (Type == CTOR_INITIALIZER_BASE) |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8675 | BOMInit = new (Context) |
| 8676 | CXXCtorInitializer(Context, TInfo, IsBaseVirtual, LParenLoc, Init, |
| 8677 | RParenLoc, MemberOrEllipsisLoc); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8678 | else if (Type == CTOR_INITIALIZER_DELEGATING) |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8679 | BOMInit = new (Context) |
| 8680 | CXXCtorInitializer(Context, TInfo, LParenLoc, Init, RParenLoc); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8681 | else if (Member) |
| 8682 | BOMInit = new (Context) |
| 8683 | CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, LParenLoc, |
| 8684 | Init, RParenLoc); |
| 8685 | else |
| 8686 | BOMInit = new (Context) |
| 8687 | CXXCtorInitializer(Context, IndirectMember, MemberOrEllipsisLoc, |
| 8688 | LParenLoc, Init, RParenLoc); |
| 8689 | |
Richard Smith | 418ed82 | 2016-12-14 19:45:03 +0000 | [diff] [blame] | 8690 | if (/*IsWritten*/Record[Idx++]) { |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8691 | unsigned SourceOrder = Record[Idx++]; |
| 8692 | BOMInit->setSourceOrder(SourceOrder); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8693 | } |
| 8694 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8695 | CtorInitializers[i] = BOMInit; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8696 | } |
| 8697 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8698 | return CtorInitializers; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8699 | } |
| 8700 | |
| 8701 | NestedNameSpecifier * |
| 8702 | ASTReader::ReadNestedNameSpecifier(ModuleFile &F, |
| 8703 | const RecordData &Record, unsigned &Idx) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8704 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8705 | unsigned N = Record[Idx++]; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8706 | NestedNameSpecifier *NNS = nullptr, *Prev = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8707 | for (unsigned I = 0; I != N; ++I) { |
| 8708 | NestedNameSpecifier::SpecifierKind Kind |
| 8709 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 8710 | switch (Kind) { |
| 8711 | case NestedNameSpecifier::Identifier: { |
| 8712 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
| 8713 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
| 8714 | break; |
| 8715 | } |
| 8716 | |
| 8717 | case NestedNameSpecifier::Namespace: { |
| 8718 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
| 8719 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
| 8720 | break; |
| 8721 | } |
| 8722 | |
| 8723 | case NestedNameSpecifier::NamespaceAlias: { |
| 8724 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
| 8725 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
| 8726 | break; |
| 8727 | } |
| 8728 | |
| 8729 | case NestedNameSpecifier::TypeSpec: |
| 8730 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 8731 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
| 8732 | if (!T) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8733 | return nullptr; |
| 8734 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8735 | bool Template = Record[Idx++]; |
| 8736 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
| 8737 | break; |
| 8738 | } |
| 8739 | |
| 8740 | case NestedNameSpecifier::Global: { |
| 8741 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
| 8742 | // No associated value, and there can't be a prefix. |
| 8743 | break; |
| 8744 | } |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8745 | |
| 8746 | case NestedNameSpecifier::Super: { |
| 8747 | CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx); |
| 8748 | NNS = NestedNameSpecifier::SuperSpecifier(Context, RD); |
| 8749 | break; |
| 8750 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8751 | } |
| 8752 | Prev = NNS; |
| 8753 | } |
| 8754 | return NNS; |
| 8755 | } |
| 8756 | |
| 8757 | NestedNameSpecifierLoc |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8758 | ASTReader::ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8759 | unsigned &Idx) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8760 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8761 | unsigned N = Record[Idx++]; |
| 8762 | NestedNameSpecifierLocBuilder Builder; |
| 8763 | for (unsigned I = 0; I != N; ++I) { |
| 8764 | NestedNameSpecifier::SpecifierKind Kind |
| 8765 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 8766 | switch (Kind) { |
| 8767 | case NestedNameSpecifier::Identifier: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8768 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8769 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8770 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
| 8771 | break; |
| 8772 | } |
| 8773 | |
| 8774 | case NestedNameSpecifier::Namespace: { |
| 8775 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
| 8776 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8777 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
| 8778 | break; |
| 8779 | } |
| 8780 | |
| 8781 | case NestedNameSpecifier::NamespaceAlias: { |
| 8782 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
| 8783 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8784 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
| 8785 | break; |
| 8786 | } |
| 8787 | |
| 8788 | case NestedNameSpecifier::TypeSpec: |
| 8789 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 8790 | bool Template = Record[Idx++]; |
| 8791 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 8792 | if (!T) |
| 8793 | return NestedNameSpecifierLoc(); |
| 8794 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
| 8795 | |
| 8796 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8797 | Builder.Extend(Context, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8798 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 8799 | T->getTypeLoc(), ColonColonLoc); |
| 8800 | break; |
| 8801 | } |
| 8802 | |
| 8803 | case NestedNameSpecifier::Global: { |
| 8804 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
| 8805 | Builder.MakeGlobal(Context, ColonColonLoc); |
| 8806 | break; |
| 8807 | } |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8808 | |
| 8809 | case NestedNameSpecifier::Super: { |
| 8810 | CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx); |
| 8811 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8812 | Builder.MakeSuper(Context, RD, Range.getBegin(), Range.getEnd()); |
| 8813 | break; |
| 8814 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8815 | } |
| 8816 | } |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8817 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8818 | return Builder.getWithLocInContext(Context); |
| 8819 | } |
| 8820 | |
| 8821 | SourceRange |
| 8822 | ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record, |
| 8823 | unsigned &Idx) { |
| 8824 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 8825 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
| 8826 | return SourceRange(beg, end); |
| 8827 | } |
| 8828 | |
| 8829 | /// \brief Read an integral value |
| 8830 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
| 8831 | unsigned BitWidth = Record[Idx++]; |
| 8832 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 8833 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 8834 | Idx += NumWords; |
| 8835 | return Result; |
| 8836 | } |
| 8837 | |
| 8838 | /// \brief Read a signed integral value |
| 8839 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
| 8840 | bool isUnsigned = Record[Idx++]; |
| 8841 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 8842 | } |
| 8843 | |
| 8844 | /// \brief Read a floating-point value |
Tim Northover | 178723a | 2013-01-22 09:46:51 +0000 | [diff] [blame] | 8845 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, |
| 8846 | const llvm::fltSemantics &Sem, |
| 8847 | unsigned &Idx) { |
| 8848 | return llvm::APFloat(Sem, ReadAPInt(Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8849 | } |
| 8850 | |
| 8851 | // \brief Read a string |
| 8852 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
| 8853 | unsigned Len = Record[Idx++]; |
| 8854 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
| 8855 | Idx += Len; |
| 8856 | return Result; |
| 8857 | } |
| 8858 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 8859 | std::string ASTReader::ReadPath(ModuleFile &F, const RecordData &Record, |
| 8860 | unsigned &Idx) { |
| 8861 | std::string Filename = ReadString(Record, Idx); |
| 8862 | ResolveImportedPath(F, Filename); |
| 8863 | return Filename; |
| 8864 | } |
| 8865 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8866 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8867 | unsigned &Idx) { |
| 8868 | unsigned Major = Record[Idx++]; |
| 8869 | unsigned Minor = Record[Idx++]; |
| 8870 | unsigned Subminor = Record[Idx++]; |
| 8871 | if (Minor == 0) |
| 8872 | return VersionTuple(Major); |
| 8873 | if (Subminor == 0) |
| 8874 | return VersionTuple(Major, Minor - 1); |
| 8875 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 8876 | } |
| 8877 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8878 | CXXTemporary *ASTReader::ReadCXXTemporary(ModuleFile &F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8879 | const RecordData &Record, |
| 8880 | unsigned &Idx) { |
| 8881 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8882 | return CXXTemporary::Create(getContext(), Decl); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8883 | } |
| 8884 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8885 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) const { |
Argyrios Kyrtzidis | dc9fdaf | 2013-05-24 05:44:08 +0000 | [diff] [blame] | 8886 | return Diag(CurrentImportLoc, DiagID); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8887 | } |
| 8888 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8889 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8890 | return Diags.Report(Loc, DiagID); |
| 8891 | } |
| 8892 | |
| 8893 | /// \brief Retrieve the identifier table associated with the |
| 8894 | /// preprocessor. |
| 8895 | IdentifierTable &ASTReader::getIdentifierTable() { |
| 8896 | return PP.getIdentifierTable(); |
| 8897 | } |
| 8898 | |
| 8899 | /// \brief Record that the given ID maps to the given switch-case |
| 8900 | /// statement. |
| 8901 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8902 | assert((*CurrSwitchCaseStmts)[ID] == nullptr && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8903 | "Already have a SwitchCase with this ID"); |
| 8904 | (*CurrSwitchCaseStmts)[ID] = SC; |
| 8905 | } |
| 8906 | |
| 8907 | /// \brief Retrieve the switch-case statement with the given ID. |
| 8908 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8909 | assert((*CurrSwitchCaseStmts)[ID] != nullptr && "No SwitchCase with this ID"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8910 | return (*CurrSwitchCaseStmts)[ID]; |
| 8911 | } |
| 8912 | |
| 8913 | void ASTReader::ClearSwitchCaseIDs() { |
| 8914 | CurrSwitchCaseStmts->clear(); |
| 8915 | } |
| 8916 | |
| 8917 | void ASTReader::ReadComments() { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8918 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8919 | std::vector<RawComment *> Comments; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 8920 | for (SmallVectorImpl<std::pair<BitstreamCursor, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8921 | serialization::ModuleFile *> >::iterator |
| 8922 | I = CommentsCursors.begin(), |
| 8923 | E = CommentsCursors.end(); |
| 8924 | I != E; ++I) { |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 8925 | Comments.clear(); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 8926 | BitstreamCursor &Cursor = I->first; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8927 | serialization::ModuleFile &F = *I->second; |
| 8928 | SavedStreamPosition SavedPosition(Cursor); |
| 8929 | |
| 8930 | RecordData Record; |
| 8931 | while (true) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 8932 | llvm::BitstreamEntry Entry = |
| 8933 | Cursor.advanceSkippingSubblocks(BitstreamCursor::AF_DontPopBlockAtEnd); |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 8934 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 8935 | switch (Entry.Kind) { |
| 8936 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 8937 | case llvm::BitstreamEntry::Error: |
| 8938 | Error("malformed block record in AST file"); |
| 8939 | return; |
| 8940 | case llvm::BitstreamEntry::EndBlock: |
| 8941 | goto NextCursor; |
| 8942 | case llvm::BitstreamEntry::Record: |
| 8943 | // The interesting case. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8944 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8945 | } |
| 8946 | |
| 8947 | // Read a record. |
| 8948 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 8949 | switch ((CommentRecordTypes)Cursor.readRecord(Entry.ID, Record)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8950 | case COMMENTS_RAW_COMMENT: { |
| 8951 | unsigned Idx = 0; |
| 8952 | SourceRange SR = ReadSourceRange(F, Record, Idx); |
| 8953 | RawComment::CommentKind Kind = |
| 8954 | (RawComment::CommentKind) Record[Idx++]; |
| 8955 | bool IsTrailingComment = Record[Idx++]; |
| 8956 | bool IsAlmostTrailingComment = Record[Idx++]; |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 8957 | Comments.push_back(new (Context) RawComment( |
| 8958 | SR, Kind, IsTrailingComment, IsAlmostTrailingComment, |
| 8959 | Context.getLangOpts().CommentOpts.ParseAllComments)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8960 | break; |
| 8961 | } |
| 8962 | } |
| 8963 | } |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 8964 | NextCursor: |
Bruno Cardoso Lopes | c23af57 | 2016-12-19 21:06:06 +0000 | [diff] [blame] | 8965 | // De-serialized SourceLocations get negative FileIDs for other modules, |
| 8966 | // potentially invalidating the original order. Sort it again. |
| 8967 | std::sort(Comments.begin(), Comments.end(), |
| 8968 | BeforeThanCompare<RawComment>(SourceMgr)); |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 8969 | Context.Comments.addDeserializedComments(Comments); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8970 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8971 | } |
| 8972 | |
Argyrios Kyrtzidis | a38cb20 | 2017-01-30 06:05:58 +0000 | [diff] [blame] | 8973 | void ASTReader::visitInputFiles(serialization::ModuleFile &MF, |
| 8974 | bool IncludeSystem, bool Complain, |
| 8975 | llvm::function_ref<void(const serialization::InputFile &IF, |
| 8976 | bool isSystem)> Visitor) { |
| 8977 | unsigned NumUserInputs = MF.NumUserInputFiles; |
| 8978 | unsigned NumInputs = MF.InputFilesLoaded.size(); |
| 8979 | assert(NumUserInputs <= NumInputs); |
| 8980 | unsigned N = IncludeSystem ? NumInputs : NumUserInputs; |
| 8981 | for (unsigned I = 0; I < N; ++I) { |
| 8982 | bool IsSystem = I >= NumUserInputs; |
| 8983 | InputFile IF = getInputFile(MF, I+1, Complain); |
| 8984 | Visitor(IF, IsSystem); |
| 8985 | } |
| 8986 | } |
| 8987 | |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 8988 | void ASTReader::visitTopLevelModuleMaps( |
| 8989 | serialization::ModuleFile &MF, |
| 8990 | llvm::function_ref<void(const FileEntry *FE)> Visitor) { |
| 8991 | unsigned NumInputs = MF.InputFilesLoaded.size(); |
| 8992 | for (unsigned I = 0; I < NumInputs; ++I) { |
| 8993 | InputFileInfo IFI = readInputFileInfo(MF, I + 1); |
| 8994 | if (IFI.TopLevelModuleMap) |
| 8995 | // FIXME: This unnecessarily re-reads the InputFileInfo. |
| 8996 | if (auto *FE = getInputFile(MF, I + 1).getFile()) |
| 8997 | Visitor(FE); |
| 8998 | } |
| 8999 | } |
| 9000 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9001 | std::string ASTReader::getOwningModuleNameForDiagnostic(const Decl *D) { |
| 9002 | // If we know the owning module, use it. |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 9003 | if (Module *M = D->getImportedOwningModule()) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9004 | return M->getFullModuleName(); |
| 9005 | |
| 9006 | // Otherwise, use the name of the top-level module the decl is within. |
| 9007 | if (ModuleFile *M = getOwningModuleFile(D)) |
| 9008 | return M->ModuleName; |
| 9009 | |
| 9010 | // Not from a module. |
| 9011 | return ""; |
| 9012 | } |
| 9013 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9014 | void ASTReader::finishPendingActions() { |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 9015 | while (!PendingIdentifierInfos.empty() || |
| 9016 | !PendingIncompleteDeclChains.empty() || !PendingDeclChains.empty() || |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 9017 | !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() || |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9018 | !PendingUpdateRecords.empty()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9019 | // If any identifiers with corresponding top-level declarations have |
| 9020 | // been loaded, load those declarations now. |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 9021 | typedef llvm::DenseMap<IdentifierInfo *, SmallVector<Decl *, 2> > |
| 9022 | TopLevelDeclsMap; |
| 9023 | TopLevelDeclsMap TopLevelDecls; |
| 9024 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9025 | while (!PendingIdentifierInfos.empty()) { |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9026 | IdentifierInfo *II = PendingIdentifierInfos.back().first; |
Richard Smith | f0ae3c2d | 2014-03-28 17:31:23 +0000 | [diff] [blame] | 9027 | SmallVector<uint32_t, 4> DeclIDs = |
| 9028 | std::move(PendingIdentifierInfos.back().second); |
Douglas Gregor | cb15f08 | 2013-02-19 18:26:28 +0000 | [diff] [blame] | 9029 | PendingIdentifierInfos.pop_back(); |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9030 | |
| 9031 | SetGloballyVisibleDecls(II, DeclIDs, &TopLevelDecls[II]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9032 | } |
Richard Smith | f0ae3c2d | 2014-03-28 17:31:23 +0000 | [diff] [blame] | 9033 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 9034 | // For each decl chain that we wanted to complete while deserializing, mark |
| 9035 | // it as "still needs to be completed". |
| 9036 | for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) { |
| 9037 | markIncompleteDeclChain(PendingIncompleteDeclChains[I]); |
| 9038 | } |
| 9039 | PendingIncompleteDeclChains.clear(); |
| 9040 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9041 | // Load pending declaration chains. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 9042 | for (unsigned I = 0; I != PendingDeclChains.size(); ++I) |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 9043 | loadPendingDeclChain(PendingDeclChains[I].first, PendingDeclChains[I].second); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9044 | PendingDeclChains.clear(); |
| 9045 | |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9046 | // Make the most recent of the top-level declarations visible. |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 9047 | for (TopLevelDeclsMap::iterator TLD = TopLevelDecls.begin(), |
| 9048 | TLDEnd = TopLevelDecls.end(); TLD != TLDEnd; ++TLD) { |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9049 | IdentifierInfo *II = TLD->first; |
| 9050 | for (unsigned I = 0, N = TLD->second.size(); I != N; ++I) { |
Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 9051 | pushExternalDeclIntoScope(cast<NamedDecl>(TLD->second[I]), II); |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9052 | } |
| 9053 | } |
| 9054 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9055 | // Load any pending macro definitions. |
| 9056 | for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) { |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9057 | IdentifierInfo *II = PendingMacroIDs.begin()[I].first; |
| 9058 | SmallVector<PendingMacroInfo, 2> GlobalIDs; |
| 9059 | GlobalIDs.swap(PendingMacroIDs.begin()[I].second); |
| 9060 | // Initialize the macro history from chained-PCHs ahead of module imports. |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 9061 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
Argyrios Kyrtzidis | 719736c | 2013-01-19 03:14:56 +0000 | [diff] [blame] | 9062 | ++IDIdx) { |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9063 | const PendingMacroInfo &Info = GlobalIDs[IDIdx]; |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 9064 | if (!Info.M->isModule()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9065 | resolvePendingMacro(II, Info); |
| 9066 | } |
| 9067 | // Handle module imports. |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 9068 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9069 | ++IDIdx) { |
| 9070 | const PendingMacroInfo &Info = GlobalIDs[IDIdx]; |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 9071 | if (Info.M->isModule()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9072 | resolvePendingMacro(II, Info); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9073 | } |
| 9074 | } |
| 9075 | PendingMacroIDs.clear(); |
Argyrios Kyrtzidis | 83a6e3b | 2013-02-16 00:48:59 +0000 | [diff] [blame] | 9076 | |
| 9077 | // Wire up the DeclContexts for Decls that we delayed setting until |
| 9078 | // recursive loading is completed. |
| 9079 | while (!PendingDeclContextInfos.empty()) { |
| 9080 | PendingDeclContextInfo Info = PendingDeclContextInfos.front(); |
| 9081 | PendingDeclContextInfos.pop_front(); |
| 9082 | DeclContext *SemaDC = cast<DeclContext>(GetDecl(Info.SemaDC)); |
| 9083 | DeclContext *LexicalDC = cast<DeclContext>(GetDecl(Info.LexicalDC)); |
| 9084 | Info.D->setDeclContextsImpl(SemaDC, LexicalDC, getContext()); |
| 9085 | } |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 9086 | |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 9087 | // Perform any pending declaration updates. |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 9088 | while (!PendingUpdateRecords.empty()) { |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 9089 | auto Update = PendingUpdateRecords.pop_back_val(); |
| 9090 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 9091 | loadDeclUpdateRecords(Update); |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 9092 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9093 | } |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 9094 | |
| 9095 | // At this point, all update records for loaded decls are in place, so any |
| 9096 | // fake class definitions should have become real. |
| 9097 | assert(PendingFakeDefinitionData.empty() && |
| 9098 | "faked up a class definition but never saw the real one"); |
| 9099 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9100 | // If we deserialized any C++ or Objective-C class definitions, any |
| 9101 | // Objective-C protocol definitions, or any redeclarable templates, make sure |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 9102 | // that all redeclarations point to the definitions. Note that this can only |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9103 | // happen now, after the redeclaration chains have been fully wired. |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9104 | for (Decl *D : PendingDefinitions) { |
| 9105 | if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
Richard Smith | 5b21db8 | 2014-04-23 18:20:42 +0000 | [diff] [blame] | 9106 | if (const TagType *TagT = dyn_cast<TagType>(TD->getTypeForDecl())) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9107 | // Make sure that the TagType points at the definition. |
| 9108 | const_cast<TagType*>(TagT)->decl = TD; |
| 9109 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9110 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9111 | if (auto RD = dyn_cast<CXXRecordDecl>(D)) { |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9112 | for (auto *R = getMostRecentExistingDecl(RD); R; |
| 9113 | R = R->getPreviousDecl()) { |
| 9114 | assert((R == D) == |
| 9115 | cast<CXXRecordDecl>(R)->isThisDeclarationADefinition() && |
Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 9116 | "declaration thinks it's the definition but it isn't"); |
Aaron Ballman | 86c9390 | 2014-03-06 23:45:36 +0000 | [diff] [blame] | 9117 | cast<CXXRecordDecl>(R)->DefinitionData = RD->DefinitionData; |
Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 9118 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9119 | } |
| 9120 | |
| 9121 | continue; |
| 9122 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9123 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9124 | if (auto ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9125 | // Make sure that the ObjCInterfaceType points at the definition. |
| 9126 | const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl)) |
| 9127 | ->Decl = ID; |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9128 | |
| 9129 | for (auto *R = getMostRecentExistingDecl(ID); R; R = R->getPreviousDecl()) |
| 9130 | cast<ObjCInterfaceDecl>(R)->Data = ID->Data; |
| 9131 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9132 | continue; |
| 9133 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9134 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9135 | if (auto PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9136 | for (auto *R = getMostRecentExistingDecl(PD); R; R = R->getPreviousDecl()) |
| 9137 | cast<ObjCProtocolDecl>(R)->Data = PD->Data; |
| 9138 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9139 | continue; |
| 9140 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9141 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9142 | auto RTD = cast<RedeclarableTemplateDecl>(D)->getCanonicalDecl(); |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9143 | for (auto *R = getMostRecentExistingDecl(RTD); R; R = R->getPreviousDecl()) |
| 9144 | cast<RedeclarableTemplateDecl>(R)->Common = RTD->Common; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9145 | } |
| 9146 | PendingDefinitions.clear(); |
| 9147 | |
| 9148 | // Load the bodies of any functions or methods we've encountered. We do |
| 9149 | // this now (delayed) so that we can be sure that the declaration chains |
Richard Smith | b9fa996 | 2015-08-21 03:04:33 +0000 | [diff] [blame] | 9150 | // have been fully wired up (hasBody relies on this). |
| 9151 | // FIXME: We shouldn't require complete redeclaration chains here. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9152 | for (PendingBodiesMap::iterator PB = PendingBodies.begin(), |
| 9153 | PBEnd = PendingBodies.end(); |
| 9154 | PB != PBEnd; ++PB) { |
| 9155 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(PB->first)) { |
| 9156 | // FIXME: Check for =delete/=default? |
| 9157 | // FIXME: Complain about ODR violations here? |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 9158 | const FunctionDecl *Defn = nullptr; |
David Blaikie | e6b7c28 | 2017-04-11 20:46:34 +0000 | [diff] [blame] | 9159 | if (!getContext().getLangOpts().Modules || !FD->hasBody(Defn)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9160 | FD->setLazyBody(PB->second); |
David Blaikie | e6b7c28 | 2017-04-11 20:46:34 +0000 | [diff] [blame] | 9161 | } else |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 9162 | mergeDefinitionVisibility(const_cast<FunctionDecl*>(Defn), FD); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9163 | continue; |
| 9164 | } |
| 9165 | |
| 9166 | ObjCMethodDecl *MD = cast<ObjCMethodDecl>(PB->first); |
| 9167 | if (!getContext().getLangOpts().Modules || !MD->hasBody()) |
| 9168 | MD->setLazyBody(PB->second); |
| 9169 | } |
| 9170 | PendingBodies.clear(); |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 9171 | |
| 9172 | // Do some cleanup. |
| 9173 | for (auto *ND : PendingMergedDefinitionsToDeduplicate) |
| 9174 | getContext().deduplicateMergedDefinitonsFor(ND); |
| 9175 | PendingMergedDefinitionsToDeduplicate.clear(); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9176 | } |
| 9177 | |
| 9178 | void ASTReader::diagnoseOdrViolations() { |
Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 9179 | if (PendingOdrMergeFailures.empty() && PendingOdrMergeChecks.empty()) |
| 9180 | return; |
| 9181 | |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9182 | // Trigger the import of the full definition of each class that had any |
| 9183 | // odr-merging problems, so we can produce better diagnostics for them. |
Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 9184 | // These updates may in turn find and diagnose some ODR failures, so take |
| 9185 | // ownership of the set first. |
| 9186 | auto OdrMergeFailures = std::move(PendingOdrMergeFailures); |
| 9187 | PendingOdrMergeFailures.clear(); |
| 9188 | for (auto &Merge : OdrMergeFailures) { |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9189 | Merge.first->buildLookup(); |
| 9190 | Merge.first->decls_begin(); |
| 9191 | Merge.first->bases_begin(); |
| 9192 | Merge.first->vbases_begin(); |
| 9193 | for (auto *RD : Merge.second) { |
| 9194 | RD->decls_begin(); |
| 9195 | RD->bases_begin(); |
| 9196 | RD->vbases_begin(); |
| 9197 | } |
| 9198 | } |
| 9199 | |
| 9200 | // For each declaration from a merged context, check that the canonical |
| 9201 | // definition of that context also contains a declaration of the same |
| 9202 | // entity. |
| 9203 | // |
| 9204 | // Caution: this loop does things that might invalidate iterators into |
| 9205 | // PendingOdrMergeChecks. Don't turn this into a range-based for loop! |
| 9206 | while (!PendingOdrMergeChecks.empty()) { |
| 9207 | NamedDecl *D = PendingOdrMergeChecks.pop_back_val(); |
| 9208 | |
| 9209 | // FIXME: Skip over implicit declarations for now. This matters for things |
| 9210 | // like implicitly-declared special member functions. This isn't entirely |
| 9211 | // correct; we can end up with multiple unmerged declarations of the same |
| 9212 | // implicit entity. |
| 9213 | if (D->isImplicit()) |
| 9214 | continue; |
| 9215 | |
| 9216 | DeclContext *CanonDef = D->getDeclContext(); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9217 | |
| 9218 | bool Found = false; |
| 9219 | const Decl *DCanon = D->getCanonicalDecl(); |
| 9220 | |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 9221 | for (auto RI : D->redecls()) { |
| 9222 | if (RI->getLexicalDeclContext() == CanonDef) { |
| 9223 | Found = true; |
| 9224 | break; |
| 9225 | } |
| 9226 | } |
| 9227 | if (Found) |
| 9228 | continue; |
| 9229 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9230 | // Quick check failed, time to do the slow thing. Note, we can't just |
| 9231 | // look up the name of D in CanonDef here, because the member that is |
| 9232 | // in CanonDef might not be found by name lookup (it might have been |
| 9233 | // replaced by a more recent declaration in the lookup table), and we |
| 9234 | // can't necessarily find it in the redeclaration chain because it might |
| 9235 | // be merely mergeable, not redeclarable. |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9236 | llvm::SmallVector<const NamedDecl*, 4> Candidates; |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9237 | for (auto *CanonMember : CanonDef->decls()) { |
| 9238 | if (CanonMember->getCanonicalDecl() == DCanon) { |
| 9239 | // This can happen if the declaration is merely mergeable and not |
| 9240 | // actually redeclarable (we looked for redeclarations earlier). |
| 9241 | // |
| 9242 | // FIXME: We should be able to detect this more efficiently, without |
| 9243 | // pulling in all of the members of CanonDef. |
| 9244 | Found = true; |
| 9245 | break; |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9246 | } |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9247 | if (auto *ND = dyn_cast<NamedDecl>(CanonMember)) |
| 9248 | if (ND->getDeclName() == D->getDeclName()) |
| 9249 | Candidates.push_back(ND); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9250 | } |
| 9251 | |
| 9252 | if (!Found) { |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 9253 | // The AST doesn't like TagDecls becoming invalid after they've been |
| 9254 | // completed. We only really need to mark FieldDecls as invalid here. |
| 9255 | if (!isa<TagDecl>(D)) |
| 9256 | D->setInvalidDecl(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 9257 | |
Richard Smith | 4ab3dbd | 2015-02-13 22:43:51 +0000 | [diff] [blame] | 9258 | // Ensure we don't accidentally recursively enter deserialization while |
| 9259 | // we're producing our diagnostic. |
| 9260 | Deserializing RecursionGuard(this); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9261 | |
| 9262 | std::string CanonDefModule = |
| 9263 | getOwningModuleNameForDiagnostic(cast<Decl>(CanonDef)); |
| 9264 | Diag(D->getLocation(), diag::err_module_odr_violation_missing_decl) |
| 9265 | << D << getOwningModuleNameForDiagnostic(D) |
| 9266 | << CanonDef << CanonDefModule.empty() << CanonDefModule; |
| 9267 | |
| 9268 | if (Candidates.empty()) |
| 9269 | Diag(cast<Decl>(CanonDef)->getLocation(), |
| 9270 | diag::note_module_odr_violation_no_possible_decls) << D; |
| 9271 | else { |
| 9272 | for (unsigned I = 0, N = Candidates.size(); I != N; ++I) |
| 9273 | Diag(Candidates[I]->getLocation(), |
| 9274 | diag::note_module_odr_violation_possible_decl) |
| 9275 | << Candidates[I]; |
| 9276 | } |
| 9277 | |
| 9278 | DiagnosedOdrMergeFailures.insert(CanonDef); |
| 9279 | } |
| 9280 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9281 | |
Richard Smith | 4ab3dbd | 2015-02-13 22:43:51 +0000 | [diff] [blame] | 9282 | if (OdrMergeFailures.empty()) |
| 9283 | return; |
| 9284 | |
| 9285 | // Ensure we don't accidentally recursively enter deserialization while |
| 9286 | // we're producing our diagnostics. |
| 9287 | Deserializing RecursionGuard(this); |
| 9288 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9289 | // Issue any pending ODR-failure diagnostics. |
Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 9290 | for (auto &Merge : OdrMergeFailures) { |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9291 | // If we've already pointed out a specific problem with this class, don't |
| 9292 | // bother issuing a general "something's different" diagnostic. |
David Blaikie | 82e95a3 | 2014-11-19 07:49:47 +0000 | [diff] [blame] | 9293 | if (!DiagnosedOdrMergeFailures.insert(Merge.first).second) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9294 | continue; |
| 9295 | |
| 9296 | bool Diagnosed = false; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9297 | CXXRecordDecl *FirstRecord = Merge.first; |
| 9298 | std::string FirstModule = getOwningModuleNameForDiagnostic(FirstRecord); |
| 9299 | for (CXXRecordDecl *SecondRecord : Merge.second) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9300 | // Multiple different declarations got merged together; tell the user |
| 9301 | // where they came from. |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9302 | if (FirstRecord == SecondRecord) |
| 9303 | continue; |
| 9304 | |
| 9305 | std::string SecondModule = getOwningModuleNameForDiagnostic(SecondRecord); |
| 9306 | using DeclHashes = llvm::SmallVector<std::pair<Decl *, unsigned>, 4>; |
Richard Trieu | 498117b | 2017-08-23 02:43:59 +0000 | [diff] [blame] | 9307 | |
| 9308 | const ClassTemplateDecl *FirstTemplate = |
| 9309 | FirstRecord->getDescribedClassTemplate(); |
| 9310 | const ClassTemplateDecl *SecondTemplate = |
| 9311 | SecondRecord->getDescribedClassTemplate(); |
| 9312 | |
| 9313 | assert(!FirstTemplate == !SecondTemplate && |
| 9314 | "Both pointers should be null or non-null"); |
| 9315 | |
| 9316 | enum ODRTemplateDifference { |
| 9317 | ParamEmptyName, |
| 9318 | ParamName, |
| 9319 | ParamSingleDefaultArgument, |
| 9320 | ParamDifferentDefaultArgument, |
| 9321 | }; |
| 9322 | |
| 9323 | if (FirstTemplate && SecondTemplate) { |
| 9324 | DeclHashes FirstTemplateHashes; |
| 9325 | DeclHashes SecondTemplateHashes; |
| 9326 | ODRHash Hash; |
| 9327 | |
| 9328 | auto PopulateTemplateParameterHashs = |
| 9329 | [&Hash](DeclHashes &Hashes, const ClassTemplateDecl *TD) { |
| 9330 | for (auto *D : TD->getTemplateParameters()->asArray()) { |
| 9331 | Hash.clear(); |
| 9332 | Hash.AddSubDecl(D); |
| 9333 | Hashes.emplace_back(D, Hash.CalculateHash()); |
| 9334 | } |
| 9335 | }; |
| 9336 | |
| 9337 | PopulateTemplateParameterHashs(FirstTemplateHashes, FirstTemplate); |
| 9338 | PopulateTemplateParameterHashs(SecondTemplateHashes, SecondTemplate); |
| 9339 | |
| 9340 | assert(FirstTemplateHashes.size() == SecondTemplateHashes.size() && |
| 9341 | "Number of template parameters should be equal."); |
| 9342 | |
| 9343 | auto FirstIt = FirstTemplateHashes.begin(); |
| 9344 | auto FirstEnd = FirstTemplateHashes.end(); |
| 9345 | auto SecondIt = SecondTemplateHashes.begin(); |
| 9346 | for (; FirstIt != FirstEnd; ++FirstIt, ++SecondIt) { |
| 9347 | if (FirstIt->second == SecondIt->second) |
| 9348 | continue; |
| 9349 | |
| 9350 | auto ODRDiagError = [FirstRecord, &FirstModule, |
| 9351 | this](SourceLocation Loc, SourceRange Range, |
| 9352 | ODRTemplateDifference DiffType) { |
| 9353 | return Diag(Loc, diag::err_module_odr_violation_template_parameter) |
| 9354 | << FirstRecord << FirstModule.empty() << FirstModule << Range |
| 9355 | << DiffType; |
| 9356 | }; |
| 9357 | auto ODRDiagNote = [&SecondModule, |
| 9358 | this](SourceLocation Loc, SourceRange Range, |
| 9359 | ODRTemplateDifference DiffType) { |
| 9360 | return Diag(Loc, diag::note_module_odr_violation_template_parameter) |
| 9361 | << SecondModule << Range << DiffType; |
| 9362 | }; |
| 9363 | |
| 9364 | const NamedDecl* FirstDecl = cast<NamedDecl>(FirstIt->first); |
| 9365 | const NamedDecl* SecondDecl = cast<NamedDecl>(SecondIt->first); |
| 9366 | |
| 9367 | assert(FirstDecl->getKind() == SecondDecl->getKind() && |
| 9368 | "Parameter Decl's should be the same kind."); |
| 9369 | |
| 9370 | DeclarationName FirstName = FirstDecl->getDeclName(); |
| 9371 | DeclarationName SecondName = SecondDecl->getDeclName(); |
| 9372 | |
| 9373 | if (FirstName != SecondName) { |
| 9374 | const bool FirstNameEmpty = |
| 9375 | FirstName.isIdentifier() && !FirstName.getAsIdentifierInfo(); |
| 9376 | const bool SecondNameEmpty = |
| 9377 | SecondName.isIdentifier() && !SecondName.getAsIdentifierInfo(); |
| 9378 | assert((!FirstNameEmpty || !SecondNameEmpty) && |
| 9379 | "Both template parameters cannot be unnamed."); |
| 9380 | ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(), |
| 9381 | FirstNameEmpty ? ParamEmptyName : ParamName) |
| 9382 | << FirstName; |
| 9383 | ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(), |
| 9384 | SecondNameEmpty ? ParamEmptyName : ParamName) |
| 9385 | << SecondName; |
| 9386 | break; |
| 9387 | } |
| 9388 | |
| 9389 | switch (FirstDecl->getKind()) { |
| 9390 | default: |
| 9391 | llvm_unreachable("Invalid template parameter type."); |
| 9392 | case Decl::TemplateTypeParm: { |
| 9393 | const auto *FirstParam = cast<TemplateTypeParmDecl>(FirstDecl); |
| 9394 | const auto *SecondParam = cast<TemplateTypeParmDecl>(SecondDecl); |
| 9395 | const bool HasFirstDefaultArgument = |
| 9396 | FirstParam->hasDefaultArgument() && |
| 9397 | !FirstParam->defaultArgumentWasInherited(); |
| 9398 | const bool HasSecondDefaultArgument = |
| 9399 | SecondParam->hasDefaultArgument() && |
| 9400 | !SecondParam->defaultArgumentWasInherited(); |
| 9401 | |
| 9402 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 9403 | ODRDiagError(FirstDecl->getLocation(), |
| 9404 | FirstDecl->getSourceRange(), |
| 9405 | ParamSingleDefaultArgument) |
| 9406 | << HasFirstDefaultArgument; |
| 9407 | ODRDiagNote(SecondDecl->getLocation(), |
| 9408 | SecondDecl->getSourceRange(), |
| 9409 | ParamSingleDefaultArgument) |
| 9410 | << HasSecondDefaultArgument; |
| 9411 | break; |
| 9412 | } |
| 9413 | |
| 9414 | assert(HasFirstDefaultArgument && HasSecondDefaultArgument && |
| 9415 | "Expecting default arguments."); |
| 9416 | |
| 9417 | ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(), |
| 9418 | ParamDifferentDefaultArgument); |
| 9419 | ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(), |
| 9420 | ParamDifferentDefaultArgument); |
| 9421 | |
| 9422 | break; |
| 9423 | } |
| 9424 | case Decl::NonTypeTemplateParm: { |
| 9425 | const auto *FirstParam = cast<NonTypeTemplateParmDecl>(FirstDecl); |
| 9426 | const auto *SecondParam = cast<NonTypeTemplateParmDecl>(SecondDecl); |
| 9427 | const bool HasFirstDefaultArgument = |
| 9428 | FirstParam->hasDefaultArgument() && |
| 9429 | !FirstParam->defaultArgumentWasInherited(); |
| 9430 | const bool HasSecondDefaultArgument = |
| 9431 | SecondParam->hasDefaultArgument() && |
| 9432 | !SecondParam->defaultArgumentWasInherited(); |
| 9433 | |
| 9434 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 9435 | ODRDiagError(FirstDecl->getLocation(), |
| 9436 | FirstDecl->getSourceRange(), |
| 9437 | ParamSingleDefaultArgument) |
| 9438 | << HasFirstDefaultArgument; |
| 9439 | ODRDiagNote(SecondDecl->getLocation(), |
| 9440 | SecondDecl->getSourceRange(), |
| 9441 | ParamSingleDefaultArgument) |
| 9442 | << HasSecondDefaultArgument; |
| 9443 | break; |
| 9444 | } |
| 9445 | |
| 9446 | assert(HasFirstDefaultArgument && HasSecondDefaultArgument && |
| 9447 | "Expecting default arguments."); |
| 9448 | |
| 9449 | ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(), |
| 9450 | ParamDifferentDefaultArgument); |
| 9451 | ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(), |
| 9452 | ParamDifferentDefaultArgument); |
| 9453 | |
| 9454 | break; |
| 9455 | } |
| 9456 | case Decl::TemplateTemplateParm: { |
| 9457 | const auto *FirstParam = cast<TemplateTemplateParmDecl>(FirstDecl); |
| 9458 | const auto *SecondParam = |
| 9459 | cast<TemplateTemplateParmDecl>(SecondDecl); |
| 9460 | const bool HasFirstDefaultArgument = |
| 9461 | FirstParam->hasDefaultArgument() && |
| 9462 | !FirstParam->defaultArgumentWasInherited(); |
| 9463 | const bool HasSecondDefaultArgument = |
| 9464 | SecondParam->hasDefaultArgument() && |
| 9465 | !SecondParam->defaultArgumentWasInherited(); |
| 9466 | |
| 9467 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 9468 | ODRDiagError(FirstDecl->getLocation(), |
| 9469 | FirstDecl->getSourceRange(), |
| 9470 | ParamSingleDefaultArgument) |
| 9471 | << HasFirstDefaultArgument; |
| 9472 | ODRDiagNote(SecondDecl->getLocation(), |
| 9473 | SecondDecl->getSourceRange(), |
| 9474 | ParamSingleDefaultArgument) |
| 9475 | << HasSecondDefaultArgument; |
| 9476 | break; |
| 9477 | } |
| 9478 | |
| 9479 | assert(HasFirstDefaultArgument && HasSecondDefaultArgument && |
| 9480 | "Expecting default arguments."); |
| 9481 | |
| 9482 | ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(), |
| 9483 | ParamDifferentDefaultArgument); |
| 9484 | ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(), |
| 9485 | ParamDifferentDefaultArgument); |
| 9486 | |
| 9487 | break; |
| 9488 | } |
| 9489 | } |
| 9490 | |
| 9491 | break; |
| 9492 | } |
| 9493 | |
| 9494 | if (FirstIt != FirstEnd) { |
| 9495 | Diagnosed = true; |
| 9496 | break; |
| 9497 | } |
| 9498 | } |
| 9499 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9500 | DeclHashes FirstHashes; |
| 9501 | DeclHashes SecondHashes; |
| 9502 | ODRHash Hash; |
| 9503 | |
| 9504 | auto PopulateHashes = [&Hash, FirstRecord](DeclHashes &Hashes, |
| 9505 | CXXRecordDecl *Record) { |
| 9506 | for (auto *D : Record->decls()) { |
| 9507 | // Due to decl merging, the first CXXRecordDecl is the parent of |
| 9508 | // Decls in both records. |
| 9509 | if (!ODRHash::isWhitelistedDecl(D, FirstRecord)) |
| 9510 | continue; |
| 9511 | Hash.clear(); |
| 9512 | Hash.AddSubDecl(D); |
| 9513 | Hashes.emplace_back(D, Hash.CalculateHash()); |
| 9514 | } |
| 9515 | }; |
| 9516 | PopulateHashes(FirstHashes, FirstRecord); |
| 9517 | PopulateHashes(SecondHashes, SecondRecord); |
| 9518 | |
| 9519 | // Used with err_module_odr_violation_mismatch_decl and |
| 9520 | // note_module_odr_violation_mismatch_decl |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 9521 | // This list should be the same Decl's as in ODRHash::isWhiteListedDecl |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9522 | enum { |
| 9523 | EndOfClass, |
| 9524 | PublicSpecifer, |
| 9525 | PrivateSpecifer, |
| 9526 | ProtectedSpecifer, |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9527 | StaticAssert, |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9528 | Field, |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9529 | CXXMethod, |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 9530 | TypeAlias, |
| 9531 | TypeDef, |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9532 | Var, |
Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 9533 | Friend, |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9534 | Other |
| 9535 | } FirstDiffType = Other, |
| 9536 | SecondDiffType = Other; |
| 9537 | |
| 9538 | auto DifferenceSelector = [](Decl *D) { |
| 9539 | assert(D && "valid Decl required"); |
| 9540 | switch (D->getKind()) { |
| 9541 | default: |
| 9542 | return Other; |
| 9543 | case Decl::AccessSpec: |
| 9544 | switch (D->getAccess()) { |
| 9545 | case AS_public: |
| 9546 | return PublicSpecifer; |
| 9547 | case AS_private: |
| 9548 | return PrivateSpecifer; |
| 9549 | case AS_protected: |
| 9550 | return ProtectedSpecifer; |
| 9551 | case AS_none: |
Simon Pilgrim | eeb1b30 | 2017-02-22 13:21:24 +0000 | [diff] [blame] | 9552 | break; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9553 | } |
Simon Pilgrim | eeb1b30 | 2017-02-22 13:21:24 +0000 | [diff] [blame] | 9554 | llvm_unreachable("Invalid access specifier"); |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9555 | case Decl::StaticAssert: |
| 9556 | return StaticAssert; |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9557 | case Decl::Field: |
| 9558 | return Field; |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9559 | case Decl::CXXMethod: |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9560 | case Decl::CXXConstructor: |
| 9561 | case Decl::CXXDestructor: |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9562 | return CXXMethod; |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 9563 | case Decl::TypeAlias: |
| 9564 | return TypeAlias; |
| 9565 | case Decl::Typedef: |
| 9566 | return TypeDef; |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9567 | case Decl::Var: |
| 9568 | return Var; |
Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 9569 | case Decl::Friend: |
| 9570 | return Friend; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9571 | } |
| 9572 | }; |
| 9573 | |
| 9574 | Decl *FirstDecl = nullptr; |
| 9575 | Decl *SecondDecl = nullptr; |
| 9576 | auto FirstIt = FirstHashes.begin(); |
| 9577 | auto SecondIt = SecondHashes.begin(); |
| 9578 | |
| 9579 | // If there is a diagnoseable difference, FirstDiffType and |
| 9580 | // SecondDiffType will not be Other and FirstDecl and SecondDecl will be |
| 9581 | // filled in if not EndOfClass. |
| 9582 | while (FirstIt != FirstHashes.end() || SecondIt != SecondHashes.end()) { |
Benjamin Kramer | 6f224d2 | 2017-02-22 10:19:45 +0000 | [diff] [blame] | 9583 | if (FirstIt != FirstHashes.end() && SecondIt != SecondHashes.end() && |
| 9584 | FirstIt->second == SecondIt->second) { |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9585 | ++FirstIt; |
| 9586 | ++SecondIt; |
| 9587 | continue; |
Richard Trieu | dc4cb02 | 2017-02-17 07:19:24 +0000 | [diff] [blame] | 9588 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9589 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9590 | FirstDecl = FirstIt == FirstHashes.end() ? nullptr : FirstIt->first; |
| 9591 | SecondDecl = SecondIt == SecondHashes.end() ? nullptr : SecondIt->first; |
| 9592 | |
| 9593 | FirstDiffType = FirstDecl ? DifferenceSelector(FirstDecl) : EndOfClass; |
| 9594 | SecondDiffType = |
| 9595 | SecondDecl ? DifferenceSelector(SecondDecl) : EndOfClass; |
| 9596 | |
| 9597 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9598 | } |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9599 | |
| 9600 | if (FirstDiffType == Other || SecondDiffType == Other) { |
| 9601 | // Reaching this point means an unexpected Decl was encountered |
| 9602 | // or no difference was detected. This causes a generic error |
| 9603 | // message to be emitted. |
| 9604 | Diag(FirstRecord->getLocation(), |
| 9605 | diag::err_module_odr_violation_different_definitions) |
| 9606 | << FirstRecord << FirstModule.empty() << FirstModule; |
| 9607 | |
Richard Trieu | ca48d36 | 2017-06-21 01:43:13 +0000 | [diff] [blame] | 9608 | if (FirstDecl) { |
| 9609 | Diag(FirstDecl->getLocation(), diag::note_first_module_difference) |
| 9610 | << FirstRecord << FirstDecl->getSourceRange(); |
| 9611 | } |
| 9612 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9613 | Diag(SecondRecord->getLocation(), |
| 9614 | diag::note_module_odr_violation_different_definitions) |
| 9615 | << SecondModule; |
Richard Trieu | ca48d36 | 2017-06-21 01:43:13 +0000 | [diff] [blame] | 9616 | |
| 9617 | if (SecondDecl) { |
| 9618 | Diag(SecondDecl->getLocation(), diag::note_second_module_difference) |
| 9619 | << SecondDecl->getSourceRange(); |
| 9620 | } |
| 9621 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9622 | Diagnosed = true; |
| 9623 | break; |
| 9624 | } |
| 9625 | |
| 9626 | if (FirstDiffType != SecondDiffType) { |
| 9627 | SourceLocation FirstLoc; |
| 9628 | SourceRange FirstRange; |
| 9629 | if (FirstDiffType == EndOfClass) { |
| 9630 | FirstLoc = FirstRecord->getBraceRange().getEnd(); |
| 9631 | } else { |
| 9632 | FirstLoc = FirstIt->first->getLocation(); |
| 9633 | FirstRange = FirstIt->first->getSourceRange(); |
| 9634 | } |
| 9635 | Diag(FirstLoc, diag::err_module_odr_violation_mismatch_decl) |
| 9636 | << FirstRecord << FirstModule.empty() << FirstModule << FirstRange |
| 9637 | << FirstDiffType; |
| 9638 | |
| 9639 | SourceLocation SecondLoc; |
| 9640 | SourceRange SecondRange; |
| 9641 | if (SecondDiffType == EndOfClass) { |
| 9642 | SecondLoc = SecondRecord->getBraceRange().getEnd(); |
| 9643 | } else { |
| 9644 | SecondLoc = SecondDecl->getLocation(); |
| 9645 | SecondRange = SecondDecl->getSourceRange(); |
| 9646 | } |
| 9647 | Diag(SecondLoc, diag::note_module_odr_violation_mismatch_decl) |
| 9648 | << SecondModule << SecondRange << SecondDiffType; |
| 9649 | Diagnosed = true; |
| 9650 | break; |
| 9651 | } |
| 9652 | |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9653 | assert(FirstDiffType == SecondDiffType); |
| 9654 | |
| 9655 | // Used with err_module_odr_violation_mismatch_decl_diff and |
| 9656 | // note_module_odr_violation_mismatch_decl_diff |
| 9657 | enum ODRDeclDifference{ |
| 9658 | StaticAssertCondition, |
| 9659 | StaticAssertMessage, |
| 9660 | StaticAssertOnlyMessage, |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9661 | FieldName, |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 9662 | FieldTypeName, |
Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 9663 | FieldSingleBitField, |
Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 9664 | FieldDifferentWidthBitField, |
| 9665 | FieldSingleMutable, |
| 9666 | FieldSingleInitializer, |
| 9667 | FieldDifferentInitializers, |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9668 | MethodName, |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9669 | MethodDeleted, |
| 9670 | MethodVirtual, |
| 9671 | MethodStatic, |
| 9672 | MethodVolatile, |
| 9673 | MethodConst, |
| 9674 | MethodInline, |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 9675 | MethodNumberParameters, |
| 9676 | MethodParameterType, |
| 9677 | MethodParameterName, |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9678 | MethodParameterSingleDefaultArgument, |
| 9679 | MethodParameterDifferentDefaultArgument, |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 9680 | TypedefName, |
| 9681 | TypedefType, |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9682 | VarName, |
| 9683 | VarType, |
| 9684 | VarSingleInitializer, |
| 9685 | VarDifferentInitializer, |
| 9686 | VarConstexpr, |
Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 9687 | FriendTypeFunction, |
| 9688 | FriendType, |
| 9689 | FriendFunction, |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9690 | }; |
| 9691 | |
| 9692 | // These lambdas have the common portions of the ODR diagnostics. This |
| 9693 | // has the same return as Diag(), so addition parameters can be passed |
| 9694 | // in with operator<< |
| 9695 | auto ODRDiagError = [FirstRecord, &FirstModule, this]( |
| 9696 | SourceLocation Loc, SourceRange Range, ODRDeclDifference DiffType) { |
| 9697 | return Diag(Loc, diag::err_module_odr_violation_mismatch_decl_diff) |
| 9698 | << FirstRecord << FirstModule.empty() << FirstModule << Range |
| 9699 | << DiffType; |
| 9700 | }; |
| 9701 | auto ODRDiagNote = [&SecondModule, this]( |
| 9702 | SourceLocation Loc, SourceRange Range, ODRDeclDifference DiffType) { |
| 9703 | return Diag(Loc, diag::note_module_odr_violation_mismatch_decl_diff) |
| 9704 | << SecondModule << Range << DiffType; |
| 9705 | }; |
| 9706 | |
| 9707 | auto ComputeODRHash = [&Hash](const Stmt* S) { |
| 9708 | assert(S); |
| 9709 | Hash.clear(); |
| 9710 | Hash.AddStmt(S); |
| 9711 | return Hash.CalculateHash(); |
| 9712 | }; |
| 9713 | |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 9714 | auto ComputeQualTypeODRHash = [&Hash](QualType Ty) { |
| 9715 | Hash.clear(); |
| 9716 | Hash.AddQualType(Ty); |
| 9717 | return Hash.CalculateHash(); |
| 9718 | }; |
| 9719 | |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9720 | switch (FirstDiffType) { |
| 9721 | case Other: |
| 9722 | case EndOfClass: |
| 9723 | case PublicSpecifer: |
| 9724 | case PrivateSpecifer: |
| 9725 | case ProtectedSpecifer: |
| 9726 | llvm_unreachable("Invalid diff type"); |
| 9727 | |
| 9728 | case StaticAssert: { |
| 9729 | StaticAssertDecl *FirstSA = cast<StaticAssertDecl>(FirstDecl); |
| 9730 | StaticAssertDecl *SecondSA = cast<StaticAssertDecl>(SecondDecl); |
| 9731 | |
| 9732 | Expr *FirstExpr = FirstSA->getAssertExpr(); |
| 9733 | Expr *SecondExpr = SecondSA->getAssertExpr(); |
| 9734 | unsigned FirstODRHash = ComputeODRHash(FirstExpr); |
| 9735 | unsigned SecondODRHash = ComputeODRHash(SecondExpr); |
| 9736 | if (FirstODRHash != SecondODRHash) { |
| 9737 | ODRDiagError(FirstExpr->getLocStart(), FirstExpr->getSourceRange(), |
| 9738 | StaticAssertCondition); |
| 9739 | ODRDiagNote(SecondExpr->getLocStart(), |
| 9740 | SecondExpr->getSourceRange(), StaticAssertCondition); |
| 9741 | Diagnosed = true; |
| 9742 | break; |
| 9743 | } |
| 9744 | |
| 9745 | StringLiteral *FirstStr = FirstSA->getMessage(); |
| 9746 | StringLiteral *SecondStr = SecondSA->getMessage(); |
| 9747 | assert((FirstStr || SecondStr) && "Both messages cannot be empty"); |
| 9748 | if ((FirstStr && !SecondStr) || (!FirstStr && SecondStr)) { |
| 9749 | SourceLocation FirstLoc, SecondLoc; |
| 9750 | SourceRange FirstRange, SecondRange; |
| 9751 | if (FirstStr) { |
| 9752 | FirstLoc = FirstStr->getLocStart(); |
| 9753 | FirstRange = FirstStr->getSourceRange(); |
| 9754 | } else { |
| 9755 | FirstLoc = FirstSA->getLocStart(); |
| 9756 | FirstRange = FirstSA->getSourceRange(); |
| 9757 | } |
| 9758 | if (SecondStr) { |
| 9759 | SecondLoc = SecondStr->getLocStart(); |
| 9760 | SecondRange = SecondStr->getSourceRange(); |
| 9761 | } else { |
| 9762 | SecondLoc = SecondSA->getLocStart(); |
| 9763 | SecondRange = SecondSA->getSourceRange(); |
| 9764 | } |
| 9765 | ODRDiagError(FirstLoc, FirstRange, StaticAssertOnlyMessage) |
| 9766 | << (FirstStr == nullptr); |
| 9767 | ODRDiagNote(SecondLoc, SecondRange, StaticAssertOnlyMessage) |
| 9768 | << (SecondStr == nullptr); |
| 9769 | Diagnosed = true; |
| 9770 | break; |
| 9771 | } |
| 9772 | |
| 9773 | if (FirstStr && SecondStr && |
| 9774 | FirstStr->getString() != SecondStr->getString()) { |
| 9775 | ODRDiagError(FirstStr->getLocStart(), FirstStr->getSourceRange(), |
| 9776 | StaticAssertMessage); |
| 9777 | ODRDiagNote(SecondStr->getLocStart(), SecondStr->getSourceRange(), |
| 9778 | StaticAssertMessage); |
| 9779 | Diagnosed = true; |
| 9780 | break; |
| 9781 | } |
| 9782 | break; |
| 9783 | } |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9784 | case Field: { |
| 9785 | FieldDecl *FirstField = cast<FieldDecl>(FirstDecl); |
| 9786 | FieldDecl *SecondField = cast<FieldDecl>(SecondDecl); |
| 9787 | IdentifierInfo *FirstII = FirstField->getIdentifier(); |
| 9788 | IdentifierInfo *SecondII = SecondField->getIdentifier(); |
| 9789 | if (FirstII->getName() != SecondII->getName()) { |
| 9790 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9791 | FieldName) |
| 9792 | << FirstII; |
| 9793 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9794 | FieldName) |
| 9795 | << SecondII; |
| 9796 | |
| 9797 | Diagnosed = true; |
| 9798 | break; |
| 9799 | } |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 9800 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 9801 | assert(getContext().hasSameType(FirstField->getType(), |
| 9802 | SecondField->getType())); |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 9803 | |
| 9804 | QualType FirstType = FirstField->getType(); |
| 9805 | QualType SecondType = SecondField->getType(); |
Richard Trieu | ce81b19 | 2017-05-17 03:23:35 +0000 | [diff] [blame] | 9806 | if (ComputeQualTypeODRHash(FirstType) != |
| 9807 | ComputeQualTypeODRHash(SecondType)) { |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 9808 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9809 | FieldTypeName) |
| 9810 | << FirstII << FirstType; |
| 9811 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9812 | FieldTypeName) |
| 9813 | << SecondII << SecondType; |
| 9814 | |
| 9815 | Diagnosed = true; |
| 9816 | break; |
| 9817 | } |
| 9818 | |
Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 9819 | const bool IsFirstBitField = FirstField->isBitField(); |
| 9820 | const bool IsSecondBitField = SecondField->isBitField(); |
| 9821 | if (IsFirstBitField != IsSecondBitField) { |
| 9822 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9823 | FieldSingleBitField) |
| 9824 | << FirstII << IsFirstBitField; |
| 9825 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9826 | FieldSingleBitField) |
| 9827 | << SecondII << IsSecondBitField; |
| 9828 | Diagnosed = true; |
| 9829 | break; |
| 9830 | } |
| 9831 | |
| 9832 | if (IsFirstBitField && IsSecondBitField) { |
| 9833 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9834 | FieldDifferentWidthBitField) |
| 9835 | << FirstII << FirstField->getBitWidth()->getSourceRange(); |
| 9836 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9837 | FieldDifferentWidthBitField) |
| 9838 | << SecondII << SecondField->getBitWidth()->getSourceRange(); |
| 9839 | Diagnosed = true; |
| 9840 | break; |
| 9841 | } |
| 9842 | |
Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 9843 | const bool IsFirstMutable = FirstField->isMutable(); |
| 9844 | const bool IsSecondMutable = SecondField->isMutable(); |
| 9845 | if (IsFirstMutable != IsSecondMutable) { |
| 9846 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9847 | FieldSingleMutable) |
| 9848 | << FirstII << IsFirstMutable; |
| 9849 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9850 | FieldSingleMutable) |
| 9851 | << SecondII << IsSecondMutable; |
| 9852 | Diagnosed = true; |
| 9853 | break; |
| 9854 | } |
| 9855 | |
| 9856 | const Expr *FirstInitializer = FirstField->getInClassInitializer(); |
| 9857 | const Expr *SecondInitializer = SecondField->getInClassInitializer(); |
| 9858 | if ((!FirstInitializer && SecondInitializer) || |
| 9859 | (FirstInitializer && !SecondInitializer)) { |
| 9860 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9861 | FieldSingleInitializer) |
| 9862 | << FirstII << (FirstInitializer != nullptr); |
| 9863 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9864 | FieldSingleInitializer) |
| 9865 | << SecondII << (SecondInitializer != nullptr); |
| 9866 | Diagnosed = true; |
| 9867 | break; |
| 9868 | } |
| 9869 | |
| 9870 | if (FirstInitializer && SecondInitializer) { |
| 9871 | unsigned FirstInitHash = ComputeODRHash(FirstInitializer); |
| 9872 | unsigned SecondInitHash = ComputeODRHash(SecondInitializer); |
| 9873 | if (FirstInitHash != SecondInitHash) { |
| 9874 | ODRDiagError(FirstField->getLocation(), |
| 9875 | FirstField->getSourceRange(), |
| 9876 | FieldDifferentInitializers) |
| 9877 | << FirstII << FirstInitializer->getSourceRange(); |
| 9878 | ODRDiagNote(SecondField->getLocation(), |
| 9879 | SecondField->getSourceRange(), |
| 9880 | FieldDifferentInitializers) |
| 9881 | << SecondII << SecondInitializer->getSourceRange(); |
| 9882 | Diagnosed = true; |
| 9883 | break; |
| 9884 | } |
| 9885 | } |
| 9886 | |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9887 | break; |
| 9888 | } |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9889 | case CXXMethod: { |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9890 | enum { |
| 9891 | DiagMethod, |
| 9892 | DiagConstructor, |
| 9893 | DiagDestructor, |
| 9894 | } FirstMethodType, |
| 9895 | SecondMethodType; |
| 9896 | auto GetMethodTypeForDiagnostics = [](const CXXMethodDecl* D) { |
| 9897 | if (isa<CXXConstructorDecl>(D)) return DiagConstructor; |
| 9898 | if (isa<CXXDestructorDecl>(D)) return DiagDestructor; |
| 9899 | return DiagMethod; |
| 9900 | }; |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9901 | const CXXMethodDecl *FirstMethod = cast<CXXMethodDecl>(FirstDecl); |
| 9902 | const CXXMethodDecl *SecondMethod = cast<CXXMethodDecl>(SecondDecl); |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9903 | FirstMethodType = GetMethodTypeForDiagnostics(FirstMethod); |
| 9904 | SecondMethodType = GetMethodTypeForDiagnostics(SecondMethod); |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9905 | auto FirstName = FirstMethod->getDeclName(); |
| 9906 | auto SecondName = SecondMethod->getDeclName(); |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9907 | if (FirstMethodType != SecondMethodType || FirstName != SecondName) { |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9908 | ODRDiagError(FirstMethod->getLocation(), |
| 9909 | FirstMethod->getSourceRange(), MethodName) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9910 | << FirstMethodType << FirstName; |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9911 | ODRDiagNote(SecondMethod->getLocation(), |
| 9912 | SecondMethod->getSourceRange(), MethodName) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9913 | << SecondMethodType << SecondName; |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9914 | |
| 9915 | Diagnosed = true; |
| 9916 | break; |
| 9917 | } |
| 9918 | |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9919 | const bool FirstDeleted = FirstMethod->isDeleted(); |
| 9920 | const bool SecondDeleted = SecondMethod->isDeleted(); |
| 9921 | if (FirstDeleted != SecondDeleted) { |
| 9922 | ODRDiagError(FirstMethod->getLocation(), |
| 9923 | FirstMethod->getSourceRange(), MethodDeleted) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9924 | << FirstMethodType << FirstName << FirstDeleted; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9925 | |
| 9926 | ODRDiagNote(SecondMethod->getLocation(), |
| 9927 | SecondMethod->getSourceRange(), MethodDeleted) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9928 | << SecondMethodType << SecondName << SecondDeleted; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9929 | Diagnosed = true; |
| 9930 | break; |
| 9931 | } |
| 9932 | |
| 9933 | const bool FirstVirtual = FirstMethod->isVirtualAsWritten(); |
| 9934 | const bool SecondVirtual = SecondMethod->isVirtualAsWritten(); |
| 9935 | const bool FirstPure = FirstMethod->isPure(); |
| 9936 | const bool SecondPure = SecondMethod->isPure(); |
| 9937 | if ((FirstVirtual || SecondVirtual) && |
| 9938 | (FirstVirtual != SecondVirtual || FirstPure != SecondPure)) { |
| 9939 | ODRDiagError(FirstMethod->getLocation(), |
| 9940 | FirstMethod->getSourceRange(), MethodVirtual) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9941 | << FirstMethodType << FirstName << FirstPure << FirstVirtual; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9942 | ODRDiagNote(SecondMethod->getLocation(), |
| 9943 | SecondMethod->getSourceRange(), MethodVirtual) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9944 | << SecondMethodType << SecondName << SecondPure << SecondVirtual; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9945 | Diagnosed = true; |
| 9946 | break; |
| 9947 | } |
| 9948 | |
| 9949 | // CXXMethodDecl::isStatic uses the canonical Decl. With Decl merging, |
| 9950 | // FirstDecl is the canonical Decl of SecondDecl, so the storage |
| 9951 | // class needs to be checked instead. |
| 9952 | const auto FirstStorage = FirstMethod->getStorageClass(); |
| 9953 | const auto SecondStorage = SecondMethod->getStorageClass(); |
| 9954 | const bool FirstStatic = FirstStorage == SC_Static; |
| 9955 | const bool SecondStatic = SecondStorage == SC_Static; |
| 9956 | if (FirstStatic != SecondStatic) { |
| 9957 | ODRDiagError(FirstMethod->getLocation(), |
| 9958 | FirstMethod->getSourceRange(), MethodStatic) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9959 | << FirstMethodType << FirstName << FirstStatic; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9960 | ODRDiagNote(SecondMethod->getLocation(), |
| 9961 | SecondMethod->getSourceRange(), MethodStatic) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9962 | << SecondMethodType << SecondName << SecondStatic; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9963 | Diagnosed = true; |
| 9964 | break; |
| 9965 | } |
| 9966 | |
| 9967 | const bool FirstVolatile = FirstMethod->isVolatile(); |
| 9968 | const bool SecondVolatile = SecondMethod->isVolatile(); |
| 9969 | if (FirstVolatile != SecondVolatile) { |
| 9970 | ODRDiagError(FirstMethod->getLocation(), |
| 9971 | FirstMethod->getSourceRange(), MethodVolatile) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9972 | << FirstMethodType << FirstName << FirstVolatile; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9973 | ODRDiagNote(SecondMethod->getLocation(), |
| 9974 | SecondMethod->getSourceRange(), MethodVolatile) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9975 | << SecondMethodType << SecondName << SecondVolatile; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9976 | Diagnosed = true; |
| 9977 | break; |
| 9978 | } |
| 9979 | |
| 9980 | const bool FirstConst = FirstMethod->isConst(); |
| 9981 | const bool SecondConst = SecondMethod->isConst(); |
| 9982 | if (FirstConst != SecondConst) { |
| 9983 | ODRDiagError(FirstMethod->getLocation(), |
| 9984 | FirstMethod->getSourceRange(), MethodConst) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9985 | << FirstMethodType << FirstName << FirstConst; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9986 | ODRDiagNote(SecondMethod->getLocation(), |
| 9987 | SecondMethod->getSourceRange(), MethodConst) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9988 | << SecondMethodType << SecondName << SecondConst; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9989 | Diagnosed = true; |
| 9990 | break; |
| 9991 | } |
| 9992 | |
| 9993 | const bool FirstInline = FirstMethod->isInlineSpecified(); |
| 9994 | const bool SecondInline = SecondMethod->isInlineSpecified(); |
| 9995 | if (FirstInline != SecondInline) { |
| 9996 | ODRDiagError(FirstMethod->getLocation(), |
| 9997 | FirstMethod->getSourceRange(), MethodInline) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9998 | << FirstMethodType << FirstName << FirstInline; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9999 | ODRDiagNote(SecondMethod->getLocation(), |
| 10000 | SecondMethod->getSourceRange(), MethodInline) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10001 | << SecondMethodType << SecondName << SecondInline; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10002 | Diagnosed = true; |
| 10003 | break; |
| 10004 | } |
| 10005 | |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10006 | const unsigned FirstNumParameters = FirstMethod->param_size(); |
| 10007 | const unsigned SecondNumParameters = SecondMethod->param_size(); |
| 10008 | if (FirstNumParameters != SecondNumParameters) { |
| 10009 | ODRDiagError(FirstMethod->getLocation(), |
| 10010 | FirstMethod->getSourceRange(), MethodNumberParameters) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10011 | << FirstMethodType << FirstName << FirstNumParameters; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10012 | ODRDiagNote(SecondMethod->getLocation(), |
| 10013 | SecondMethod->getSourceRange(), MethodNumberParameters) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10014 | << SecondMethodType << SecondName << SecondNumParameters; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10015 | Diagnosed = true; |
| 10016 | break; |
| 10017 | } |
| 10018 | |
| 10019 | // Need this status boolean to know when break out of the switch. |
| 10020 | bool ParameterMismatch = false; |
| 10021 | for (unsigned I = 0; I < FirstNumParameters; ++I) { |
| 10022 | const ParmVarDecl *FirstParam = FirstMethod->getParamDecl(I); |
| 10023 | const ParmVarDecl *SecondParam = SecondMethod->getParamDecl(I); |
| 10024 | |
| 10025 | QualType FirstParamType = FirstParam->getType(); |
| 10026 | QualType SecondParamType = SecondParam->getType(); |
| 10027 | if (FirstParamType != SecondParamType && |
| 10028 | ComputeQualTypeODRHash(FirstParamType) != |
| 10029 | ComputeQualTypeODRHash(SecondParamType)) { |
| 10030 | if (const DecayedType *ParamDecayedType = |
| 10031 | FirstParamType->getAs<DecayedType>()) { |
| 10032 | ODRDiagError(FirstMethod->getLocation(), |
| 10033 | FirstMethod->getSourceRange(), MethodParameterType) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10034 | << FirstMethodType << FirstName << (I + 1) << FirstParamType |
| 10035 | << true << ParamDecayedType->getOriginalType(); |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10036 | } else { |
| 10037 | ODRDiagError(FirstMethod->getLocation(), |
| 10038 | FirstMethod->getSourceRange(), MethodParameterType) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10039 | << FirstMethodType << FirstName << (I + 1) << FirstParamType |
| 10040 | << false; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10041 | } |
| 10042 | |
| 10043 | if (const DecayedType *ParamDecayedType = |
| 10044 | SecondParamType->getAs<DecayedType>()) { |
| 10045 | ODRDiagNote(SecondMethod->getLocation(), |
| 10046 | SecondMethod->getSourceRange(), MethodParameterType) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10047 | << SecondMethodType << SecondName << (I + 1) |
| 10048 | << SecondParamType << true |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10049 | << ParamDecayedType->getOriginalType(); |
| 10050 | } else { |
| 10051 | ODRDiagNote(SecondMethod->getLocation(), |
| 10052 | SecondMethod->getSourceRange(), MethodParameterType) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10053 | << SecondMethodType << SecondName << (I + 1) |
| 10054 | << SecondParamType << false; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10055 | } |
| 10056 | ParameterMismatch = true; |
| 10057 | break; |
| 10058 | } |
| 10059 | |
| 10060 | DeclarationName FirstParamName = FirstParam->getDeclName(); |
| 10061 | DeclarationName SecondParamName = SecondParam->getDeclName(); |
| 10062 | if (FirstParamName != SecondParamName) { |
| 10063 | ODRDiagError(FirstMethod->getLocation(), |
| 10064 | FirstMethod->getSourceRange(), MethodParameterName) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10065 | << FirstMethodType << FirstName << (I + 1) << FirstParamName; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10066 | ODRDiagNote(SecondMethod->getLocation(), |
| 10067 | SecondMethod->getSourceRange(), MethodParameterName) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10068 | << SecondMethodType << SecondName << (I + 1) << SecondParamName; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10069 | ParameterMismatch = true; |
| 10070 | break; |
| 10071 | } |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10072 | |
| 10073 | const Expr *FirstInit = FirstParam->getInit(); |
| 10074 | const Expr *SecondInit = SecondParam->getInit(); |
| 10075 | if ((FirstInit == nullptr) != (SecondInit == nullptr)) { |
| 10076 | ODRDiagError(FirstMethod->getLocation(), |
| 10077 | FirstMethod->getSourceRange(), |
| 10078 | MethodParameterSingleDefaultArgument) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10079 | << FirstMethodType << FirstName << (I + 1) |
| 10080 | << (FirstInit == nullptr) |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10081 | << (FirstInit ? FirstInit->getSourceRange() : SourceRange()); |
| 10082 | ODRDiagNote(SecondMethod->getLocation(), |
| 10083 | SecondMethod->getSourceRange(), |
| 10084 | MethodParameterSingleDefaultArgument) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10085 | << SecondMethodType << SecondName << (I + 1) |
| 10086 | << (SecondInit == nullptr) |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10087 | << (SecondInit ? SecondInit->getSourceRange() : SourceRange()); |
| 10088 | ParameterMismatch = true; |
| 10089 | break; |
| 10090 | } |
| 10091 | |
| 10092 | if (FirstInit && SecondInit && |
| 10093 | ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) { |
| 10094 | ODRDiagError(FirstMethod->getLocation(), |
| 10095 | FirstMethod->getSourceRange(), |
| 10096 | MethodParameterDifferentDefaultArgument) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10097 | << FirstMethodType << FirstName << (I + 1) |
| 10098 | << FirstInit->getSourceRange(); |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10099 | ODRDiagNote(SecondMethod->getLocation(), |
| 10100 | SecondMethod->getSourceRange(), |
| 10101 | MethodParameterDifferentDefaultArgument) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10102 | << SecondMethodType << SecondName << (I + 1) |
| 10103 | << SecondInit->getSourceRange(); |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10104 | ParameterMismatch = true; |
| 10105 | break; |
| 10106 | |
| 10107 | } |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10108 | } |
| 10109 | |
| 10110 | if (ParameterMismatch) { |
| 10111 | Diagnosed = true; |
| 10112 | break; |
| 10113 | } |
| 10114 | |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10115 | break; |
| 10116 | } |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 10117 | case TypeAlias: |
| 10118 | case TypeDef: { |
| 10119 | TypedefNameDecl *FirstTD = cast<TypedefNameDecl>(FirstDecl); |
| 10120 | TypedefNameDecl *SecondTD = cast<TypedefNameDecl>(SecondDecl); |
| 10121 | auto FirstName = FirstTD->getDeclName(); |
| 10122 | auto SecondName = SecondTD->getDeclName(); |
| 10123 | if (FirstName != SecondName) { |
| 10124 | ODRDiagError(FirstTD->getLocation(), FirstTD->getSourceRange(), |
| 10125 | TypedefName) |
| 10126 | << (FirstDiffType == TypeAlias) << FirstName; |
| 10127 | ODRDiagNote(SecondTD->getLocation(), SecondTD->getSourceRange(), |
| 10128 | TypedefName) |
| 10129 | << (FirstDiffType == TypeAlias) << SecondName; |
| 10130 | Diagnosed = true; |
| 10131 | break; |
| 10132 | } |
| 10133 | |
| 10134 | QualType FirstType = FirstTD->getUnderlyingType(); |
| 10135 | QualType SecondType = SecondTD->getUnderlyingType(); |
| 10136 | if (ComputeQualTypeODRHash(FirstType) != |
| 10137 | ComputeQualTypeODRHash(SecondType)) { |
| 10138 | ODRDiagError(FirstTD->getLocation(), FirstTD->getSourceRange(), |
| 10139 | TypedefType) |
| 10140 | << (FirstDiffType == TypeAlias) << FirstName << FirstType; |
| 10141 | ODRDiagNote(SecondTD->getLocation(), SecondTD->getSourceRange(), |
| 10142 | TypedefType) |
| 10143 | << (FirstDiffType == TypeAlias) << SecondName << SecondType; |
| 10144 | Diagnosed = true; |
| 10145 | break; |
| 10146 | } |
| 10147 | break; |
| 10148 | } |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10149 | case Var: { |
| 10150 | VarDecl *FirstVD = cast<VarDecl>(FirstDecl); |
| 10151 | VarDecl *SecondVD = cast<VarDecl>(SecondDecl); |
| 10152 | auto FirstName = FirstVD->getDeclName(); |
| 10153 | auto SecondName = SecondVD->getDeclName(); |
| 10154 | if (FirstName != SecondName) { |
| 10155 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 10156 | VarName) |
| 10157 | << FirstName; |
| 10158 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 10159 | VarName) |
| 10160 | << SecondName; |
| 10161 | Diagnosed = true; |
| 10162 | break; |
| 10163 | } |
| 10164 | |
| 10165 | QualType FirstType = FirstVD->getType(); |
| 10166 | QualType SecondType = SecondVD->getType(); |
| 10167 | if (ComputeQualTypeODRHash(FirstType) != |
| 10168 | ComputeQualTypeODRHash(SecondType)) { |
| 10169 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 10170 | VarType) |
| 10171 | << FirstName << FirstType; |
| 10172 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 10173 | VarType) |
| 10174 | << SecondName << SecondType; |
| 10175 | Diagnosed = true; |
| 10176 | break; |
| 10177 | } |
| 10178 | |
| 10179 | const Expr *FirstInit = FirstVD->getInit(); |
| 10180 | const Expr *SecondInit = SecondVD->getInit(); |
| 10181 | if ((FirstInit == nullptr) != (SecondInit == nullptr)) { |
| 10182 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 10183 | VarSingleInitializer) |
| 10184 | << FirstName << (FirstInit == nullptr) |
| 10185 | << (FirstInit ? FirstInit->getSourceRange(): SourceRange()); |
| 10186 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 10187 | VarSingleInitializer) |
| 10188 | << SecondName << (SecondInit == nullptr) |
| 10189 | << (SecondInit ? SecondInit->getSourceRange() : SourceRange()); |
| 10190 | Diagnosed = true; |
| 10191 | break; |
| 10192 | } |
| 10193 | |
| 10194 | if (FirstInit && SecondInit && |
| 10195 | ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) { |
| 10196 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 10197 | VarDifferentInitializer) |
| 10198 | << FirstName << FirstInit->getSourceRange(); |
| 10199 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 10200 | VarDifferentInitializer) |
| 10201 | << SecondName << SecondInit->getSourceRange(); |
| 10202 | Diagnosed = true; |
| 10203 | break; |
| 10204 | } |
| 10205 | |
| 10206 | const bool FirstIsConstexpr = FirstVD->isConstexpr(); |
| 10207 | const bool SecondIsConstexpr = SecondVD->isConstexpr(); |
| 10208 | if (FirstIsConstexpr != SecondIsConstexpr) { |
| 10209 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 10210 | VarConstexpr) |
| 10211 | << FirstName << FirstIsConstexpr; |
| 10212 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 10213 | VarConstexpr) |
| 10214 | << SecondName << SecondIsConstexpr; |
| 10215 | Diagnosed = true; |
| 10216 | break; |
| 10217 | } |
| 10218 | break; |
| 10219 | } |
Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 10220 | case Friend: { |
| 10221 | FriendDecl *FirstFriend = cast<FriendDecl>(FirstDecl); |
| 10222 | FriendDecl *SecondFriend = cast<FriendDecl>(SecondDecl); |
| 10223 | |
| 10224 | NamedDecl *FirstND = FirstFriend->getFriendDecl(); |
| 10225 | NamedDecl *SecondND = SecondFriend->getFriendDecl(); |
| 10226 | |
| 10227 | TypeSourceInfo *FirstTSI = FirstFriend->getFriendType(); |
| 10228 | TypeSourceInfo *SecondTSI = SecondFriend->getFriendType(); |
| 10229 | |
| 10230 | if (FirstND && SecondND) { |
| 10231 | ODRDiagError(FirstFriend->getFriendLoc(), |
| 10232 | FirstFriend->getSourceRange(), FriendFunction) |
| 10233 | << FirstND; |
| 10234 | ODRDiagNote(SecondFriend->getFriendLoc(), |
| 10235 | SecondFriend->getSourceRange(), FriendFunction) |
| 10236 | << SecondND; |
| 10237 | |
| 10238 | Diagnosed = true; |
| 10239 | break; |
| 10240 | } |
| 10241 | |
| 10242 | if (FirstTSI && SecondTSI) { |
| 10243 | QualType FirstFriendType = FirstTSI->getType(); |
| 10244 | QualType SecondFriendType = SecondTSI->getType(); |
| 10245 | assert(ComputeQualTypeODRHash(FirstFriendType) != |
| 10246 | ComputeQualTypeODRHash(SecondFriendType)); |
| 10247 | ODRDiagError(FirstFriend->getFriendLoc(), |
| 10248 | FirstFriend->getSourceRange(), FriendType) |
| 10249 | << FirstFriendType; |
| 10250 | ODRDiagNote(SecondFriend->getFriendLoc(), |
| 10251 | SecondFriend->getSourceRange(), FriendType) |
| 10252 | << SecondFriendType; |
| 10253 | Diagnosed = true; |
| 10254 | break; |
| 10255 | } |
| 10256 | |
| 10257 | ODRDiagError(FirstFriend->getFriendLoc(), FirstFriend->getSourceRange(), |
| 10258 | FriendTypeFunction) |
| 10259 | << (FirstTSI == nullptr); |
| 10260 | ODRDiagNote(SecondFriend->getFriendLoc(), |
| 10261 | SecondFriend->getSourceRange(), FriendTypeFunction) |
| 10262 | << (SecondTSI == nullptr); |
| 10263 | |
| 10264 | Diagnosed = true; |
| 10265 | break; |
| 10266 | } |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10267 | } |
| 10268 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 10269 | if (Diagnosed == true) |
| 10270 | continue; |
| 10271 | |
Richard Trieu | 708859a | 2017-06-08 00:56:21 +0000 | [diff] [blame] | 10272 | Diag(FirstDecl->getLocation(), |
| 10273 | diag::err_module_odr_violation_mismatch_decl_unknown) |
| 10274 | << FirstRecord << FirstModule.empty() << FirstModule << FirstDiffType |
| 10275 | << FirstDecl->getSourceRange(); |
| 10276 | Diag(SecondDecl->getLocation(), |
| 10277 | diag::note_module_odr_violation_mismatch_decl_unknown) |
| 10278 | << SecondModule << FirstDiffType << SecondDecl->getSourceRange(); |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 10279 | Diagnosed = true; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 10280 | } |
| 10281 | |
| 10282 | if (!Diagnosed) { |
| 10283 | // All definitions are updates to the same declaration. This happens if a |
| 10284 | // module instantiates the declaration of a class template specialization |
| 10285 | // and two or more other modules instantiate its definition. |
| 10286 | // |
| 10287 | // FIXME: Indicate which modules had instantiations of this definition. |
| 10288 | // FIXME: How can this even happen? |
| 10289 | Diag(Merge.first->getLocation(), |
| 10290 | diag::err_module_odr_violation_different_instantiations) |
| 10291 | << Merge.first; |
| 10292 | } |
| 10293 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10294 | } |
| 10295 | |
Richard Smith | ce18a18 | 2015-07-14 00:26:00 +0000 | [diff] [blame] | 10296 | void ASTReader::StartedDeserializing() { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 10297 | if (++NumCurrentElementsDeserializing == 1 && ReadTimer.get()) |
Richard Smith | ce18a18 | 2015-07-14 00:26:00 +0000 | [diff] [blame] | 10298 | ReadTimer->startTimer(); |
| 10299 | } |
| 10300 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10301 | void ASTReader::FinishedDeserializing() { |
| 10302 | assert(NumCurrentElementsDeserializing && |
| 10303 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 10304 | if (NumCurrentElementsDeserializing == 1) { |
| 10305 | // We decrease NumCurrentElementsDeserializing only after pending actions |
| 10306 | // are finished, to avoid recursively re-calling finishPendingActions(). |
| 10307 | finishPendingActions(); |
| 10308 | } |
| 10309 | --NumCurrentElementsDeserializing; |
| 10310 | |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 10311 | if (NumCurrentElementsDeserializing == 0) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 10312 | // Propagate exception specification updates along redeclaration chains. |
Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 10313 | while (!PendingExceptionSpecUpdates.empty()) { |
| 10314 | auto Updates = std::move(PendingExceptionSpecUpdates); |
| 10315 | PendingExceptionSpecUpdates.clear(); |
| 10316 | for (auto Update : Updates) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 10317 | ProcessingUpdatesRAIIObj ProcessingUpdates(*this); |
Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 10318 | auto *FPT = Update.second->getType()->castAs<FunctionProtoType>(); |
Richard Smith | 1d0f199 | 2015-08-19 21:09:32 +0000 | [diff] [blame] | 10319 | auto ESI = FPT->getExtProtoInfo().ExceptionSpec; |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 10320 | if (auto *Listener = getContext().getASTMutationListener()) |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 10321 | Listener->ResolvedExceptionSpec(cast<FunctionDecl>(Update.second)); |
Richard Smith | 1d0f199 | 2015-08-19 21:09:32 +0000 | [diff] [blame] | 10322 | for (auto *Redecl : Update.second->redecls()) |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 10323 | getContext().adjustExceptionSpec(cast<FunctionDecl>(Redecl), ESI); |
Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 10324 | } |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 10325 | } |
| 10326 | |
Richard Smith | ce18a18 | 2015-07-14 00:26:00 +0000 | [diff] [blame] | 10327 | if (ReadTimer) |
| 10328 | ReadTimer->stopTimer(); |
| 10329 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 10330 | diagnoseOdrViolations(); |
| 10331 | |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 10332 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 10333 | // decls to the consumer. |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 10334 | if (Consumer) |
| 10335 | PassInterestingDeclsToConsumer(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10336 | } |
| 10337 | } |
| 10338 | |
Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 10339 | void ASTReader::pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 10340 | if (IdentifierInfo *II = Name.getAsIdentifierInfo()) { |
| 10341 | // Remove any fake results before adding any real ones. |
| 10342 | auto It = PendingFakeLookupResults.find(II); |
| 10343 | if (It != PendingFakeLookupResults.end()) { |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 10344 | for (auto *ND : It->second) |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 10345 | SemaObj->IdResolver.RemoveDecl(ND); |
Ben Langmuir | eb8bd2d | 2015-04-10 22:25:42 +0000 | [diff] [blame] | 10346 | // FIXME: this works around module+PCH performance issue. |
| 10347 | // Rather than erase the result from the map, which is O(n), just clear |
| 10348 | // the vector of NamedDecls. |
| 10349 | It->second.clear(); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 10350 | } |
| 10351 | } |
Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 10352 | |
| 10353 | if (SemaObj->IdResolver.tryAddTopLevelDecl(D, Name) && SemaObj->TUScope) { |
| 10354 | SemaObj->TUScope->AddDecl(D); |
| 10355 | } else if (SemaObj->TUScope) { |
| 10356 | // Adding the decl to IdResolver may have failed because it was already in |
| 10357 | // (even though it was not added in scope). If it is already in, make sure |
| 10358 | // it gets in the scope as well. |
| 10359 | if (std::find(SemaObj->IdResolver.begin(Name), |
| 10360 | SemaObj->IdResolver.end(), D) != SemaObj->IdResolver.end()) |
| 10361 | SemaObj->TUScope->AddDecl(D); |
| 10362 | } |
| 10363 | } |
| 10364 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 10365 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 10366 | const PCHContainerReader &PCHContainerRdr, |
| 10367 | ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, |
| 10368 | StringRef isysroot, bool DisableValidation, |
| 10369 | bool AllowASTWithCompilerErrors, |
| 10370 | bool AllowConfigurationMismatch, bool ValidateSystemInputs, |
| 10371 | bool UseGlobalIndex, |
| 10372 | std::unique_ptr<llvm::Timer> ReadTimer) |
| 10373 | : Listener(DisableValidation |
| 10374 | ? cast<ASTReaderListener>(new SimpleASTReaderListener(PP)) |
| 10375 | : cast<ASTReaderListener>(new PCHValidator(PP, *this))), |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 10376 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
David Blaikie | 9d7c1ba | 2017-01-05 18:45:43 +0000 | [diff] [blame] | 10377 | PCHContainerRdr(PCHContainerRdr), Diags(PP.getDiagnostics()), PP(PP), |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 10378 | ContextObj(Context), |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 10379 | ModuleMgr(PP.getFileManager(), PP.getPCMCache(), PCHContainerRdr, |
| 10380 | PP.getHeaderSearchInfo()), |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 10381 | PCMCache(PP.getPCMCache()), DummyIdResolver(PP), |
| 10382 | ReadTimer(std::move(ReadTimer)), isysroot(isysroot), |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 10383 | DisableValidation(DisableValidation), |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 10384 | AllowASTWithCompilerErrors(AllowASTWithCompilerErrors), |
| 10385 | AllowConfigurationMismatch(AllowConfigurationMismatch), |
| 10386 | ValidateSystemInputs(ValidateSystemInputs), |
David Blaikie | 9d7c1ba | 2017-01-05 18:45:43 +0000 | [diff] [blame] | 10387 | UseGlobalIndex(UseGlobalIndex), CurrSwitchCaseStmts(&SwitchCaseStmts) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10388 | SourceMgr.setExternalSLocEntrySource(this); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 10389 | |
| 10390 | for (const auto &Ext : Extensions) { |
| 10391 | auto BlockName = Ext->getExtensionMetadata().BlockName; |
| 10392 | auto Known = ModuleFileExtensions.find(BlockName); |
| 10393 | if (Known != ModuleFileExtensions.end()) { |
| 10394 | Diags.Report(diag::warn_duplicate_module_file_extension) |
| 10395 | << BlockName; |
| 10396 | continue; |
| 10397 | } |
| 10398 | |
| 10399 | ModuleFileExtensions.insert({BlockName, Ext}); |
| 10400 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10401 | } |
| 10402 | |
| 10403 | ASTReader::~ASTReader() { |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 10404 | if (OwnsDeserializationListener) |
| 10405 | delete DeserializationListener; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10406 | } |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 10407 | |
| 10408 | IdentifierResolver &ASTReader::getIdResolver() { |
| 10409 | return SemaObj ? SemaObj->IdResolver : DummyIdResolver; |
| 10410 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 10411 | |
| 10412 | unsigned ASTRecordReader::readRecord(llvm::BitstreamCursor &Cursor, |
| 10413 | unsigned AbbrevID) { |
| 10414 | Idx = 0; |
| 10415 | Record.clear(); |
| 10416 | return Cursor.readRecord(AbbrevID, Record); |
| 10417 | } |