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 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 295 | return false; |
| 296 | } |
| 297 | |
| 298 | /// \brief Compare the given set of target options against an existing set of |
| 299 | /// target options. |
| 300 | /// |
| 301 | /// \param Diags If non-NULL, diagnostics will be emitted via this engine. |
| 302 | /// |
| 303 | /// \returns true if the target options mis-match, false otherwise. |
| 304 | static bool checkTargetOptions(const TargetOptions &TargetOpts, |
| 305 | const TargetOptions &ExistingTargetOpts, |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 306 | DiagnosticsEngine *Diags, |
| 307 | bool AllowCompatibleDifferences = true) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 308 | #define CHECK_TARGET_OPT(Field, Name) \ |
| 309 | if (TargetOpts.Field != ExistingTargetOpts.Field) { \ |
| 310 | if (Diags) \ |
| 311 | Diags->Report(diag::err_pch_targetopt_mismatch) \ |
| 312 | << Name << TargetOpts.Field << ExistingTargetOpts.Field; \ |
| 313 | return true; \ |
| 314 | } |
| 315 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 316 | // The triple and ABI must match exactly. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 317 | CHECK_TARGET_OPT(Triple, "target"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 318 | CHECK_TARGET_OPT(ABI, "target ABI"); |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 319 | |
| 320 | // We can tolerate different CPUs in many cases, notably when one CPU |
| 321 | // supports a strict superset of another. When allowing compatible |
| 322 | // differences skip this check. |
| 323 | if (!AllowCompatibleDifferences) |
| 324 | CHECK_TARGET_OPT(CPU, "target CPU"); |
| 325 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 326 | #undef CHECK_TARGET_OPT |
| 327 | |
| 328 | // Compare feature sets. |
| 329 | SmallVector<StringRef, 4> ExistingFeatures( |
| 330 | ExistingTargetOpts.FeaturesAsWritten.begin(), |
| 331 | ExistingTargetOpts.FeaturesAsWritten.end()); |
| 332 | SmallVector<StringRef, 4> ReadFeatures(TargetOpts.FeaturesAsWritten.begin(), |
| 333 | TargetOpts.FeaturesAsWritten.end()); |
| 334 | std::sort(ExistingFeatures.begin(), ExistingFeatures.end()); |
| 335 | std::sort(ReadFeatures.begin(), ReadFeatures.end()); |
| 336 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 337 | // We compute the set difference in both directions explicitly so that we can |
| 338 | // diagnose the differences differently. |
| 339 | SmallVector<StringRef, 4> UnmatchedExistingFeatures, UnmatchedReadFeatures; |
| 340 | std::set_difference( |
| 341 | ExistingFeatures.begin(), ExistingFeatures.end(), ReadFeatures.begin(), |
| 342 | ReadFeatures.end(), std::back_inserter(UnmatchedExistingFeatures)); |
| 343 | std::set_difference(ReadFeatures.begin(), ReadFeatures.end(), |
| 344 | ExistingFeatures.begin(), ExistingFeatures.end(), |
| 345 | std::back_inserter(UnmatchedReadFeatures)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 346 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 347 | // If we are allowing compatible differences and the read feature set is |
| 348 | // a strict subset of the existing feature set, there is nothing to diagnose. |
| 349 | if (AllowCompatibleDifferences && UnmatchedReadFeatures.empty()) |
| 350 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 351 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 352 | if (Diags) { |
| 353 | for (StringRef Feature : UnmatchedReadFeatures) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 354 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 355 | << /* is-existing-feature */ false << Feature; |
| 356 | for (StringRef Feature : UnmatchedExistingFeatures) |
| 357 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
| 358 | << /* is-existing-feature */ true << Feature; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 361 | return !UnmatchedReadFeatures.empty() || !UnmatchedExistingFeatures.empty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | bool |
| 365 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 366 | bool Complain, |
| 367 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 368 | const LangOptions &ExistingLangOpts = PP.getLangOpts(); |
| 369 | return checkLanguageOptions(LangOpts, ExistingLangOpts, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 370 | Complain ? &Reader.Diags : nullptr, |
| 371 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | bool PCHValidator::ReadTargetOptions(const TargetOptions &TargetOpts, |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 375 | bool Complain, |
| 376 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 377 | const TargetOptions &ExistingTargetOpts = PP.getTargetInfo().getTargetOpts(); |
| 378 | return checkTargetOptions(TargetOpts, ExistingTargetOpts, |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 379 | Complain ? &Reader.Diags : nullptr, |
| 380 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 384 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 385 | typedef llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> > |
| 386 | MacroDefinitionsMap; |
Craig Topper | 3598eb7 | 2013-07-05 04:43:31 +0000 | [diff] [blame] | 387 | typedef llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8> > |
| 388 | DeclsMap; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 389 | |
| 390 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 391 | |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 392 | static bool checkDiagnosticGroupMappings(DiagnosticsEngine &StoredDiags, |
| 393 | DiagnosticsEngine &Diags, |
| 394 | bool Complain) { |
| 395 | typedef DiagnosticsEngine::Level Level; |
| 396 | |
| 397 | // Check current mappings for new -Werror mappings, and the stored mappings |
| 398 | // for cases that were explicitly mapped to *not* be errors that are now |
| 399 | // errors because of options like -Werror. |
| 400 | DiagnosticsEngine *MappingSources[] = { &Diags, &StoredDiags }; |
| 401 | |
| 402 | for (DiagnosticsEngine *MappingSource : MappingSources) { |
| 403 | for (auto DiagIDMappingPair : MappingSource->getDiagnosticMappings()) { |
| 404 | diag::kind DiagID = DiagIDMappingPair.first; |
| 405 | Level CurLevel = Diags.getDiagnosticLevel(DiagID, SourceLocation()); |
| 406 | if (CurLevel < DiagnosticsEngine::Error) |
| 407 | continue; // not significant |
| 408 | Level StoredLevel = |
| 409 | StoredDiags.getDiagnosticLevel(DiagID, SourceLocation()); |
| 410 | if (StoredLevel < DiagnosticsEngine::Error) { |
| 411 | if (Complain) |
| 412 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror=" + |
| 413 | Diags.getDiagnosticIDs()->getWarningOptionForDiag(DiagID).str(); |
| 414 | return true; |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | return false; |
| 420 | } |
| 421 | |
Alp Toker | ac4e8e5 | 2014-06-22 21:58:33 +0000 | [diff] [blame] | 422 | static bool isExtHandlingFromDiagsError(DiagnosticsEngine &Diags) { |
| 423 | diag::Severity Ext = Diags.getExtensionHandlingBehavior(); |
| 424 | if (Ext == diag::Severity::Warning && Diags.getWarningsAsErrors()) |
| 425 | return true; |
| 426 | return Ext >= diag::Severity::Error; |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | static bool checkDiagnosticMappings(DiagnosticsEngine &StoredDiags, |
| 430 | DiagnosticsEngine &Diags, |
| 431 | bool IsSystem, bool Complain) { |
| 432 | // Top-level options |
| 433 | if (IsSystem) { |
| 434 | if (Diags.getSuppressSystemWarnings()) |
| 435 | return false; |
| 436 | // If -Wsystem-headers was not enabled before, be conservative |
| 437 | if (StoredDiags.getSuppressSystemWarnings()) { |
| 438 | if (Complain) |
| 439 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Wsystem-headers"; |
| 440 | return true; |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | if (Diags.getWarningsAsErrors() && !StoredDiags.getWarningsAsErrors()) { |
| 445 | if (Complain) |
| 446 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror"; |
| 447 | return true; |
| 448 | } |
| 449 | |
| 450 | if (Diags.getWarningsAsErrors() && Diags.getEnableAllWarnings() && |
| 451 | !StoredDiags.getEnableAllWarnings()) { |
| 452 | if (Complain) |
| 453 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Weverything -Werror"; |
| 454 | return true; |
| 455 | } |
| 456 | |
| 457 | if (isExtHandlingFromDiagsError(Diags) && |
| 458 | !isExtHandlingFromDiagsError(StoredDiags)) { |
| 459 | if (Complain) |
| 460 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-pedantic-errors"; |
| 461 | return true; |
| 462 | } |
| 463 | |
| 464 | return checkDiagnosticGroupMappings(StoredDiags, Diags, Complain); |
| 465 | } |
| 466 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 467 | /// Return the top import module if it is implicit, nullptr otherwise. |
| 468 | static Module *getTopImportImplicitModule(ModuleManager &ModuleMgr, |
| 469 | Preprocessor &PP) { |
| 470 | // If the original import came from a file explicitly generated by the user, |
| 471 | // don't check the diagnostic mappings. |
| 472 | // FIXME: currently this is approximated by checking whether this is not a |
| 473 | // module import of an implicitly-loaded module file. |
| 474 | // Note: ModuleMgr.rbegin() may not be the current module, but it must be in |
| 475 | // the transitive closure of its imports, since unrelated modules cannot be |
| 476 | // imported until after this module finishes validation. |
| 477 | ModuleFile *TopImport = &*ModuleMgr.rbegin(); |
| 478 | while (!TopImport->ImportedBy.empty()) |
| 479 | TopImport = TopImport->ImportedBy[0]; |
| 480 | if (TopImport->Kind != MK_ImplicitModule) |
| 481 | return nullptr; |
| 482 | |
| 483 | StringRef ModuleName = TopImport->ModuleName; |
| 484 | assert(!ModuleName.empty() && "diagnostic options read before module name"); |
| 485 | |
| 486 | Module *M = PP.getHeaderSearchInfo().lookupModule(ModuleName); |
| 487 | assert(M && "missing module"); |
| 488 | return M; |
| 489 | } |
| 490 | |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 491 | bool PCHValidator::ReadDiagnosticOptions( |
| 492 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) { |
| 493 | DiagnosticsEngine &ExistingDiags = PP.getDiagnostics(); |
| 494 | IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(ExistingDiags.getDiagnosticIDs()); |
| 495 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags( |
Alp Toker | f994cef | 2014-07-05 03:08:06 +0000 | [diff] [blame] | 496 | new DiagnosticsEngine(DiagIDs, DiagOpts.get())); |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 497 | // This should never fail, because we would have processed these options |
| 498 | // before writing them to an ASTFile. |
| 499 | ProcessWarningOptions(*Diags, *DiagOpts, /*Report*/false); |
| 500 | |
| 501 | ModuleManager &ModuleMgr = Reader.getModuleManager(); |
| 502 | assert(ModuleMgr.size() >= 1 && "what ASTFile is this then"); |
| 503 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 504 | Module *TopM = getTopImportImplicitModule(ModuleMgr, PP); |
| 505 | if (!TopM) |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 506 | return false; |
| 507 | |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 508 | // FIXME: if the diagnostics are incompatible, save a DiagnosticOptions that |
| 509 | // contains the union of their flags. |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 510 | return checkDiagnosticMappings(*Diags, ExistingDiags, TopM->IsSystem, |
| 511 | Complain); |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 514 | /// \brief Collect the macro definitions provided by the given preprocessor |
| 515 | /// options. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 516 | static void |
| 517 | collectMacroDefinitions(const PreprocessorOptions &PPOpts, |
| 518 | MacroDefinitionsMap &Macros, |
| 519 | SmallVectorImpl<StringRef> *MacroNames = nullptr) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 520 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 521 | StringRef Macro = PPOpts.Macros[I].first; |
| 522 | bool IsUndef = PPOpts.Macros[I].second; |
| 523 | |
| 524 | std::pair<StringRef, StringRef> MacroPair = Macro.split('='); |
| 525 | StringRef MacroName = MacroPair.first; |
| 526 | StringRef MacroBody = MacroPair.second; |
| 527 | |
| 528 | // For an #undef'd macro, we only care about the name. |
| 529 | if (IsUndef) { |
| 530 | if (MacroNames && !Macros.count(MacroName)) |
| 531 | MacroNames->push_back(MacroName); |
| 532 | |
| 533 | Macros[MacroName] = std::make_pair("", true); |
| 534 | continue; |
| 535 | } |
| 536 | |
| 537 | // For a #define'd macro, figure out the actual definition. |
| 538 | if (MacroName.size() == Macro.size()) |
| 539 | MacroBody = "1"; |
| 540 | else { |
| 541 | // Note: GCC drops anything following an end-of-line character. |
| 542 | StringRef::size_type End = MacroBody.find_first_of("\n\r"); |
| 543 | MacroBody = MacroBody.substr(0, End); |
| 544 | } |
| 545 | |
| 546 | if (MacroNames && !Macros.count(MacroName)) |
| 547 | MacroNames->push_back(MacroName); |
| 548 | Macros[MacroName] = std::make_pair(MacroBody, false); |
| 549 | } |
| 550 | } |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 551 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 552 | /// \brief Check the preprocessor options deserialized from the control block |
| 553 | /// against the preprocessor options in an existing preprocessor. |
| 554 | /// |
| 555 | /// \param Diags If non-null, produce diagnostics for any mismatches incurred. |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 556 | /// \param Validate If true, validate preprocessor options. If false, allow |
| 557 | /// macros defined by \p ExistingPPOpts to override those defined by |
| 558 | /// \p PPOpts in SuggestedPredefines. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 559 | static bool checkPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 560 | const PreprocessorOptions &ExistingPPOpts, |
| 561 | DiagnosticsEngine *Diags, |
| 562 | FileManager &FileMgr, |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 563 | std::string &SuggestedPredefines, |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 564 | const LangOptions &LangOpts, |
| 565 | bool Validate = true) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 566 | // Check macro definitions. |
| 567 | MacroDefinitionsMap ASTFileMacros; |
| 568 | collectMacroDefinitions(PPOpts, ASTFileMacros); |
| 569 | MacroDefinitionsMap ExistingMacros; |
| 570 | SmallVector<StringRef, 4> ExistingMacroNames; |
| 571 | collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames); |
| 572 | |
| 573 | for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) { |
| 574 | // Dig out the macro definition in the existing preprocessor options. |
| 575 | StringRef MacroName = ExistingMacroNames[I]; |
| 576 | std::pair<StringRef, bool> Existing = ExistingMacros[MacroName]; |
| 577 | |
| 578 | // Check whether we know anything about this macro name or not. |
| 579 | llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> >::iterator Known |
| 580 | = ASTFileMacros.find(MacroName); |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 581 | if (!Validate || Known == ASTFileMacros.end()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 582 | // FIXME: Check whether this identifier was referenced anywhere in the |
| 583 | // AST file. If so, we should reject the AST file. Unfortunately, this |
| 584 | // information isn't in the control block. What shall we do about it? |
| 585 | |
| 586 | if (Existing.second) { |
| 587 | SuggestedPredefines += "#undef "; |
| 588 | SuggestedPredefines += MacroName.str(); |
| 589 | SuggestedPredefines += '\n'; |
| 590 | } else { |
| 591 | SuggestedPredefines += "#define "; |
| 592 | SuggestedPredefines += MacroName.str(); |
| 593 | SuggestedPredefines += ' '; |
| 594 | SuggestedPredefines += Existing.first.str(); |
| 595 | SuggestedPredefines += '\n'; |
| 596 | } |
| 597 | continue; |
| 598 | } |
| 599 | |
| 600 | // If the macro was defined in one but undef'd in the other, we have a |
| 601 | // conflict. |
| 602 | if (Existing.second != Known->second.second) { |
| 603 | if (Diags) { |
| 604 | Diags->Report(diag::err_pch_macro_def_undef) |
| 605 | << MacroName << Known->second.second; |
| 606 | } |
| 607 | return true; |
| 608 | } |
| 609 | |
| 610 | // If the macro was #undef'd in both, or if the macro bodies are identical, |
| 611 | // it's fine. |
| 612 | if (Existing.second || Existing.first == Known->second.first) |
| 613 | continue; |
| 614 | |
| 615 | // The macro bodies differ; complain. |
| 616 | if (Diags) { |
| 617 | Diags->Report(diag::err_pch_macro_def_conflict) |
| 618 | << MacroName << Known->second.first << Existing.first; |
| 619 | } |
| 620 | return true; |
| 621 | } |
| 622 | |
| 623 | // Check whether we're using predefines. |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 624 | if (PPOpts.UsePredefines != ExistingPPOpts.UsePredefines && Validate) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 625 | if (Diags) { |
| 626 | Diags->Report(diag::err_pch_undef) << ExistingPPOpts.UsePredefines; |
| 627 | } |
| 628 | return true; |
| 629 | } |
| 630 | |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 631 | // Detailed record is important since it is used for the module cache hash. |
| 632 | if (LangOpts.Modules && |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 633 | PPOpts.DetailedRecord != ExistingPPOpts.DetailedRecord && Validate) { |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 634 | if (Diags) { |
| 635 | Diags->Report(diag::err_pch_pp_detailed_record) << PPOpts.DetailedRecord; |
| 636 | } |
| 637 | return true; |
| 638 | } |
| 639 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 640 | // Compute the #include and #include_macros lines we need. |
| 641 | for (unsigned I = 0, N = ExistingPPOpts.Includes.size(); I != N; ++I) { |
| 642 | StringRef File = ExistingPPOpts.Includes[I]; |
| 643 | if (File == ExistingPPOpts.ImplicitPCHInclude) |
| 644 | continue; |
| 645 | |
| 646 | if (std::find(PPOpts.Includes.begin(), PPOpts.Includes.end(), File) |
| 647 | != PPOpts.Includes.end()) |
| 648 | continue; |
| 649 | |
| 650 | SuggestedPredefines += "#include \""; |
Manuel Klimek | 9af34ae | 2014-08-12 08:25:57 +0000 | [diff] [blame] | 651 | SuggestedPredefines += File; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 652 | SuggestedPredefines += "\"\n"; |
| 653 | } |
| 654 | |
| 655 | for (unsigned I = 0, N = ExistingPPOpts.MacroIncludes.size(); I != N; ++I) { |
| 656 | StringRef File = ExistingPPOpts.MacroIncludes[I]; |
| 657 | if (std::find(PPOpts.MacroIncludes.begin(), PPOpts.MacroIncludes.end(), |
| 658 | File) |
| 659 | != PPOpts.MacroIncludes.end()) |
| 660 | continue; |
| 661 | |
| 662 | SuggestedPredefines += "#__include_macros \""; |
Manuel Klimek | 9af34ae | 2014-08-12 08:25:57 +0000 | [diff] [blame] | 663 | SuggestedPredefines += File; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 664 | SuggestedPredefines += "\"\n##\n"; |
| 665 | } |
| 666 | |
| 667 | return false; |
| 668 | } |
| 669 | |
| 670 | bool PCHValidator::ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 671 | bool Complain, |
| 672 | std::string &SuggestedPredefines) { |
| 673 | const PreprocessorOptions &ExistingPPOpts = PP.getPreprocessorOpts(); |
| 674 | |
| 675 | return checkPreprocessorOptions(PPOpts, ExistingPPOpts, |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 676 | Complain? &Reader.Diags : nullptr, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 677 | PP.getFileManager(), |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 678 | SuggestedPredefines, |
| 679 | PP.getLangOpts()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 680 | } |
| 681 | |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 682 | bool SimpleASTReaderListener::ReadPreprocessorOptions( |
| 683 | const PreprocessorOptions &PPOpts, |
| 684 | bool Complain, |
| 685 | std::string &SuggestedPredefines) { |
| 686 | return checkPreprocessorOptions(PPOpts, |
| 687 | PP.getPreprocessorOpts(), |
| 688 | nullptr, |
| 689 | PP.getFileManager(), |
| 690 | SuggestedPredefines, |
| 691 | PP.getLangOpts(), |
| 692 | false); |
| 693 | } |
| 694 | |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 695 | /// Check the header search options deserialized from the control block |
| 696 | /// against the header search options in an existing preprocessor. |
| 697 | /// |
| 698 | /// \param Diags If non-null, produce diagnostics for any mismatches incurred. |
| 699 | static bool checkHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 700 | StringRef SpecificModuleCachePath, |
| 701 | StringRef ExistingModuleCachePath, |
| 702 | DiagnosticsEngine *Diags, |
| 703 | const LangOptions &LangOpts) { |
| 704 | if (LangOpts.Modules) { |
| 705 | if (SpecificModuleCachePath != ExistingModuleCachePath) { |
| 706 | if (Diags) |
| 707 | Diags->Report(diag::err_pch_modulecache_mismatch) |
| 708 | << SpecificModuleCachePath << ExistingModuleCachePath; |
| 709 | return true; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | return false; |
| 714 | } |
| 715 | |
| 716 | bool PCHValidator::ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 717 | StringRef SpecificModuleCachePath, |
| 718 | bool Complain) { |
| 719 | return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 720 | PP.getHeaderSearchInfo().getModuleCachePath(), |
| 721 | Complain ? &Reader.Diags : nullptr, |
| 722 | PP.getLangOpts()); |
| 723 | } |
| 724 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 725 | void PCHValidator::ReadCounter(const ModuleFile &M, unsigned Value) { |
| 726 | PP.setCounterValue(Value); |
| 727 | } |
| 728 | |
| 729 | //===----------------------------------------------------------------------===// |
| 730 | // AST reader implementation |
| 731 | //===----------------------------------------------------------------------===// |
| 732 | |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 733 | void ASTReader::setDeserializationListener(ASTDeserializationListener *Listener, |
| 734 | bool TakeOwnership) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 735 | DeserializationListener = Listener; |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 736 | OwnsDeserializationListener = TakeOwnership; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 737 | } |
| 738 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 739 | unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { |
| 740 | return serialization::ComputeHash(Sel); |
| 741 | } |
| 742 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 743 | std::pair<unsigned, unsigned> |
| 744 | ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 745 | using namespace llvm::support; |
| 746 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 747 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 748 | return std::make_pair(KeyLen, DataLen); |
| 749 | } |
| 750 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 751 | ASTSelectorLookupTrait::internal_key_type |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 752 | ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 753 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 754 | SelectorTable &SelTable = Reader.getContext().Selectors; |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 755 | unsigned N = endian::readNext<uint16_t, little, unaligned>(d); |
| 756 | IdentifierInfo *FirstII = Reader.getLocalIdentifier( |
| 757 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 758 | if (N == 0) |
| 759 | return SelTable.getNullarySelector(FirstII); |
| 760 | else if (N == 1) |
| 761 | return SelTable.getUnarySelector(FirstII); |
| 762 | |
| 763 | SmallVector<IdentifierInfo *, 16> Args; |
| 764 | Args.push_back(FirstII); |
| 765 | for (unsigned I = 1; I != N; ++I) |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 766 | Args.push_back(Reader.getLocalIdentifier( |
| 767 | F, endian::readNext<uint32_t, little, unaligned>(d))); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 768 | |
| 769 | return SelTable.getSelector(N, Args.data()); |
| 770 | } |
| 771 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 772 | ASTSelectorLookupTrait::data_type |
| 773 | ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 774 | unsigned DataLen) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 775 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 776 | |
| 777 | data_type Result; |
| 778 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 779 | Result.ID = Reader.getGlobalSelectorID( |
| 780 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 781 | unsigned FullInstanceBits = endian::readNext<uint16_t, little, unaligned>(d); |
| 782 | unsigned FullFactoryBits = endian::readNext<uint16_t, little, unaligned>(d); |
| 783 | Result.InstanceBits = FullInstanceBits & 0x3; |
| 784 | Result.InstanceHasMoreThanOneDecl = (FullInstanceBits >> 2) & 0x1; |
| 785 | Result.FactoryBits = FullFactoryBits & 0x3; |
| 786 | Result.FactoryHasMoreThanOneDecl = (FullFactoryBits >> 2) & 0x1; |
| 787 | unsigned NumInstanceMethods = FullInstanceBits >> 3; |
| 788 | unsigned NumFactoryMethods = FullFactoryBits >> 3; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 789 | |
| 790 | // Load instance methods |
| 791 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 792 | if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>( |
| 793 | F, endian::readNext<uint32_t, little, unaligned>(d))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 794 | Result.Instance.push_back(Method); |
| 795 | } |
| 796 | |
| 797 | // Load factory methods |
| 798 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 799 | if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>( |
| 800 | F, endian::readNext<uint32_t, little, unaligned>(d))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 801 | Result.Factory.push_back(Method); |
| 802 | } |
| 803 | |
| 804 | return Result; |
| 805 | } |
| 806 | |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 807 | unsigned ASTIdentifierLookupTraitBase::ComputeHash(const internal_key_type& a) { |
| 808 | return llvm::HashString(a); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | std::pair<unsigned, unsigned> |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 812 | ASTIdentifierLookupTraitBase::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 813 | using namespace llvm::support; |
| 814 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 815 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 816 | return std::make_pair(KeyLen, DataLen); |
| 817 | } |
| 818 | |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 819 | ASTIdentifierLookupTraitBase::internal_key_type |
| 820 | ASTIdentifierLookupTraitBase::ReadKey(const unsigned char* d, unsigned n) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 821 | assert(n >= 2 && d[n-1] == '\0'); |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 822 | return StringRef((const char*) d, n-1); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 823 | } |
| 824 | |
Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 825 | /// \brief Whether the given identifier is "interesting". |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 826 | static bool isInterestingIdentifier(ASTReader &Reader, IdentifierInfo &II, |
| 827 | bool IsModule) { |
Richard Smith | cab8980 | 2015-07-17 20:19:56 +0000 | [diff] [blame] | 828 | return II.hadMacroDefinition() || |
| 829 | II.isPoisoned() || |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 830 | (IsModule ? II.hasRevertedBuiltin() : II.getObjCOrBuiltinID()) || |
Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 831 | II.hasRevertedTokenIDToIdentifier() || |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 832 | (!(IsModule && Reader.getContext().getLangOpts().CPlusPlus) && |
| 833 | II.getFETokenInfo<void>()); |
Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 834 | } |
| 835 | |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 836 | static bool readBit(unsigned &Bits) { |
| 837 | bool Value = Bits & 0x1; |
| 838 | Bits >>= 1; |
| 839 | return Value; |
| 840 | } |
| 841 | |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 842 | IdentID ASTIdentifierLookupTrait::ReadIdentifierID(const unsigned char *d) { |
| 843 | using namespace llvm::support; |
| 844 | unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d); |
| 845 | return Reader.getGlobalIdentifierID(F, RawID >> 1); |
| 846 | } |
| 847 | |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 848 | static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II) { |
| 849 | if (!II.isFromAST()) { |
| 850 | II.setIsFromAST(); |
| 851 | bool IsModule = Reader.getPreprocessor().getCurrentModule() != nullptr; |
| 852 | if (isInterestingIdentifier(Reader, II, IsModule)) |
| 853 | II.setChangedSinceDeserialization(); |
| 854 | } |
| 855 | } |
| 856 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 857 | IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, |
| 858 | const unsigned char* d, |
| 859 | unsigned DataLen) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 860 | using namespace llvm::support; |
| 861 | unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 862 | bool IsInteresting = RawID & 0x01; |
| 863 | |
| 864 | // Wipe out the "is interesting" bit. |
| 865 | RawID = RawID >> 1; |
| 866 | |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 867 | // Build the IdentifierInfo and link the identifier ID with it. |
| 868 | IdentifierInfo *II = KnownII; |
| 869 | if (!II) { |
| 870 | II = &Reader.getIdentifierTable().getOwn(k); |
| 871 | KnownII = II; |
| 872 | } |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 873 | markIdentifierFromAST(Reader, *II); |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 874 | Reader.markIdentifierUpToDate(II); |
| 875 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 876 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
| 877 | if (!IsInteresting) { |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 878 | // For uninteresting identifiers, there's nothing else to do. Just notify |
| 879 | // the reader that we've finished loading this identifier. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 880 | Reader.SetIdentifierInfo(ID, II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 881 | return II; |
| 882 | } |
| 883 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 884 | unsigned ObjCOrBuiltinID = endian::readNext<uint16_t, little, unaligned>(d); |
| 885 | unsigned Bits = endian::readNext<uint16_t, little, unaligned>(d); |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 886 | bool CPlusPlusOperatorKeyword = readBit(Bits); |
| 887 | bool HasRevertedTokenIDToIdentifier = readBit(Bits); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 888 | bool HasRevertedBuiltin = readBit(Bits); |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 889 | bool Poisoned = readBit(Bits); |
| 890 | bool ExtensionToken = readBit(Bits); |
| 891 | bool HadMacroDefinition = readBit(Bits); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 892 | |
| 893 | assert(Bits == 0 && "Extra bits in the identifier?"); |
| 894 | DataLen -= 8; |
| 895 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 896 | // Set or check the various bits in the IdentifierInfo structure. |
| 897 | // Token IDs are read-only. |
Argyrios Kyrtzidis | ddee8c9 | 2013-02-27 01:13:51 +0000 | [diff] [blame] | 898 | if (HasRevertedTokenIDToIdentifier && II->getTokenID() != tok::identifier) |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 899 | II->revertTokenIDToIdentifier(); |
| 900 | if (!F.isModule()) |
| 901 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 902 | else if (HasRevertedBuiltin && II->getBuiltinID()) { |
| 903 | II->revertBuiltin(); |
| 904 | assert((II->hasRevertedBuiltin() || |
| 905 | II->getObjCOrBuiltinID() == ObjCOrBuiltinID) && |
| 906 | "Incorrect ObjC keyword or builtin ID"); |
| 907 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 908 | assert(II->isExtensionToken() == ExtensionToken && |
| 909 | "Incorrect extension token flag"); |
| 910 | (void)ExtensionToken; |
| 911 | if (Poisoned) |
| 912 | II->setIsPoisoned(true); |
| 913 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 914 | "Incorrect C++ operator keyword flag"); |
| 915 | (void)CPlusPlusOperatorKeyword; |
| 916 | |
| 917 | // If this identifier is a macro, deserialize the macro |
| 918 | // definition. |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 919 | if (HadMacroDefinition) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 920 | uint32_t MacroDirectivesOffset = |
| 921 | endian::readNext<uint32_t, little, unaligned>(d); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 922 | DataLen -= 4; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 923 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 924 | Reader.addPendingMacro(II, &F, MacroDirectivesOffset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | Reader.SetIdentifierInfo(ID, II); |
| 928 | |
| 929 | // Read all of the declarations visible at global scope with this |
| 930 | // name. |
| 931 | if (DataLen > 0) { |
| 932 | SmallVector<uint32_t, 4> DeclIDs; |
| 933 | for (; DataLen > 0; DataLen -= 4) |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 934 | DeclIDs.push_back(Reader.getGlobalDeclID( |
| 935 | F, endian::readNext<uint32_t, little, unaligned>(d))); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 936 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
| 937 | } |
| 938 | |
| 939 | return II; |
| 940 | } |
| 941 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 942 | DeclarationNameKey::DeclarationNameKey(DeclarationName Name) |
| 943 | : Kind(Name.getNameKind()) { |
| 944 | switch (Kind) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 945 | case DeclarationName::Identifier: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 946 | Data = (uint64_t)Name.getAsIdentifierInfo(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 947 | break; |
| 948 | case DeclarationName::ObjCZeroArgSelector: |
| 949 | case DeclarationName::ObjCOneArgSelector: |
| 950 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 951 | Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 952 | break; |
| 953 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 954 | Data = Name.getCXXOverloadedOperator(); |
| 955 | break; |
| 956 | case DeclarationName::CXXLiteralOperatorName: |
| 957 | Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 958 | break; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 959 | case DeclarationName::CXXDeductionGuideName: |
| 960 | Data = (uint64_t)Name.getCXXDeductionGuideTemplate() |
| 961 | ->getDeclName().getAsIdentifierInfo(); |
| 962 | break; |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 963 | case DeclarationName::CXXConstructorName: |
| 964 | case DeclarationName::CXXDestructorName: |
| 965 | case DeclarationName::CXXConversionFunctionName: |
| 966 | case DeclarationName::CXXUsingDirective: |
| 967 | Data = 0; |
| 968 | break; |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | unsigned DeclarationNameKey::getHash() const { |
| 973 | llvm::FoldingSetNodeID ID; |
| 974 | ID.AddInteger(Kind); |
| 975 | |
| 976 | switch (Kind) { |
| 977 | case DeclarationName::Identifier: |
| 978 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 979 | case DeclarationName::CXXDeductionGuideName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 980 | ID.AddString(((IdentifierInfo*)Data)->getName()); |
| 981 | break; |
| 982 | case DeclarationName::ObjCZeroArgSelector: |
| 983 | case DeclarationName::ObjCOneArgSelector: |
| 984 | case DeclarationName::ObjCMultiArgSelector: |
| 985 | ID.AddInteger(serialization::ComputeHash(Selector(Data))); |
| 986 | break; |
| 987 | case DeclarationName::CXXOperatorName: |
| 988 | ID.AddInteger((OverloadedOperatorKind)Data); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 989 | break; |
| 990 | case DeclarationName::CXXConstructorName: |
| 991 | case DeclarationName::CXXDestructorName: |
| 992 | case DeclarationName::CXXConversionFunctionName: |
| 993 | case DeclarationName::CXXUsingDirective: |
| 994 | break; |
| 995 | } |
| 996 | |
| 997 | return ID.ComputeHash(); |
| 998 | } |
| 999 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1000 | ModuleFile * |
| 1001 | ASTDeclContextNameLookupTrait::ReadFileRef(const unsigned char *&d) { |
| 1002 | using namespace llvm::support; |
| 1003 | uint32_t ModuleFileID = endian::readNext<uint32_t, little, unaligned>(d); |
| 1004 | return Reader.getLocalModuleFile(F, ModuleFileID); |
| 1005 | } |
| 1006 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1007 | std::pair<unsigned, unsigned> |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1008 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char *&d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1009 | using namespace llvm::support; |
| 1010 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 1011 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1012 | return std::make_pair(KeyLen, DataLen); |
| 1013 | } |
| 1014 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1015 | ASTDeclContextNameLookupTrait::internal_key_type |
| 1016 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char *d, unsigned) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1017 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1018 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1019 | auto Kind = (DeclarationName::NameKind)*d++; |
| 1020 | uint64_t Data; |
| 1021 | switch (Kind) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1022 | case DeclarationName::Identifier: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1023 | case DeclarationName::CXXLiteralOperatorName: |
| 1024 | case DeclarationName::CXXDeductionGuideName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1025 | Data = (uint64_t)Reader.getLocalIdentifier( |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1026 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1027 | break; |
| 1028 | case DeclarationName::ObjCZeroArgSelector: |
| 1029 | case DeclarationName::ObjCOneArgSelector: |
| 1030 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1031 | Data = |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1032 | (uint64_t)Reader.getLocalSelector( |
| 1033 | F, endian::readNext<uint32_t, little, unaligned>( |
| 1034 | d)).getAsOpaquePtr(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1035 | break; |
| 1036 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1037 | Data = *d++; // OverloadedOperatorKind |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1038 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1039 | case DeclarationName::CXXConstructorName: |
| 1040 | case DeclarationName::CXXDestructorName: |
| 1041 | case DeclarationName::CXXConversionFunctionName: |
| 1042 | case DeclarationName::CXXUsingDirective: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1043 | Data = 0; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1044 | break; |
| 1045 | } |
| 1046 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1047 | return DeclarationNameKey(Kind, Data); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1050 | void ASTDeclContextNameLookupTrait::ReadDataInto(internal_key_type, |
| 1051 | const unsigned char *d, |
| 1052 | unsigned DataLen, |
| 1053 | data_type_builder &Val) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1054 | using namespace llvm::support; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1055 | for (unsigned NumDecls = DataLen / 4; NumDecls; --NumDecls) { |
| 1056 | uint32_t LocalID = endian::readNext<uint32_t, little, unaligned>(d); |
| 1057 | Val.insert(Reader.getGlobalDeclID(F, LocalID)); |
| 1058 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1061 | bool ASTReader::ReadLexicalDeclContextStorage(ModuleFile &M, |
| 1062 | BitstreamCursor &Cursor, |
| 1063 | uint64_t Offset, |
| 1064 | DeclContext *DC) { |
| 1065 | assert(Offset != 0); |
| 1066 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1067 | SavedStreamPosition SavedPosition(Cursor); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1068 | Cursor.JumpToBit(Offset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1069 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1070 | RecordData Record; |
| 1071 | StringRef Blob; |
| 1072 | unsigned Code = Cursor.ReadCode(); |
| 1073 | unsigned RecCode = Cursor.readRecord(Code, Record, &Blob); |
| 1074 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 1075 | Error("Expected lexical block"); |
| 1076 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 1079 | assert(!isa<TranslationUnitDecl>(DC) && |
| 1080 | "expected a TU_UPDATE_LEXICAL record for TU"); |
Richard Smith | 9c9173d | 2015-08-11 22:00:24 +0000 | [diff] [blame] | 1081 | // If we are handling a C++ class template instantiation, we can see multiple |
| 1082 | // lexical updates for the same record. It's important that we select only one |
| 1083 | // of them, so that field numbering works properly. Just pick the first one we |
| 1084 | // see. |
| 1085 | auto &Lex = LexicalDecls[DC]; |
| 1086 | if (!Lex.first) { |
| 1087 | Lex = std::make_pair( |
| 1088 | &M, llvm::makeArrayRef( |
| 1089 | reinterpret_cast<const llvm::support::unaligned_uint32_t *>( |
| 1090 | Blob.data()), |
| 1091 | Blob.size() / 4)); |
| 1092 | } |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1093 | DC->setHasExternalLexicalStorage(true); |
| 1094 | return false; |
| 1095 | } |
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 | bool ASTReader::ReadVisibleDeclContextStorage(ModuleFile &M, |
| 1098 | BitstreamCursor &Cursor, |
| 1099 | uint64_t Offset, |
| 1100 | DeclID ID) { |
| 1101 | assert(Offset != 0); |
| 1102 | |
| 1103 | SavedStreamPosition SavedPosition(Cursor); |
| 1104 | Cursor.JumpToBit(Offset); |
| 1105 | |
| 1106 | RecordData Record; |
| 1107 | StringRef Blob; |
| 1108 | unsigned Code = Cursor.ReadCode(); |
| 1109 | unsigned RecCode = Cursor.readRecord(Code, Record, &Blob); |
| 1110 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 1111 | Error("Expected visible lookup table block"); |
| 1112 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1115 | // We can't safely determine the primary context yet, so delay attaching the |
| 1116 | // lookup table until we're done with recursive deserialization. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1117 | auto *Data = (const unsigned char*)Blob.data(); |
| 1118 | PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&M, Data}); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1119 | return false; |
| 1120 | } |
| 1121 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 1122 | void ASTReader::Error(StringRef Msg) const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1123 | Error(diag::err_fe_pch_malformed, Msg); |
Richard Smith | fb1e7f7 | 2015-08-14 05:02:58 +0000 | [diff] [blame] | 1124 | if (Context.getLangOpts().Modules && !Diags.isDiagnosticInFlight() && |
| 1125 | !PP.getHeaderSearchInfo().getModuleCachePath().empty()) { |
Douglas Gregor | 940e805 | 2013-05-10 22:15:13 +0000 | [diff] [blame] | 1126 | Diag(diag::note_module_cache_path) |
| 1127 | << PP.getHeaderSearchInfo().getModuleCachePath(); |
| 1128 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | void ASTReader::Error(unsigned DiagID, |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 1132 | StringRef Arg1, StringRef Arg2) const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1133 | if (Diags.isDiagnosticInFlight()) |
| 1134 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 1135 | else |
| 1136 | Diag(DiagID) << Arg1 << Arg2; |
| 1137 | } |
| 1138 | |
| 1139 | //===----------------------------------------------------------------------===// |
| 1140 | // Source Manager Deserialization |
| 1141 | //===----------------------------------------------------------------------===// |
| 1142 | |
| 1143 | /// \brief Read the line table in the source manager block. |
| 1144 | /// \returns true if there was an error. |
| 1145 | bool ASTReader::ParseLineTable(ModuleFile &F, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1146 | const RecordData &Record) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1147 | unsigned Idx = 0; |
| 1148 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1149 | |
| 1150 | // Parse the file names |
| 1151 | std::map<int, int> FileIDs; |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1152 | for (unsigned I = 0; Record[Idx]; ++I) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1153 | // Extract the file name |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1154 | auto Filename = ReadPath(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1155 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
| 1156 | } |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1157 | ++Idx; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1158 | |
| 1159 | // Parse the line entries |
| 1160 | std::vector<LineEntry> Entries; |
| 1161 | while (Idx < Record.size()) { |
| 1162 | int FID = Record[Idx++]; |
| 1163 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 1164 | // Remap FileID from 1-based old view. |
| 1165 | FID += F.SLocEntryBaseID - 1; |
| 1166 | |
| 1167 | // Extract the line entries |
| 1168 | unsigned NumEntries = Record[Idx++]; |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1169 | assert(NumEntries && "no line entries for file ID"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1170 | Entries.clear(); |
| 1171 | Entries.reserve(NumEntries); |
| 1172 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1173 | unsigned FileOffset = Record[Idx++]; |
| 1174 | unsigned LineNo = Record[Idx++]; |
| 1175 | int FilenameID = FileIDs[Record[Idx++]]; |
| 1176 | SrcMgr::CharacteristicKind FileKind |
| 1177 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1178 | unsigned IncludeOffset = Record[Idx++]; |
| 1179 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1180 | FileKind, IncludeOffset)); |
| 1181 | } |
| 1182 | LineTable.AddEntry(FileID::get(FID), Entries); |
| 1183 | } |
| 1184 | |
| 1185 | return false; |
| 1186 | } |
| 1187 | |
| 1188 | /// \brief Read a source manager block |
| 1189 | bool ASTReader::ReadSourceManagerBlock(ModuleFile &F) { |
| 1190 | using namespace SrcMgr; |
| 1191 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1192 | BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1193 | |
| 1194 | // Set the source-location entry cursor to the current position in |
| 1195 | // the stream. This cursor will be used to read the contents of the |
| 1196 | // source manager block initially, and then lazily read |
| 1197 | // source-location entries as needed. |
| 1198 | SLocEntryCursor = F.Stream; |
| 1199 | |
| 1200 | // The stream itself is going to skip over the source manager block. |
| 1201 | if (F.Stream.SkipBlock()) { |
| 1202 | Error("malformed block record in AST file"); |
| 1203 | return true; |
| 1204 | } |
| 1205 | |
| 1206 | // Enter the source manager block. |
| 1207 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
| 1208 | Error("malformed source manager block record in AST file"); |
| 1209 | return true; |
| 1210 | } |
| 1211 | |
| 1212 | RecordData Record; |
| 1213 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1214 | llvm::BitstreamEntry E = SLocEntryCursor.advanceSkippingSubblocks(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1215 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1216 | switch (E.Kind) { |
| 1217 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1218 | case llvm::BitstreamEntry::Error: |
| 1219 | Error("malformed block record in AST file"); |
| 1220 | return true; |
| 1221 | case llvm::BitstreamEntry::EndBlock: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1222 | return false; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1223 | case llvm::BitstreamEntry::Record: |
| 1224 | // The interesting case. |
| 1225 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1226 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1227 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1228 | // Read a record. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1229 | Record.clear(); |
Chris Lattner | 15c3e7d | 2013-01-21 18:28:26 +0000 | [diff] [blame] | 1230 | StringRef Blob; |
| 1231 | switch (SLocEntryCursor.readRecord(E.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1232 | default: // Default behavior: ignore. |
| 1233 | break; |
| 1234 | |
| 1235 | case SM_SLOC_FILE_ENTRY: |
| 1236 | case SM_SLOC_BUFFER_ENTRY: |
| 1237 | case SM_SLOC_EXPANSION_ENTRY: |
| 1238 | // Once we hit one of the source location entries, we're done. |
| 1239 | return false; |
| 1240 | } |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | /// \brief If a header file is not found at the path that we expect it to be |
| 1245 | /// and the PCH file was moved from its original location, try to resolve the |
| 1246 | /// file by assuming that header+PCH were moved together and the header is in |
| 1247 | /// the same place relative to the PCH. |
| 1248 | static std::string |
| 1249 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1250 | const std::string &OriginalDir, |
| 1251 | const std::string &CurrDir) { |
| 1252 | assert(OriginalDir != CurrDir && |
| 1253 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1254 | using namespace llvm::sys; |
| 1255 | SmallString<128> filePath(Filename); |
| 1256 | fs::make_absolute(filePath); |
| 1257 | assert(path::is_absolute(OriginalDir)); |
| 1258 | SmallString<128> currPCHPath(CurrDir); |
| 1259 | |
| 1260 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1261 | fileDirE = path::end(path::parent_path(filePath)); |
| 1262 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1263 | origDirE = path::end(OriginalDir); |
| 1264 | // Skip the common path components from filePath and OriginalDir. |
| 1265 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1266 | *fileDirI == *origDirI) { |
| 1267 | ++fileDirI; |
| 1268 | ++origDirI; |
| 1269 | } |
| 1270 | for (; origDirI != origDirE; ++origDirI) |
| 1271 | path::append(currPCHPath, ".."); |
| 1272 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1273 | path::append(currPCHPath, path::filename(Filename)); |
| 1274 | return currPCHPath.str(); |
| 1275 | } |
| 1276 | |
| 1277 | bool ASTReader::ReadSLocEntry(int ID) { |
| 1278 | if (ID == 0) |
| 1279 | return false; |
| 1280 | |
| 1281 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
| 1282 | Error("source location entry ID out-of-range for AST file"); |
| 1283 | return true; |
| 1284 | } |
| 1285 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1286 | // Local helper to read the (possibly-compressed) buffer data following the |
| 1287 | // entry record. |
| 1288 | auto ReadBuffer = [this]( |
| 1289 | BitstreamCursor &SLocEntryCursor, |
| 1290 | StringRef Name) -> std::unique_ptr<llvm::MemoryBuffer> { |
| 1291 | RecordData Record; |
| 1292 | StringRef Blob; |
| 1293 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1294 | unsigned RecCode = SLocEntryCursor.readRecord(Code, Record, &Blob); |
| 1295 | |
| 1296 | if (RecCode == SM_SLOC_BUFFER_BLOB_COMPRESSED) { |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 1297 | if (!llvm::zlib::isAvailable()) { |
| 1298 | Error("zlib is not available"); |
| 1299 | return nullptr; |
| 1300 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1301 | SmallString<0> Uncompressed; |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 1302 | if (llvm::Error E = |
| 1303 | llvm::zlib::uncompress(Blob, Uncompressed, Record[0])) { |
| 1304 | Error("could not decompress embedded file contents: " + |
| 1305 | llvm::toString(std::move(E))); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1306 | return nullptr; |
| 1307 | } |
| 1308 | return llvm::MemoryBuffer::getMemBufferCopy(Uncompressed, Name); |
| 1309 | } else if (RecCode == SM_SLOC_BUFFER_BLOB) { |
| 1310 | return llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), Name, true); |
| 1311 | } else { |
| 1312 | Error("AST record has invalid code"); |
| 1313 | return nullptr; |
| 1314 | } |
| 1315 | }; |
| 1316 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1317 | ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second; |
| 1318 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1319 | BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1320 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
| 1321 | |
| 1322 | ++NumSLocEntriesRead; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1323 | llvm::BitstreamEntry Entry = SLocEntryCursor.advance(); |
| 1324 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1325 | Error("incorrectly-formatted source location entry in AST file"); |
| 1326 | return true; |
| 1327 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1328 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1329 | RecordData Record; |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1330 | StringRef Blob; |
| 1331 | switch (SLocEntryCursor.readRecord(Entry.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1332 | default: |
| 1333 | Error("incorrectly-formatted source location entry in AST file"); |
| 1334 | return true; |
| 1335 | |
| 1336 | case SM_SLOC_FILE_ENTRY: { |
| 1337 | // We will detect whether a file changed and return 'Failure' for it, but |
| 1338 | // we will also try to fail gracefully by setting up the SLocEntry. |
| 1339 | unsigned InputID = Record[4]; |
| 1340 | InputFile IF = getInputFile(*F, InputID); |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 1341 | const FileEntry *File = IF.getFile(); |
| 1342 | bool OverriddenBuffer = IF.isOverridden(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1343 | |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 1344 | // Note that we only check if a File was returned. If it was out-of-date |
| 1345 | // we have complained but we will continue creating a FileID to recover |
| 1346 | // gracefully. |
| 1347 | if (!File) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1348 | return true; |
| 1349 | |
| 1350 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
| 1351 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
| 1352 | // This is the module's main file. |
| 1353 | IncludeLoc = getImportLocation(F); |
| 1354 | } |
| 1355 | SrcMgr::CharacteristicKind |
| 1356 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1357 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter, |
| 1358 | ID, BaseOffset + Record[0]); |
| 1359 | SrcMgr::FileInfo &FileInfo = |
| 1360 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
| 1361 | FileInfo.NumCreatedFIDs = Record[5]; |
| 1362 | if (Record[3]) |
| 1363 | FileInfo.setHasLineDirectives(); |
| 1364 | |
| 1365 | const DeclID *FirstDecl = F->FileSortedDecls + Record[6]; |
| 1366 | unsigned NumFileDecls = Record[7]; |
| 1367 | if (NumFileDecls) { |
| 1368 | assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?"); |
| 1369 | FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl, |
| 1370 | NumFileDecls)); |
| 1371 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1372 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1373 | const SrcMgr::ContentCache *ContentCache |
| 1374 | = SourceMgr.getOrCreateContentCache(File, |
| 1375 | /*isSystemFile=*/FileCharacter != SrcMgr::C_User); |
| 1376 | if (OverriddenBuffer && !ContentCache->BufferOverridden && |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1377 | ContentCache->ContentsEntry == ContentCache->OrigEntry && |
| 1378 | !ContentCache->getRawBuffer()) { |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1379 | auto Buffer = ReadBuffer(SLocEntryCursor, File->getName()); |
| 1380 | if (!Buffer) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1381 | return true; |
David Blaikie | 49cc318 | 2014-08-27 20:54:45 +0000 | [diff] [blame] | 1382 | SourceMgr.overrideFileContents(File, std::move(Buffer)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | break; |
| 1386 | } |
| 1387 | |
| 1388 | case SM_SLOC_BUFFER_ENTRY: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1389 | const char *Name = Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1390 | unsigned Offset = Record[0]; |
| 1391 | SrcMgr::CharacteristicKind |
| 1392 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1393 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 1394 | if (IncludeLoc.isInvalid() && F->isModule()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1395 | IncludeLoc = getImportLocation(F); |
| 1396 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1397 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1398 | auto Buffer = ReadBuffer(SLocEntryCursor, Name); |
| 1399 | if (!Buffer) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1400 | return true; |
David Blaikie | 50a5f97 | 2014-08-29 07:59:55 +0000 | [diff] [blame] | 1401 | SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID, |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 1402 | BaseOffset + Offset, IncludeLoc); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1403 | break; |
| 1404 | } |
| 1405 | |
| 1406 | case SM_SLOC_EXPANSION_ENTRY: { |
| 1407 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
| 1408 | SourceMgr.createExpansionLoc(SpellingLoc, |
| 1409 | ReadSourceLocation(*F, Record[2]), |
| 1410 | ReadSourceLocation(*F, Record[3]), |
| 1411 | Record[4], |
| 1412 | ID, |
| 1413 | BaseOffset + Record[0]); |
| 1414 | break; |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | return false; |
| 1419 | } |
| 1420 | |
| 1421 | std::pair<SourceLocation, StringRef> ASTReader::getModuleImportLoc(int ID) { |
| 1422 | if (ID == 0) |
| 1423 | return std::make_pair(SourceLocation(), ""); |
| 1424 | |
| 1425 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
| 1426 | Error("source location entry ID out-of-range for AST file"); |
| 1427 | return std::make_pair(SourceLocation(), ""); |
| 1428 | } |
| 1429 | |
| 1430 | // Find which module file this entry lands in. |
| 1431 | ModuleFile *M = GlobalSLocEntryMap.find(-ID)->second; |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 1432 | if (!M->isModule()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1433 | return std::make_pair(SourceLocation(), ""); |
| 1434 | |
| 1435 | // FIXME: Can we map this down to a particular submodule? That would be |
| 1436 | // ideal. |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1437 | return std::make_pair(M->ImportLoc, StringRef(M->ModuleName)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | /// \brief Find the location where the module F is imported. |
| 1441 | SourceLocation ASTReader::getImportLocation(ModuleFile *F) { |
| 1442 | if (F->ImportLoc.isValid()) |
| 1443 | return F->ImportLoc; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1444 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1445 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1446 | // location of its includer. |
| 1447 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1448 | // Main file is the importer. |
Yaron Keren | 8b56366 | 2015-10-03 10:46:20 +0000 | [diff] [blame] | 1449 | assert(SourceMgr.getMainFileID().isValid() && "missing main file"); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1450 | return SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1451 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1452 | return F->ImportedBy[0]->FirstLoc; |
| 1453 | } |
| 1454 | |
| 1455 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1456 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1457 | /// and then leave the cursor pointing into the block. |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1458 | bool ASTReader::ReadBlockAbbrevs(BitstreamCursor &Cursor, unsigned BlockID) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1459 | if (Cursor.EnterSubBlock(BlockID)) |
| 1460 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1461 | |
| 1462 | while (true) { |
| 1463 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
| 1464 | unsigned Code = Cursor.ReadCode(); |
| 1465 | |
| 1466 | // We expect all abbrevs to be at the start of the block. |
| 1467 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1468 | Cursor.JumpToBit(Offset); |
| 1469 | return false; |
| 1470 | } |
| 1471 | Cursor.ReadAbbrevRecord(); |
| 1472 | } |
| 1473 | } |
| 1474 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 1475 | Token ASTReader::ReadToken(ModuleFile &F, const RecordDataImpl &Record, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1476 | unsigned &Idx) { |
| 1477 | Token Tok; |
| 1478 | Tok.startToken(); |
| 1479 | Tok.setLocation(ReadSourceLocation(F, Record, Idx)); |
| 1480 | Tok.setLength(Record[Idx++]); |
| 1481 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[Idx++])) |
| 1482 | Tok.setIdentifierInfo(II); |
| 1483 | Tok.setKind((tok::TokenKind)Record[Idx++]); |
| 1484 | Tok.setFlag((Token::TokenFlags)Record[Idx++]); |
| 1485 | return Tok; |
| 1486 | } |
| 1487 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1488 | MacroInfo *ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1489 | BitstreamCursor &Stream = F.MacroCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1490 | |
| 1491 | // Keep track of where we are in the stream, then jump back there |
| 1492 | // after reading this macro. |
| 1493 | SavedStreamPosition SavedPosition(Stream); |
| 1494 | |
| 1495 | Stream.JumpToBit(Offset); |
| 1496 | RecordData Record; |
| 1497 | SmallVector<IdentifierInfo*, 16> MacroArgs; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1498 | MacroInfo *Macro = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1499 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1500 | while (true) { |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1501 | // Advance to the next record, but if we get to the end of the block, don't |
| 1502 | // pop it (removing all the abbreviations from the cursor) since we want to |
| 1503 | // be able to reseek within the block and read entries. |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1504 | unsigned Flags = BitstreamCursor::AF_DontPopBlockAtEnd; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1505 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(Flags); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1506 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1507 | switch (Entry.Kind) { |
| 1508 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1509 | case llvm::BitstreamEntry::Error: |
| 1510 | Error("malformed block record in AST file"); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1511 | return Macro; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1512 | case llvm::BitstreamEntry::EndBlock: |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1513 | return Macro; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1514 | case llvm::BitstreamEntry::Record: |
| 1515 | // The interesting case. |
| 1516 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | // Read a record. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1520 | Record.clear(); |
| 1521 | PreprocessorRecordTypes RecType = |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1522 | (PreprocessorRecordTypes)Stream.readRecord(Entry.ID, Record); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1523 | switch (RecType) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1524 | case PP_MODULE_MACRO: |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1525 | case PP_MACRO_DIRECTIVE_HISTORY: |
| 1526 | return Macro; |
| 1527 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1528 | case PP_MACRO_OBJECT_LIKE: |
| 1529 | case PP_MACRO_FUNCTION_LIKE: { |
| 1530 | // If we already have a macro, that means that we've hit the end |
| 1531 | // of the definition of the macro we were looking for. We're |
| 1532 | // done. |
| 1533 | if (Macro) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1534 | return Macro; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1535 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1536 | unsigned NextIndex = 1; // Skip identifier ID. |
| 1537 | SubmoduleID SubModID = getGlobalSubmoduleID(F, Record[NextIndex++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1538 | SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1539 | MacroInfo *MI = PP.AllocateDeserializedMacroInfo(Loc, SubModID); |
Argyrios Kyrtzidis | 7572be2 | 2013-01-07 19:16:23 +0000 | [diff] [blame] | 1540 | MI->setDefinitionEndLoc(ReadSourceLocation(F, Record, NextIndex)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1541 | MI->setIsUsed(Record[NextIndex++]); |
Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 1542 | MI->setUsedForHeaderGuard(Record[NextIndex++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1543 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1544 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
| 1545 | // Decode function-like macro info. |
| 1546 | bool isC99VarArgs = Record[NextIndex++]; |
| 1547 | bool isGNUVarArgs = Record[NextIndex++]; |
| 1548 | bool hasCommaPasting = Record[NextIndex++]; |
| 1549 | MacroArgs.clear(); |
| 1550 | unsigned NumArgs = Record[NextIndex++]; |
| 1551 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1552 | MacroArgs.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
| 1553 | |
| 1554 | // Install function-like macro info. |
| 1555 | MI->setIsFunctionLike(); |
| 1556 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1557 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
| 1558 | if (hasCommaPasting) MI->setHasCommaPasting(); |
Craig Topper | d96b3f9 | 2015-10-22 04:59:52 +0000 | [diff] [blame] | 1559 | MI->setArgumentList(MacroArgs, PP.getPreprocessorAllocator()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1562 | // Remember that we saw this macro last so that we add the tokens that |
| 1563 | // form its body to it. |
| 1564 | Macro = MI; |
| 1565 | |
| 1566 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() && |
| 1567 | Record[NextIndex]) { |
| 1568 | // We have a macro definition. Register the association |
| 1569 | PreprocessedEntityID |
| 1570 | GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]); |
| 1571 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 1572 | PreprocessingRecord::PPEntityID PPID = |
| 1573 | PPRec.getPPEntityID(GlobalID - 1, /*isLoaded=*/true); |
| 1574 | MacroDefinitionRecord *PPDef = cast_or_null<MacroDefinitionRecord>( |
| 1575 | PPRec.getPreprocessedEntity(PPID)); |
Argyrios Kyrtzidis | 832de9f | 2013-02-22 18:35:59 +0000 | [diff] [blame] | 1576 | if (PPDef) |
| 1577 | PPRec.RegisterMacroDefinition(Macro, PPDef); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | ++NumMacrosRead; |
| 1581 | break; |
| 1582 | } |
| 1583 | |
| 1584 | case PP_TOKEN: { |
| 1585 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1586 | // erroneous, just pretend we didn't see this. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1587 | if (!Macro) break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1588 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1589 | unsigned Idx = 0; |
| 1590 | Token Tok = ReadToken(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1591 | Macro->AddTokenToBody(Tok); |
| 1592 | break; |
| 1593 | } |
| 1594 | } |
| 1595 | } |
| 1596 | } |
| 1597 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1598 | PreprocessedEntityID |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 1599 | ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M, |
| 1600 | unsigned LocalID) const { |
| 1601 | if (!M.ModuleOffsetMap.empty()) |
| 1602 | ReadModuleOffsetMap(M); |
| 1603 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1604 | ContinuousRangeMap<uint32_t, int, 2>::const_iterator |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1605 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1606 | assert(I != M.PreprocessedEntityRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1607 | && "Invalid index into preprocessed entity index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1608 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1609 | return LocalID + I->second; |
| 1610 | } |
| 1611 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1612 | unsigned HeaderFileInfoTrait::ComputeHash(internal_key_ref ikey) { |
| 1613 | return llvm::hash_combine(ikey.Size, ikey.ModTime); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1614 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1615 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1616 | HeaderFileInfoTrait::internal_key_type |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1617 | HeaderFileInfoTrait::GetInternalKey(const FileEntry *FE) { |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1618 | internal_key_type ikey = {FE->getSize(), |
| 1619 | M.HasTimestamps ? FE->getModificationTime() : 0, |
| 1620 | FE->getName(), /*Imported*/ false}; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1621 | return ikey; |
| 1622 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1623 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1624 | bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) { |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1625 | 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] | 1626 | return false; |
| 1627 | |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1628 | if (llvm::sys::path::is_absolute(a.Filename) && a.Filename == b.Filename) |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1629 | return true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1630 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1631 | // Determine whether the actual files are equivalent. |
Argyrios Kyrtzidis | 2a513e8 | 2013-03-04 20:33:40 +0000 | [diff] [blame] | 1632 | FileManager &FileMgr = Reader.getFileManager(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1633 | auto GetFile = [&](const internal_key_type &Key) -> const FileEntry* { |
| 1634 | if (!Key.Imported) |
| 1635 | return FileMgr.getFile(Key.Filename); |
| 1636 | |
| 1637 | std::string Resolved = Key.Filename; |
| 1638 | Reader.ResolveImportedPath(M, Resolved); |
| 1639 | return FileMgr.getFile(Resolved); |
| 1640 | }; |
| 1641 | |
| 1642 | const FileEntry *FEA = GetFile(a); |
| 1643 | const FileEntry *FEB = GetFile(b); |
| 1644 | return FEA && FEA == FEB; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1645 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1646 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1647 | std::pair<unsigned, unsigned> |
| 1648 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1649 | using namespace llvm::support; |
| 1650 | unsigned KeyLen = (unsigned) endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1651 | unsigned DataLen = (unsigned) *d++; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1652 | return std::make_pair(KeyLen, DataLen); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1653 | } |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1654 | |
| 1655 | HeaderFileInfoTrait::internal_key_type |
| 1656 | HeaderFileInfoTrait::ReadKey(const unsigned char *d, unsigned) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1657 | using namespace llvm::support; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1658 | internal_key_type ikey; |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1659 | ikey.Size = off_t(endian::readNext<uint64_t, little, unaligned>(d)); |
| 1660 | ikey.ModTime = time_t(endian::readNext<uint64_t, little, unaligned>(d)); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1661 | ikey.Filename = (const char *)d; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1662 | ikey.Imported = true; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1663 | return ikey; |
| 1664 | } |
| 1665 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1666 | HeaderFileInfoTrait::data_type |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1667 | HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1668 | unsigned DataLen) { |
| 1669 | const unsigned char *End = d + DataLen; |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1670 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1671 | HeaderFileInfo HFI; |
| 1672 | unsigned Flags = *d++; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1673 | // FIXME: Refactor with mergeHeaderFileInfo in HeaderSearch.cpp. |
| 1674 | HFI.isImport |= (Flags >> 4) & 0x01; |
| 1675 | HFI.isPragmaOnce |= (Flags >> 3) & 0x01; |
| 1676 | HFI.DirInfo = (Flags >> 1) & 0x03; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1677 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1678 | // FIXME: Find a better way to handle this. Maybe just store a |
| 1679 | // "has been included" flag? |
| 1680 | HFI.NumIncludes = std::max(endian::readNext<uint16_t, little, unaligned>(d), |
| 1681 | HFI.NumIncludes); |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1682 | HFI.ControllingMacroID = Reader.getGlobalIdentifierID( |
| 1683 | M, endian::readNext<uint32_t, little, unaligned>(d)); |
| 1684 | if (unsigned FrameworkOffset = |
| 1685 | endian::readNext<uint32_t, little, unaligned>(d)) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1686 | // The framework offset is 1 greater than the actual offset, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1687 | // since 0 is used as an indicator for "no framework name". |
| 1688 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1689 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1690 | } |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1691 | |
| 1692 | assert((End - d) % 4 == 0 && |
| 1693 | "Wrong data length in HeaderFileInfo deserialization"); |
| 1694 | while (d != End) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1695 | uint32_t LocalSMID = endian::readNext<uint32_t, little, unaligned>(d); |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1696 | auto HeaderRole = static_cast<ModuleMap::ModuleHeaderRole>(LocalSMID & 3); |
| 1697 | LocalSMID >>= 2; |
| 1698 | |
| 1699 | // This header is part of a module. Associate it with the module to enable |
| 1700 | // implicit module import. |
| 1701 | SubmoduleID GlobalSMID = Reader.getGlobalSubmoduleID(M, LocalSMID); |
| 1702 | Module *Mod = Reader.getSubmodule(GlobalSMID); |
| 1703 | FileManager &FileMgr = Reader.getFileManager(); |
| 1704 | ModuleMap &ModMap = |
| 1705 | Reader.getPreprocessor().getHeaderSearchInfo().getModuleMap(); |
| 1706 | |
| 1707 | std::string Filename = key.Filename; |
| 1708 | if (key.Imported) |
| 1709 | Reader.ResolveImportedPath(M, Filename); |
| 1710 | // FIXME: This is not always the right filename-as-written, but we're not |
| 1711 | // going to use this information to rebuild the module, so it doesn't make |
| 1712 | // a lot of difference. |
| 1713 | Module::Header H = { key.Filename, FileMgr.getFile(Filename) }; |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1714 | ModMap.addHeader(Mod, H, HeaderRole, /*Imported*/true); |
| 1715 | HFI.isModuleHeader |= !(HeaderRole & ModuleMap::TextualHeader); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1716 | } |
| 1717 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1718 | // This HeaderFileInfo was externally loaded. |
| 1719 | HFI.External = true; |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1720 | HFI.IsValid = true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1721 | return HFI; |
| 1722 | } |
| 1723 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1724 | void ASTReader::addPendingMacro(IdentifierInfo *II, |
| 1725 | ModuleFile *M, |
| 1726 | uint64_t MacroDirectivesOffset) { |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1727 | assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard"); |
| 1728 | PendingMacroIDs[II].push_back(PendingMacroInfo(M, MacroDirectivesOffset)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1729 | } |
| 1730 | |
| 1731 | void ASTReader::ReadDefinedMacros() { |
| 1732 | // Note that we are loading defined macros. |
| 1733 | Deserializing Macros(this); |
| 1734 | |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1735 | for (ModuleFile &I : llvm::reverse(ModuleMgr)) { |
| 1736 | BitstreamCursor &MacroCursor = I.MacroCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1737 | |
| 1738 | // If there was no preprocessor block, skip this file. |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 1739 | if (MacroCursor.getBitcodeBytes().empty()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1740 | continue; |
| 1741 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1742 | BitstreamCursor Cursor = MacroCursor; |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1743 | Cursor.JumpToBit(I.MacroStartOffset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1744 | |
| 1745 | RecordData Record; |
| 1746 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1747 | llvm::BitstreamEntry E = Cursor.advanceSkippingSubblocks(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1748 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1749 | switch (E.Kind) { |
| 1750 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1751 | case llvm::BitstreamEntry::Error: |
| 1752 | Error("malformed block record in AST file"); |
| 1753 | return; |
| 1754 | case llvm::BitstreamEntry::EndBlock: |
| 1755 | goto NextCursor; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1756 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1757 | case llvm::BitstreamEntry::Record: |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1758 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1759 | switch (Cursor.readRecord(E.ID, Record)) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1760 | default: // Default behavior: ignore. |
| 1761 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1762 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1763 | case PP_MACRO_OBJECT_LIKE: |
Sean Callanan | f3682a7 | 2016-05-14 06:24:14 +0000 | [diff] [blame] | 1764 | case PP_MACRO_FUNCTION_LIKE: { |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1765 | IdentifierInfo *II = getLocalIdentifier(I, Record[0]); |
Sean Callanan | f3682a7 | 2016-05-14 06:24:14 +0000 | [diff] [blame] | 1766 | if (II->isOutOfDate()) |
| 1767 | updateOutOfDateIdentifier(*II); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1768 | break; |
Sean Callanan | f3682a7 | 2016-05-14 06:24:14 +0000 | [diff] [blame] | 1769 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1770 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1771 | case PP_TOKEN: |
| 1772 | // Ignore tokens. |
| 1773 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1774 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1775 | break; |
| 1776 | } |
| 1777 | } |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1778 | NextCursor: ; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1783 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1784 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 1785 | class IdentifierLookupVisitor { |
| 1786 | StringRef Name; |
Richard Smith | 3b63741 | 2015-07-14 18:42:41 +0000 | [diff] [blame] | 1787 | unsigned NameHash; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1788 | unsigned PriorGeneration; |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1789 | unsigned &NumIdentifierLookups; |
| 1790 | unsigned &NumIdentifierLookupHits; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1791 | IdentifierInfo *Found; |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1792 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1793 | public: |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1794 | IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration, |
| 1795 | unsigned &NumIdentifierLookups, |
| 1796 | unsigned &NumIdentifierLookupHits) |
Richard Smith | 3b63741 | 2015-07-14 18:42:41 +0000 | [diff] [blame] | 1797 | : Name(Name), NameHash(ASTIdentifierLookupTrait::ComputeHash(Name)), |
| 1798 | PriorGeneration(PriorGeneration), |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1799 | NumIdentifierLookups(NumIdentifierLookups), |
| 1800 | NumIdentifierLookupHits(NumIdentifierLookupHits), |
| 1801 | Found() |
| 1802 | { |
| 1803 | } |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 1804 | |
| 1805 | bool operator()(ModuleFile &M) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1806 | // If we've already searched this module file, skip it now. |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1807 | if (M.Generation <= PriorGeneration) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1808 | return true; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1809 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1810 | ASTIdentifierLookupTable *IdTable |
| 1811 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 1812 | if (!IdTable) |
| 1813 | return false; |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 1814 | |
| 1815 | ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), M, |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1816 | Found); |
| 1817 | ++NumIdentifierLookups; |
Richard Smith | 3b63741 | 2015-07-14 18:42:41 +0000 | [diff] [blame] | 1818 | ASTIdentifierLookupTable::iterator Pos = |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1819 | IdTable->find_hashed(Name, NameHash, &Trait); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1820 | if (Pos == IdTable->end()) |
| 1821 | return false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1822 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1823 | // Dereferencing the iterator has the effect of building the |
| 1824 | // IdentifierInfo node and populating it with the various |
| 1825 | // declarations it needs. |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1826 | ++NumIdentifierLookupHits; |
| 1827 | Found = *Pos; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1828 | return true; |
| 1829 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1830 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1831 | // \brief Retrieve the identifier info found within the module |
| 1832 | // files. |
| 1833 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 1834 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1835 | |
| 1836 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1837 | |
| 1838 | void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { |
| 1839 | // Note that we are loading an identifier. |
| 1840 | Deserializing AnIdentifier(this); |
| 1841 | |
| 1842 | unsigned PriorGeneration = 0; |
| 1843 | if (getContext().getLangOpts().Modules) |
| 1844 | PriorGeneration = IdentifierGeneration[&II]; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1845 | |
| 1846 | // If there is a global index, look there first to determine which modules |
| 1847 | // provably do not have any results for this identifier. |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1848 | GlobalModuleIndex::HitSet Hits; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1849 | GlobalModuleIndex::HitSet *HitsPtr = nullptr; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1850 | if (!loadGlobalIndex()) { |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1851 | if (GlobalIndex->lookupIdentifier(II.getName(), Hits)) { |
| 1852 | HitsPtr = &Hits; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1853 | } |
| 1854 | } |
| 1855 | |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1856 | IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration, |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1857 | NumIdentifierLookups, |
| 1858 | NumIdentifierLookupHits); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 1859 | ModuleMgr.visit(Visitor, HitsPtr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1860 | markIdentifierUpToDate(&II); |
| 1861 | } |
| 1862 | |
| 1863 | void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { |
| 1864 | if (!II) |
| 1865 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1866 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1867 | II->setOutOfDate(false); |
| 1868 | |
| 1869 | // Update the generation for this identifier. |
| 1870 | if (getContext().getLangOpts().Modules) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1871 | IdentifierGeneration[II] = getGeneration(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1872 | } |
| 1873 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1874 | void ASTReader::resolvePendingMacro(IdentifierInfo *II, |
| 1875 | const PendingMacroInfo &PMInfo) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1876 | ModuleFile &M = *PMInfo.M; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1877 | |
| 1878 | BitstreamCursor &Cursor = M.MacroCursor; |
| 1879 | SavedStreamPosition SavedPosition(Cursor); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1880 | Cursor.JumpToBit(PMInfo.MacroDirectivesOffset); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1881 | |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1882 | struct ModuleMacroRecord { |
| 1883 | SubmoduleID SubModID; |
| 1884 | MacroInfo *MI; |
| 1885 | SmallVector<SubmoduleID, 8> Overrides; |
| 1886 | }; |
| 1887 | llvm::SmallVector<ModuleMacroRecord, 8> ModuleMacros; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1888 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1889 | // We expect to see a sequence of PP_MODULE_MACRO records listing exported |
| 1890 | // macros, followed by a PP_MACRO_DIRECTIVE_HISTORY record with the complete |
| 1891 | // macro histroy. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1892 | RecordData Record; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1893 | while (true) { |
| 1894 | llvm::BitstreamEntry Entry = |
| 1895 | Cursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd); |
| 1896 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| 1897 | Error("malformed block record in AST file"); |
| 1898 | return; |
| 1899 | } |
| 1900 | |
| 1901 | Record.clear(); |
Aaron Ballman | c75a192 | 2015-04-22 15:25:05 +0000 | [diff] [blame] | 1902 | switch ((PreprocessorRecordTypes)Cursor.readRecord(Entry.ID, Record)) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1903 | case PP_MACRO_DIRECTIVE_HISTORY: |
| 1904 | break; |
| 1905 | |
| 1906 | case PP_MODULE_MACRO: { |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1907 | ModuleMacros.push_back(ModuleMacroRecord()); |
| 1908 | auto &Info = ModuleMacros.back(); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1909 | Info.SubModID = getGlobalSubmoduleID(M, Record[0]); |
| 1910 | Info.MI = getMacro(getGlobalMacroID(M, Record[1])); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1911 | for (int I = 2, N = Record.size(); I != N; ++I) |
| 1912 | Info.Overrides.push_back(getGlobalSubmoduleID(M, Record[I])); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1913 | continue; |
| 1914 | } |
| 1915 | |
| 1916 | default: |
| 1917 | Error("malformed block record in AST file"); |
| 1918 | return; |
| 1919 | } |
| 1920 | |
| 1921 | // We found the macro directive history; that's the last record |
| 1922 | // for this macro. |
| 1923 | break; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1924 | } |
| 1925 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1926 | // Module macros are listed in reverse dependency order. |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1927 | { |
| 1928 | std::reverse(ModuleMacros.begin(), ModuleMacros.end()); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1929 | llvm::SmallVector<ModuleMacro*, 8> Overrides; |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1930 | for (auto &MMR : ModuleMacros) { |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1931 | Overrides.clear(); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1932 | for (unsigned ModID : MMR.Overrides) { |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 1933 | Module *Mod = getSubmodule(ModID); |
| 1934 | auto *Macro = PP.getModuleMacro(Mod, II); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1935 | assert(Macro && "missing definition for overridden macro"); |
Richard Smith | 5dbef92 | 2015-04-22 02:09:43 +0000 | [diff] [blame] | 1936 | Overrides.push_back(Macro); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | bool Inserted = false; |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1940 | Module *Owner = getSubmodule(MMR.SubModID); |
Richard Smith | 20e883e | 2015-04-29 23:20:19 +0000 | [diff] [blame] | 1941 | PP.addModuleMacro(Owner, II, MMR.MI, Overrides, Inserted); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | // Don't read the directive history for a module; we don't have anywhere |
| 1946 | // to put it. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 1947 | if (M.isModule()) |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1948 | return; |
| 1949 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1950 | // Deserialize the macro directives history in reverse source-order. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1951 | MacroDirective *Latest = nullptr, *Earliest = nullptr; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1952 | unsigned Idx = 0, N = Record.size(); |
| 1953 | while (Idx < N) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1954 | MacroDirective *MD = nullptr; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1955 | SourceLocation Loc = ReadSourceLocation(M, Record, Idx); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1956 | MacroDirective::Kind K = (MacroDirective::Kind)Record[Idx++]; |
| 1957 | switch (K) { |
| 1958 | case MacroDirective::MD_Define: { |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1959 | MacroInfo *MI = getMacro(getGlobalMacroID(M, Record[Idx++])); |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 1960 | MD = PP.AllocateDefMacroDirective(MI, Loc); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1961 | break; |
| 1962 | } |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 1963 | case MacroDirective::MD_Undefine: { |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 1964 | MD = PP.AllocateUndefMacroDirective(Loc); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1965 | break; |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 1966 | } |
| 1967 | case MacroDirective::MD_Visibility: |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1968 | bool isPublic = Record[Idx++]; |
| 1969 | MD = PP.AllocateVisibilityMacroDirective(Loc, isPublic); |
| 1970 | break; |
| 1971 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1972 | |
| 1973 | if (!Latest) |
| 1974 | Latest = MD; |
| 1975 | if (Earliest) |
| 1976 | Earliest->setPrevious(MD); |
| 1977 | Earliest = MD; |
| 1978 | } |
| 1979 | |
Richard Smith | d6e8c0d | 2015-05-04 19:58:00 +0000 | [diff] [blame] | 1980 | if (Latest) |
Nico Weber | fd87070 | 2016-12-09 17:32:52 +0000 | [diff] [blame] | 1981 | PP.setLoadedMacroDirective(II, Earliest, Latest); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1982 | } |
| 1983 | |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 1984 | ASTReader::InputFileInfo |
| 1985 | ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) { |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 1986 | // Go find this input file. |
| 1987 | BitstreamCursor &Cursor = F.InputFilesCursor; |
| 1988 | SavedStreamPosition SavedPosition(Cursor); |
| 1989 | Cursor.JumpToBit(F.InputFileOffsets[ID-1]); |
| 1990 | |
| 1991 | unsigned Code = Cursor.ReadCode(); |
| 1992 | RecordData Record; |
| 1993 | StringRef Blob; |
| 1994 | |
| 1995 | unsigned Result = Cursor.readRecord(Code, Record, &Blob); |
| 1996 | assert(static_cast<InputFileRecordTypes>(Result) == INPUT_FILE && |
| 1997 | "invalid record type for input file"); |
| 1998 | (void)Result; |
| 1999 | |
| 2000 | assert(Record[0] == ID && "Bogus stored ID or offset"); |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2001 | InputFileInfo R; |
| 2002 | R.StoredSize = static_cast<off_t>(Record[1]); |
| 2003 | R.StoredTime = static_cast<time_t>(Record[2]); |
| 2004 | R.Overridden = static_cast<bool>(Record[3]); |
| 2005 | R.Transient = static_cast<bool>(Record[4]); |
| 2006 | R.Filename = Blob; |
| 2007 | ResolveImportedPath(F, R.Filename); |
Hans Wennborg | 7394514 | 2014-03-14 17:45:06 +0000 | [diff] [blame] | 2008 | return R; |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2009 | } |
| 2010 | |
Manman Ren | c8c9415 | 2016-10-21 23:35:03 +0000 | [diff] [blame] | 2011 | static unsigned moduleKindForDiagnostic(ModuleKind Kind); |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2012 | InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2013 | // If this ID is bogus, just return an empty input file. |
| 2014 | if (ID == 0 || ID > F.InputFilesLoaded.size()) |
| 2015 | return InputFile(); |
| 2016 | |
| 2017 | // If we've already loaded this input file, return it. |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2018 | if (F.InputFilesLoaded[ID-1].getFile()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2019 | return F.InputFilesLoaded[ID-1]; |
| 2020 | |
Argyrios Kyrtzidis | 9308f0a | 2014-01-08 19:13:34 +0000 | [diff] [blame] | 2021 | if (F.InputFilesLoaded[ID-1].isNotFound()) |
| 2022 | return InputFile(); |
| 2023 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2024 | // Go find this input file. |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2025 | BitstreamCursor &Cursor = F.InputFilesCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2026 | SavedStreamPosition SavedPosition(Cursor); |
| 2027 | Cursor.JumpToBit(F.InputFileOffsets[ID-1]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2028 | |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 2029 | InputFileInfo FI = readInputFileInfo(F, ID); |
| 2030 | off_t StoredSize = FI.StoredSize; |
| 2031 | time_t StoredTime = FI.StoredTime; |
| 2032 | bool Overridden = FI.Overridden; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2033 | bool Transient = FI.Transient; |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 2034 | StringRef Filename = FI.Filename; |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2035 | |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2036 | const FileEntry *File = FileMgr.getFile(Filename, /*OpenFile=*/false); |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2037 | |
| 2038 | // If we didn't find the file, resolve it relative to the |
| 2039 | // original directory from which this AST file was created. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 2040 | if (File == nullptr && !F.OriginalDir.empty() && !CurrentDir.empty() && |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2041 | F.OriginalDir != CurrentDir) { |
| 2042 | std::string Resolved = resolveFileRelativeToOriginalDir(Filename, |
| 2043 | F.OriginalDir, |
| 2044 | CurrentDir); |
| 2045 | if (!Resolved.empty()) |
| 2046 | File = FileMgr.getFile(Resolved); |
| 2047 | } |
| 2048 | |
| 2049 | // For an overridden file, create a virtual file with the stored |
| 2050 | // size/timestamp. |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2051 | if ((Overridden || Transient) && File == nullptr) |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2052 | File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime); |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2053 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 2054 | if (File == nullptr) { |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2055 | if (Complain) { |
| 2056 | std::string ErrorStr = "could not find file '"; |
| 2057 | ErrorStr += Filename; |
Richard Smith | 6814221 | 2015-10-13 01:26:26 +0000 | [diff] [blame] | 2058 | ErrorStr += "' referenced by AST file '"; |
| 2059 | ErrorStr += F.FileName; |
| 2060 | ErrorStr += "'"; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2061 | Error(ErrorStr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2062 | } |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2063 | // Record that we didn't find the file. |
| 2064 | F.InputFilesLoaded[ID-1] = InputFile::getNotFound(); |
| 2065 | return InputFile(); |
| 2066 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2067 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2068 | // Check if there was a request to override the contents of the file |
| 2069 | // that was part of the precompiled header. Overridding such a file |
| 2070 | // can lead to problems when lexing using the source locations from the |
| 2071 | // PCH. |
| 2072 | SourceManager &SM = getSourceManager(); |
Richard Smith | 64daf7b | 2015-12-01 03:32:49 +0000 | [diff] [blame] | 2073 | // FIXME: Reject if the overrides are different. |
| 2074 | if ((!Overridden && !Transient) && SM.isFileOverridden(File)) { |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2075 | if (Complain) |
| 2076 | Error(diag::err_fe_pch_file_overridden, Filename); |
| 2077 | // After emitting the diagnostic, recover by disabling the override so |
| 2078 | // that the original file will be used. |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2079 | // |
| 2080 | // FIXME: This recovery is just as broken as the original state; there may |
| 2081 | // be another precompiled module that's using the overridden contents, or |
| 2082 | // we might be half way through parsing it. Instead, we should treat the |
| 2083 | // overridden contents as belonging to a separate FileEntry. |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2084 | SM.disableFileContentsOverride(File); |
| 2085 | // The FileEntry is a virtual file entry with the size of the contents |
| 2086 | // that would override the original contents. Set it to the original's |
| 2087 | // size/time. |
| 2088 | FileMgr.modifyFileEntry(const_cast<FileEntry*>(File), |
| 2089 | StoredSize, StoredTime); |
| 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 | bool IsOutOfDate = false; |
| 2093 | |
| 2094 | // For an overridden file, there is nothing to validate. |
Richard Smith | 96fdab6 | 2014-10-28 16:24:08 +0000 | [diff] [blame] | 2095 | if (!Overridden && // |
| 2096 | (StoredSize != File->getSize() || |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 2097 | (StoredTime && StoredTime != File->getModificationTime() && |
| 2098 | !DisableValidation) |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2099 | )) { |
| 2100 | if (Complain) { |
| 2101 | // Build a list of the PCH imports that got us here (in reverse). |
| 2102 | SmallVector<ModuleFile *, 4> ImportStack(1, &F); |
| 2103 | while (ImportStack.back()->ImportedBy.size() > 0) |
| 2104 | ImportStack.push_back(ImportStack.back()->ImportedBy[0]); |
Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 2105 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2106 | // The top-level PCH is stale. |
| 2107 | StringRef TopLevelPCHName(ImportStack.back()->FileName); |
Manman Ren | c8c9415 | 2016-10-21 23:35:03 +0000 | [diff] [blame] | 2108 | unsigned DiagnosticKind = moduleKindForDiagnostic(ImportStack.back()->Kind); |
| 2109 | if (DiagnosticKind == 0) |
| 2110 | Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName); |
| 2111 | else if (DiagnosticKind == 1) |
| 2112 | Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName); |
| 2113 | else |
| 2114 | Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName); |
Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 2115 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2116 | // Print the import stack. |
| 2117 | if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) { |
| 2118 | Diag(diag::note_pch_required_by) |
| 2119 | << Filename << ImportStack[0]->FileName; |
| 2120 | for (unsigned I = 1; I < ImportStack.size(); ++I) |
Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 2121 | Diag(diag::note_pch_required_by) |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2122 | << ImportStack[I-1]->FileName << ImportStack[I]->FileName; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 2123 | } |
| 2124 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2125 | if (!Diags.isDiagnosticInFlight()) |
| 2126 | Diag(diag::note_pch_rebuild_required) << TopLevelPCHName; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2127 | } |
| 2128 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2129 | IsOutOfDate = true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2130 | } |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2131 | // FIXME: If the file is overridden and we've already opened it, |
| 2132 | // issue an error (or split it into a separate FileEntry). |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2133 | |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2134 | InputFile IF = InputFile(File, Overridden || Transient, IsOutOfDate); |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2135 | |
| 2136 | // Note that we've loaded this input file. |
| 2137 | F.InputFilesLoaded[ID-1] = IF; |
| 2138 | return IF; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2139 | } |
| 2140 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2141 | /// \brief If we are loading a relocatable PCH or module file, and the filename |
| 2142 | /// is not an absolute path, add the system or module root to the beginning of |
| 2143 | /// the file name. |
| 2144 | void ASTReader::ResolveImportedPath(ModuleFile &M, std::string &Filename) { |
| 2145 | // Resolve relative to the base directory, if we have one. |
| 2146 | if (!M.BaseDirectory.empty()) |
| 2147 | return ResolveImportedPath(Filename, M.BaseDirectory); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2148 | } |
| 2149 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2150 | void ASTReader::ResolveImportedPath(std::string &Filename, StringRef Prefix) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2151 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
| 2152 | return; |
| 2153 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2154 | SmallString<128> Buffer; |
| 2155 | llvm::sys::path::append(Buffer, Prefix, Filename); |
| 2156 | Filename.assign(Buffer.begin(), Buffer.end()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2157 | } |
| 2158 | |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2159 | static bool isDiagnosedResult(ASTReader::ASTReadResult ARR, unsigned Caps) { |
| 2160 | switch (ARR) { |
| 2161 | case ASTReader::Failure: return true; |
| 2162 | case ASTReader::Missing: return !(Caps & ASTReader::ARR_Missing); |
| 2163 | case ASTReader::OutOfDate: return !(Caps & ASTReader::ARR_OutOfDate); |
| 2164 | case ASTReader::VersionMismatch: return !(Caps & ASTReader::ARR_VersionMismatch); |
| 2165 | case ASTReader::ConfigurationMismatch: |
| 2166 | return !(Caps & ASTReader::ARR_ConfigurationMismatch); |
| 2167 | case ASTReader::HadErrors: return true; |
| 2168 | case ASTReader::Success: return false; |
| 2169 | } |
| 2170 | |
| 2171 | llvm_unreachable("unknown ASTReadResult"); |
| 2172 | } |
| 2173 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2174 | ASTReader::ASTReadResult ASTReader::ReadOptionsBlock( |
| 2175 | BitstreamCursor &Stream, unsigned ClientLoadCapabilities, |
| 2176 | bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener, |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2177 | std::string &SuggestedPredefines) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2178 | if (Stream.EnterSubBlock(OPTIONS_BLOCK_ID)) |
| 2179 | return Failure; |
| 2180 | |
| 2181 | // Read all of the records in the options block. |
| 2182 | RecordData Record; |
| 2183 | ASTReadResult Result = Success; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2184 | while (true) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2185 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2186 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2187 | switch (Entry.Kind) { |
| 2188 | case llvm::BitstreamEntry::Error: |
| 2189 | case llvm::BitstreamEntry::SubBlock: |
| 2190 | return Failure; |
| 2191 | |
| 2192 | case llvm::BitstreamEntry::EndBlock: |
| 2193 | return Result; |
| 2194 | |
| 2195 | case llvm::BitstreamEntry::Record: |
| 2196 | // The interesting case. |
| 2197 | break; |
| 2198 | } |
| 2199 | |
| 2200 | // Read and process a record. |
| 2201 | Record.clear(); |
| 2202 | switch ((OptionsRecordTypes)Stream.readRecord(Entry.ID, Record)) { |
| 2203 | case LANGUAGE_OPTIONS: { |
| 2204 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2205 | if (ParseLanguageOptions(Record, Complain, Listener, |
| 2206 | AllowCompatibleConfigurationMismatch)) |
| 2207 | Result = ConfigurationMismatch; |
| 2208 | break; |
| 2209 | } |
| 2210 | |
| 2211 | case TARGET_OPTIONS: { |
| 2212 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2213 | if (ParseTargetOptions(Record, Complain, Listener, |
| 2214 | AllowCompatibleConfigurationMismatch)) |
| 2215 | Result = ConfigurationMismatch; |
| 2216 | break; |
| 2217 | } |
| 2218 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2219 | case FILE_SYSTEM_OPTIONS: { |
| 2220 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2221 | if (!AllowCompatibleConfigurationMismatch && |
| 2222 | ParseFileSystemOptions(Record, Complain, Listener)) |
| 2223 | Result = ConfigurationMismatch; |
| 2224 | break; |
| 2225 | } |
| 2226 | |
| 2227 | case HEADER_SEARCH_OPTIONS: { |
| 2228 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2229 | if (!AllowCompatibleConfigurationMismatch && |
| 2230 | ParseHeaderSearchOptions(Record, Complain, Listener)) |
| 2231 | Result = ConfigurationMismatch; |
| 2232 | break; |
| 2233 | } |
| 2234 | |
| 2235 | case PREPROCESSOR_OPTIONS: |
| 2236 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2237 | if (!AllowCompatibleConfigurationMismatch && |
| 2238 | ParsePreprocessorOptions(Record, Complain, Listener, |
| 2239 | SuggestedPredefines)) |
| 2240 | Result = ConfigurationMismatch; |
| 2241 | break; |
| 2242 | } |
| 2243 | } |
| 2244 | } |
| 2245 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2246 | ASTReader::ASTReadResult |
| 2247 | ASTReader::ReadControlBlock(ModuleFile &F, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2248 | SmallVectorImpl<ImportedModule> &Loaded, |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2249 | const ModuleFile *ImportedBy, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2250 | unsigned ClientLoadCapabilities) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2251 | BitstreamCursor &Stream = F.Stream; |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2252 | ASTReadResult Result = Success; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2253 | |
| 2254 | if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
| 2255 | Error("malformed block record in AST file"); |
| 2256 | return Failure; |
| 2257 | } |
| 2258 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2259 | // Lambda to read the unhashed control block the first time it's called. |
| 2260 | // |
| 2261 | // For PCM files, the unhashed control block cannot be read until after the |
| 2262 | // MODULE_NAME record. However, PCH files have no MODULE_NAME, and yet still |
| 2263 | // need to look ahead before reading the IMPORTS record. For consistency, |
| 2264 | // this block is always read somehow (see BitstreamEntry::EndBlock). |
| 2265 | bool HasReadUnhashedControlBlock = false; |
| 2266 | auto readUnhashedControlBlockOnce = [&]() { |
| 2267 | if (!HasReadUnhashedControlBlock) { |
| 2268 | HasReadUnhashedControlBlock = true; |
| 2269 | if (ASTReadResult Result = |
| 2270 | readUnhashedControlBlock(F, ImportedBy, ClientLoadCapabilities)) |
| 2271 | return Result; |
| 2272 | } |
| 2273 | return Success; |
| 2274 | }; |
| 2275 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2276 | // Read all of the records and blocks in the control block. |
| 2277 | RecordData Record; |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2278 | unsigned NumInputs = 0; |
| 2279 | unsigned NumUserInputs = 0; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2280 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2281 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2282 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2283 | switch (Entry.Kind) { |
| 2284 | case llvm::BitstreamEntry::Error: |
| 2285 | Error("malformed block record in AST file"); |
| 2286 | return Failure; |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2287 | case llvm::BitstreamEntry::EndBlock: { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2288 | // Validate the module before returning. This call catches an AST with |
| 2289 | // no module name and no imports. |
| 2290 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2291 | return Result; |
| 2292 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2293 | // Validate input files. |
| 2294 | const HeaderSearchOptions &HSOpts = |
| 2295 | PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2296 | |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2297 | // All user input files reside at the index range [0, NumUserInputs), and |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2298 | // system input files reside at [NumUserInputs, NumInputs). For explicitly |
| 2299 | // loaded module files, ignore missing inputs. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2300 | if (!DisableValidation && F.Kind != MK_ExplicitModule && |
| 2301 | F.Kind != MK_PrebuiltModule) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2302 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2303 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2304 | // If we are reading a module, we will create a verification timestamp, |
| 2305 | // so we verify all input files. Otherwise, verify only user input |
| 2306 | // files. |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2307 | |
| 2308 | unsigned N = NumUserInputs; |
| 2309 | if (ValidateSystemInputs || |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 2310 | (HSOpts.ModulesValidateOncePerBuildSession && |
Ben Langmuir | acb803e | 2014-11-10 22:13:10 +0000 | [diff] [blame] | 2311 | F.InputFilesValidationTimestamp <= HSOpts.BuildSessionTimestamp && |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 2312 | F.Kind == MK_ImplicitModule)) |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2313 | N = NumInputs; |
| 2314 | |
Ben Langmuir | 3d4417c | 2014-02-07 17:31:11 +0000 | [diff] [blame] | 2315 | for (unsigned I = 0; I < N; ++I) { |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2316 | InputFile IF = getInputFile(F, I+1, Complain); |
| 2317 | if (!IF.getFile() || IF.isOutOfDate()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2318 | return OutOfDate; |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2319 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2320 | } |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2321 | |
Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 2322 | if (Listener) |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 2323 | Listener->visitModuleFile(F.FileName, F.Kind); |
Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 2324 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2325 | if (Listener && Listener->needsInputFileVisitation()) { |
| 2326 | unsigned N = Listener->needsSystemInputFileVisitation() ? NumInputs |
| 2327 | : NumUserInputs; |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 2328 | for (unsigned I = 0; I < N; ++I) { |
| 2329 | bool IsSystem = I >= NumUserInputs; |
| 2330 | InputFileInfo FI = readInputFileInfo(F, I+1); |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 2331 | Listener->visitInputFile(FI.Filename, IsSystem, FI.Overridden, |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2332 | F.Kind == MK_ExplicitModule || |
| 2333 | F.Kind == MK_PrebuiltModule); |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 2334 | } |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2337 | return Result; |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2338 | } |
| 2339 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2340 | case llvm::BitstreamEntry::SubBlock: |
| 2341 | switch (Entry.ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2342 | case INPUT_FILES_BLOCK_ID: |
| 2343 | F.InputFilesCursor = Stream; |
| 2344 | if (Stream.SkipBlock() || // Skip with the main cursor |
| 2345 | // Read the abbreviations |
| 2346 | ReadBlockAbbrevs(F.InputFilesCursor, INPUT_FILES_BLOCK_ID)) { |
| 2347 | Error("malformed block record in AST file"); |
| 2348 | return Failure; |
| 2349 | } |
| 2350 | continue; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2351 | |
| 2352 | case OPTIONS_BLOCK_ID: |
| 2353 | // If we're reading the first module for this group, check its options |
| 2354 | // are compatible with ours. For modules it imports, no further checking |
| 2355 | // is required, because we checked them when we built it. |
| 2356 | if (Listener && !ImportedBy) { |
| 2357 | // Should we allow the configuration of the module file to differ from |
| 2358 | // the configuration of the current translation unit in a compatible |
| 2359 | // way? |
| 2360 | // |
| 2361 | // FIXME: Allow this for files explicitly specified with -include-pch. |
| 2362 | bool AllowCompatibleConfigurationMismatch = |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2363 | F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2364 | |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2365 | Result = ReadOptionsBlock(Stream, ClientLoadCapabilities, |
| 2366 | AllowCompatibleConfigurationMismatch, |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2367 | *Listener, SuggestedPredefines); |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2368 | if (Result == Failure) { |
| 2369 | Error("malformed block record in AST file"); |
| 2370 | return Result; |
| 2371 | } |
| 2372 | |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2373 | if (DisableValidation || |
| 2374 | (AllowConfigurationMismatch && Result == ConfigurationMismatch)) |
| 2375 | Result = Success; |
| 2376 | |
Ben Langmuir | 9b1e442e | 2016-02-11 18:54:02 +0000 | [diff] [blame] | 2377 | // If we can't load the module, exit early since we likely |
| 2378 | // will rebuild the module anyway. The stream may be in the |
| 2379 | // middle of a block. |
| 2380 | if (Result != Success) |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2381 | return Result; |
| 2382 | } else if (Stream.SkipBlock()) { |
| 2383 | Error("malformed block record in AST file"); |
| 2384 | return Failure; |
| 2385 | } |
| 2386 | continue; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2387 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2388 | default: |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2389 | if (Stream.SkipBlock()) { |
| 2390 | Error("malformed block record in AST file"); |
| 2391 | return Failure; |
| 2392 | } |
| 2393 | continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2394 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2395 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2396 | case llvm::BitstreamEntry::Record: |
| 2397 | // The interesting case. |
| 2398 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | // Read and process a record. |
| 2402 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2403 | StringRef Blob; |
| 2404 | switch ((ControlRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2405 | case METADATA: { |
| 2406 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 2407 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 2408 | Diag(Record[0] < VERSION_MAJOR? diag::err_pch_version_too_old |
| 2409 | : diag::err_pch_version_too_new); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2410 | return VersionMismatch; |
| 2411 | } |
| 2412 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 2413 | bool hasErrors = Record[6]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2414 | if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) { |
| 2415 | Diag(diag::err_pch_with_compiler_errors); |
| 2416 | return HadErrors; |
| 2417 | } |
Argyrios Kyrtzidis | 70ec1c7 | 2016-07-13 20:35:26 +0000 | [diff] [blame] | 2418 | if (hasErrors) { |
| 2419 | Diags.ErrorOccurred = true; |
| 2420 | Diags.UncompilableErrorOccurred = true; |
| 2421 | Diags.UnrecoverableErrorOccurred = true; |
| 2422 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2423 | |
| 2424 | F.RelocatablePCH = Record[4]; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2425 | // Relative paths in a relocatable PCH are relative to our sysroot. |
| 2426 | if (F.RelocatablePCH) |
| 2427 | F.BaseDirectory = isysroot.empty() ? "/" : isysroot; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2428 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 2429 | F.HasTimestamps = Record[5]; |
| 2430 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2431 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2432 | StringRef ASTBranch = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2433 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2434 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 2435 | Diag(diag::err_pch_different_branch) << ASTBranch << CurBranch; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2436 | return VersionMismatch; |
| 2437 | } |
| 2438 | break; |
| 2439 | } |
| 2440 | |
| 2441 | case IMPORTS: { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2442 | // Validate the AST before processing any imports (otherwise, untangling |
| 2443 | // them can be error-prone and expensive). A module will have a name and |
| 2444 | // will already have been validated, but this catches the PCH case. |
| 2445 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2446 | return Result; |
| 2447 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2448 | // Load each of the imported PCH files. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2449 | unsigned Idx = 0, N = Record.size(); |
| 2450 | while (Idx < N) { |
| 2451 | // Read information about the AST file. |
| 2452 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 2453 | // The import location will be the local one for now; we will adjust |
| 2454 | // all import locations of module imports after the global source |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2455 | // location info are setup, in ReadAST. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2456 | SourceLocation ImportLoc = |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2457 | ReadUntranslatedSourceLocation(Record[Idx++]); |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 2458 | off_t StoredSize = (off_t)Record[Idx++]; |
| 2459 | time_t StoredModTime = (time_t)Record[Idx++]; |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2460 | ASTFileSignature StoredSignature = { |
| 2461 | {{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++], |
| 2462 | (uint32_t)Record[Idx++], (uint32_t)Record[Idx++], |
| 2463 | (uint32_t)Record[Idx++]}}}; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2464 | auto ImportedFile = ReadPath(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2465 | |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2466 | // If our client can't cope with us being out of date, we can't cope with |
| 2467 | // our dependency being missing. |
| 2468 | unsigned Capabilities = ClientLoadCapabilities; |
| 2469 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 2470 | Capabilities &= ~ARR_Missing; |
| 2471 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2472 | // Load the AST file. |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2473 | auto Result = ReadASTCore(ImportedFile, ImportedKind, ImportLoc, &F, |
| 2474 | Loaded, StoredSize, StoredModTime, |
| 2475 | StoredSignature, Capabilities); |
| 2476 | |
| 2477 | // If we diagnosed a problem, produce a backtrace. |
| 2478 | if (isDiagnosedResult(Result, Capabilities)) |
| 2479 | Diag(diag::note_module_file_imported_by) |
| 2480 | << F.FileName << !F.ModuleName.empty() << F.ModuleName; |
| 2481 | |
| 2482 | switch (Result) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2483 | case Failure: return Failure; |
| 2484 | // 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] | 2485 | case Missing: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2486 | case OutOfDate: return OutOfDate; |
| 2487 | case VersionMismatch: return VersionMismatch; |
| 2488 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 2489 | case HadErrors: return HadErrors; |
| 2490 | case Success: break; |
| 2491 | } |
| 2492 | } |
| 2493 | break; |
| 2494 | } |
| 2495 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2496 | case ORIGINAL_FILE: |
| 2497 | F.OriginalSourceFileID = FileID::get(Record[0]); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2498 | F.ActualOriginalSourceFileName = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2499 | F.OriginalSourceFileName = F.ActualOriginalSourceFileName; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2500 | ResolveImportedPath(F, F.OriginalSourceFileName); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2501 | break; |
| 2502 | |
| 2503 | case ORIGINAL_FILE_ID: |
| 2504 | F.OriginalSourceFileID = FileID::get(Record[0]); |
| 2505 | break; |
| 2506 | |
| 2507 | case ORIGINAL_PCH_DIR: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2508 | F.OriginalDir = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2509 | break; |
| 2510 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2511 | case MODULE_NAME: |
| 2512 | F.ModuleName = Blob; |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 2513 | if (Listener) |
| 2514 | Listener->ReadModuleName(F.ModuleName); |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2515 | |
| 2516 | // Validate the AST as soon as we have a name so we can exit early on |
| 2517 | // failure. |
| 2518 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2519 | return Result; |
| 2520 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2521 | break; |
| 2522 | |
Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2523 | case MODULE_DIRECTORY: { |
| 2524 | assert(!F.ModuleName.empty() && |
| 2525 | "MODULE_DIRECTORY found before MODULE_NAME"); |
| 2526 | // If we've already loaded a module map file covering this module, we may |
| 2527 | // have a better path for it (relative to the current build). |
| 2528 | Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName); |
| 2529 | if (M && M->Directory) { |
| 2530 | // If we're implicitly loading a module, the base directory can't |
| 2531 | // change between the build and use. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2532 | if (F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) { |
Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2533 | const DirectoryEntry *BuildDir = |
| 2534 | PP.getFileManager().getDirectory(Blob); |
| 2535 | if (!BuildDir || BuildDir != M->Directory) { |
| 2536 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 2537 | Diag(diag::err_imported_module_relocated) |
| 2538 | << F.ModuleName << Blob << M->Directory->getName(); |
| 2539 | return OutOfDate; |
| 2540 | } |
| 2541 | } |
| 2542 | F.BaseDirectory = M->Directory->getName(); |
| 2543 | } else { |
| 2544 | F.BaseDirectory = Blob; |
| 2545 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2546 | break; |
Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2547 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2548 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2549 | case MODULE_MAP_FILE: |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 2550 | if (ASTReadResult Result = |
| 2551 | ReadModuleMapFileBlock(Record, F, ImportedBy, ClientLoadCapabilities)) |
| 2552 | return Result; |
Ben Langmuir | 264ea15 | 2014-11-08 00:06:39 +0000 | [diff] [blame] | 2553 | break; |
| 2554 | |
Justin Bogner | ca9c0cc | 2015-06-21 20:32:36 +0000 | [diff] [blame] | 2555 | case INPUT_FILE_OFFSETS: |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2556 | NumInputs = Record[0]; |
| 2557 | NumUserInputs = Record[1]; |
Justin Bogner | 4c18324 | 2015-06-21 20:32:40 +0000 | [diff] [blame] | 2558 | F.InputFileOffsets = |
| 2559 | (const llvm::support::unaligned_uint64_t *)Blob.data(); |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2560 | F.InputFilesLoaded.resize(NumInputs); |
Argyrios Kyrtzidis | a38cb20 | 2017-01-30 06:05:58 +0000 | [diff] [blame] | 2561 | F.NumUserInputFiles = NumUserInputs; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2562 | break; |
| 2563 | } |
| 2564 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2565 | } |
| 2566 | |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2567 | ASTReader::ASTReadResult |
| 2568 | ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2569 | BitstreamCursor &Stream = F.Stream; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2570 | |
| 2571 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
| 2572 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2573 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | // Read all of the records and blocks for the AST file. |
| 2577 | RecordData Record; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2578 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2579 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2580 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2581 | switch (Entry.Kind) { |
| 2582 | case llvm::BitstreamEntry::Error: |
| 2583 | Error("error at end of module block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2584 | return Failure; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2585 | case llvm::BitstreamEntry::EndBlock: { |
Richard Smith | c0fbba7 | 2013-04-03 22:49:41 +0000 | [diff] [blame] | 2586 | // Outside of C++, we do not store a lookup map for the translation unit. |
| 2587 | // Instead, mark it as needing a lookup map to be built if this module |
| 2588 | // contains any declarations lexically within it (which it always does!). |
| 2589 | // This usually has no cost, since we very rarely need the lookup map for |
| 2590 | // the translation unit outside C++. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2591 | DeclContext *DC = Context.getTranslationUnitDecl(); |
Richard Smith | c0fbba7 | 2013-04-03 22:49:41 +0000 | [diff] [blame] | 2592 | if (DC->hasExternalLexicalStorage() && |
| 2593 | !getContext().getLangOpts().CPlusPlus) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2594 | DC->setMustBuildLookupTable(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2595 | |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2596 | return Success; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2597 | } |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2598 | case llvm::BitstreamEntry::SubBlock: |
| 2599 | switch (Entry.ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2600 | case DECLTYPES_BLOCK_ID: |
| 2601 | // We lazily load the decls block, but we want to set up the |
| 2602 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 2603 | // cursor to it, enter the block and read the abbrevs in that block. |
| 2604 | // With the main cursor, we just skip over it. |
| 2605 | F.DeclsCursor = Stream; |
| 2606 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 2607 | // Read the abbrevs. |
| 2608 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
| 2609 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2610 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2611 | } |
| 2612 | break; |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 2613 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2614 | case PREPROCESSOR_BLOCK_ID: |
| 2615 | F.MacroCursor = Stream; |
| 2616 | if (!PP.getExternalSource()) |
| 2617 | PP.setExternalSource(this); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2618 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2619 | if (Stream.SkipBlock() || |
| 2620 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
| 2621 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2622 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2623 | } |
| 2624 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
| 2625 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2626 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2627 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 2628 | F.PreprocessorDetailCursor = Stream; |
| 2629 | if (Stream.SkipBlock() || |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2630 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2631 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2632 | Error("malformed preprocessor detail record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2633 | return Failure; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2634 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2635 | F.PreprocessorDetailStartOffset |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2636 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2637 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2638 | if (!PP.getPreprocessingRecord()) |
| 2639 | PP.createPreprocessingRecord(); |
| 2640 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2641 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2642 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2643 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2644 | case SOURCE_MANAGER_BLOCK_ID: |
| 2645 | if (ReadSourceManagerBlock(F)) |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2646 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2647 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2648 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2649 | case SUBMODULE_BLOCK_ID: |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2650 | if (ASTReadResult Result = |
| 2651 | ReadSubmoduleBlock(F, ClientLoadCapabilities)) |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2652 | return Result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2653 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2654 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2655 | case COMMENTS_BLOCK_ID: { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2656 | BitstreamCursor C = Stream; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2657 | if (Stream.SkipBlock() || |
| 2658 | ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) { |
| 2659 | Error("malformed comments block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2660 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2661 | } |
| 2662 | CommentsCursors.push_back(std::make_pair(C, &F)); |
| 2663 | break; |
| 2664 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2665 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2666 | default: |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2667 | if (Stream.SkipBlock()) { |
| 2668 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2669 | return Failure; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2670 | } |
| 2671 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2672 | } |
| 2673 | continue; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2674 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2675 | case llvm::BitstreamEntry::Record: |
| 2676 | // The interesting case. |
| 2677 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | // Read and process a record. |
| 2681 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2682 | StringRef Blob; |
| 2683 | switch ((ASTRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2684 | default: // Default behavior: ignore. |
| 2685 | break; |
| 2686 | |
| 2687 | case TYPE_OFFSET: { |
| 2688 | if (F.LocalNumTypes != 0) { |
| 2689 | Error("duplicate TYPE_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2690 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2691 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2692 | F.TypeOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2693 | F.LocalNumTypes = Record[0]; |
| 2694 | unsigned LocalBaseTypeIndex = Record[1]; |
| 2695 | F.BaseTypeIndex = getTotalNumTypes(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2696 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2697 | if (F.LocalNumTypes > 0) { |
| 2698 | // Introduce the global -> local mapping for types within this module. |
| 2699 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2700 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2701 | // Introduce the local -> global mapping for types within this module. |
| 2702 | F.TypeRemap.insertOrReplace( |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2703 | std::make_pair(LocalBaseTypeIndex, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2704 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2705 | |
| 2706 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2707 | } |
| 2708 | break; |
| 2709 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2710 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2711 | case DECL_OFFSET: { |
| 2712 | if (F.LocalNumDecls != 0) { |
| 2713 | Error("duplicate DECL_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2714 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2715 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2716 | F.DeclOffsets = (const DeclOffset *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2717 | F.LocalNumDecls = Record[0]; |
| 2718 | unsigned LocalBaseDeclID = Record[1]; |
| 2719 | F.BaseDeclID = getTotalNumDecls(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2720 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2721 | if (F.LocalNumDecls > 0) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2722 | // Introduce the global -> local mapping for declarations within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2723 | // module. |
| 2724 | GlobalDeclMap.insert( |
| 2725 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2726 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2727 | // Introduce the local -> global mapping for declarations within this |
| 2728 | // module. |
| 2729 | F.DeclRemap.insertOrReplace( |
| 2730 | std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2731 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2732 | // Introduce the global -> local mapping for declarations within this |
| 2733 | // module. |
| 2734 | F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID; |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 2735 | |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2736 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 2737 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2738 | break; |
| 2739 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2740 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2741 | case TU_UPDATE_LEXICAL: { |
| 2742 | DeclContext *TU = Context.getTranslationUnitDecl(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2743 | LexicalContents Contents( |
| 2744 | reinterpret_cast<const llvm::support::unaligned_uint32_t *>( |
| 2745 | Blob.data()), |
| 2746 | static_cast<unsigned int>(Blob.size() / 4)); |
| 2747 | TULexicalDecls.push_back(std::make_pair(&F, Contents)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2748 | TU->setHasExternalLexicalStorage(true); |
| 2749 | break; |
| 2750 | } |
| 2751 | |
| 2752 | case UPDATE_VISIBLE: { |
| 2753 | unsigned Idx = 0; |
| 2754 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 2755 | auto *Data = (const unsigned char*)Blob.data(); |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 2756 | PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&F, Data}); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 2757 | // If we've already loaded the decl, perform the updates when we finish |
| 2758 | // loading this block. |
| 2759 | if (Decl *D = GetExistingDecl(ID)) |
| 2760 | PendingUpdateRecords.push_back(std::make_pair(ID, D)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2761 | break; |
| 2762 | } |
| 2763 | |
| 2764 | case IDENTIFIER_TABLE: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2765 | F.IdentifierTableData = Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2766 | if (Record[0]) { |
Justin Bogner | da4e650 | 2014-04-14 16:34:29 +0000 | [diff] [blame] | 2767 | F.IdentifierLookupTable = ASTIdentifierLookupTable::Create( |
| 2768 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2769 | (const unsigned char *)F.IdentifierTableData + sizeof(uint32_t), |
| 2770 | (const unsigned char *)F.IdentifierTableData, |
| 2771 | ASTIdentifierLookupTrait(*this, F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2772 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2773 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
| 2774 | } |
| 2775 | break; |
| 2776 | |
| 2777 | case IDENTIFIER_OFFSET: { |
| 2778 | if (F.LocalNumIdentifiers != 0) { |
| 2779 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2780 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2781 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2782 | F.IdentifierOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2783 | F.LocalNumIdentifiers = Record[0]; |
| 2784 | unsigned LocalBaseIdentifierID = Record[1]; |
| 2785 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2786 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2787 | if (F.LocalNumIdentifiers > 0) { |
| 2788 | // Introduce the global -> local mapping for identifiers within this |
| 2789 | // module. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2790 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2791 | &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2792 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2793 | // Introduce the local -> global mapping for identifiers within this |
| 2794 | // module. |
| 2795 | F.IdentifierRemap.insertOrReplace( |
| 2796 | std::make_pair(LocalBaseIdentifierID, |
| 2797 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 2798 | |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2799 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 2800 | + F.LocalNumIdentifiers); |
| 2801 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2802 | break; |
| 2803 | } |
| 2804 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 2805 | case INTERESTING_IDENTIFIERS: |
| 2806 | F.PreloadIdentifierOffsets.assign(Record.begin(), Record.end()); |
| 2807 | break; |
| 2808 | |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2809 | case EAGERLY_DESERIALIZED_DECLS: |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 2810 | // FIXME: Skip reading this record if our ASTConsumer doesn't care |
| 2811 | // about "interesting" decls (for instance, if we're building a module). |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2812 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2813 | EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2814 | break; |
| 2815 | |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2816 | case MODULAR_CODEGEN_DECLS: |
| 2817 | // FIXME: Skip reading this record if our ASTConsumer doesn't care about |
| 2818 | // them (ie: if we're not codegenerating this module). |
| 2819 | if (F.Kind == MK_MainFile) |
| 2820 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2821 | EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2822 | break; |
| 2823 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2824 | case SPECIAL_TYPES: |
Douglas Gregor | 44180f8 | 2013-02-01 23:45:03 +0000 | [diff] [blame] | 2825 | if (SpecialTypes.empty()) { |
| 2826 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2827 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
| 2828 | break; |
| 2829 | } |
| 2830 | |
| 2831 | if (SpecialTypes.size() != Record.size()) { |
| 2832 | Error("invalid special-types record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2833 | return Failure; |
Douglas Gregor | 44180f8 | 2013-02-01 23:45:03 +0000 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 2837 | serialization::TypeID ID = getGlobalTypeID(F, Record[I]); |
| 2838 | if (!SpecialTypes[I]) |
| 2839 | SpecialTypes[I] = ID; |
| 2840 | // FIXME: If ID && SpecialTypes[I] != ID, do we need a separate |
| 2841 | // merge step? |
| 2842 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2843 | break; |
| 2844 | |
| 2845 | case STATISTICS: |
| 2846 | TotalNumStatements += Record[0]; |
| 2847 | TotalNumMacros += Record[1]; |
| 2848 | TotalLexicalDeclContexts += Record[2]; |
| 2849 | TotalVisibleDeclContexts += Record[3]; |
| 2850 | break; |
| 2851 | |
| 2852 | case UNUSED_FILESCOPED_DECLS: |
| 2853 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2854 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2855 | break; |
| 2856 | |
| 2857 | case DELEGATING_CTORS: |
| 2858 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2859 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2860 | break; |
| 2861 | |
| 2862 | case WEAK_UNDECLARED_IDENTIFIERS: |
| 2863 | if (Record.size() % 4 != 0) { |
| 2864 | Error("invalid weak identifiers record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2865 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2866 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2867 | |
| 2868 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2869 | // files. This isn't the way to do it :) |
| 2870 | WeakUndeclaredIdentifiers.clear(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2871 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2872 | // Translate the weak, undeclared identifiers into global IDs. |
| 2873 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 2874 | WeakUndeclaredIdentifiers.push_back( |
| 2875 | getGlobalIdentifierID(F, Record[I++])); |
| 2876 | WeakUndeclaredIdentifiers.push_back( |
| 2877 | getGlobalIdentifierID(F, Record[I++])); |
| 2878 | WeakUndeclaredIdentifiers.push_back( |
| 2879 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2880 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 2881 | } |
| 2882 | break; |
| 2883 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2884 | case SELECTOR_OFFSETS: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2885 | F.SelectorOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2886 | F.LocalNumSelectors = Record[0]; |
| 2887 | unsigned LocalBaseSelectorID = Record[1]; |
| 2888 | F.BaseSelectorID = getTotalNumSelectors(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2889 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2890 | if (F.LocalNumSelectors > 0) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2891 | // Introduce the global -> local mapping for selectors within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2892 | // module. |
| 2893 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2894 | |
| 2895 | // Introduce the local -> global mapping for selectors within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2896 | // module. |
| 2897 | F.SelectorRemap.insertOrReplace( |
| 2898 | std::make_pair(LocalBaseSelectorID, |
| 2899 | F.BaseSelectorID - LocalBaseSelectorID)); |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2900 | |
| 2901 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2902 | } |
| 2903 | break; |
| 2904 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2905 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2906 | case METHOD_POOL: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2907 | F.SelectorLookupTableData = (const unsigned char *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2908 | if (Record[0]) |
| 2909 | F.SelectorLookupTable |
| 2910 | = ASTSelectorLookupTable::Create( |
| 2911 | F.SelectorLookupTableData + Record[0], |
| 2912 | F.SelectorLookupTableData, |
| 2913 | ASTSelectorLookupTrait(*this, F)); |
| 2914 | TotalNumMethodPoolEntries += Record[1]; |
| 2915 | break; |
| 2916 | |
| 2917 | case REFERENCED_SELECTOR_POOL: |
| 2918 | if (!Record.empty()) { |
| 2919 | 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] | 2920 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2921 | Record[Idx++])); |
| 2922 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2923 | getRawEncoding()); |
| 2924 | } |
| 2925 | } |
| 2926 | break; |
| 2927 | |
| 2928 | case PP_COUNTER_VALUE: |
| 2929 | if (!Record.empty() && Listener) |
| 2930 | Listener->ReadCounter(F, Record[0]); |
| 2931 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2932 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2933 | case FILE_SORTED_DECLS: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2934 | F.FileSortedDecls = (const DeclID *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2935 | F.NumFileSortedDecls = Record[0]; |
| 2936 | break; |
| 2937 | |
| 2938 | case SOURCE_LOCATION_OFFSETS: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2939 | F.SLocEntryOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2940 | F.LocalNumSLocEntries = Record[0]; |
| 2941 | unsigned SLocSpaceSize = Record[1]; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 2942 | std::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2943 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2944 | SLocSpaceSize); |
Richard Smith | 78d81ec | 2015-08-12 22:25:24 +0000 | [diff] [blame] | 2945 | if (!F.SLocEntryBaseID) { |
| 2946 | Error("ran out of source locations"); |
| 2947 | break; |
| 2948 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2949 | // Make our entry in the range map. BaseID is negative and growing, so |
| 2950 | // we invert it. Because we invert it, though, we need the other end of |
| 2951 | // the range. |
| 2952 | unsigned RangeStart = |
| 2953 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 2954 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 2955 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 2956 | |
| 2957 | // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. |
| 2958 | assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); |
| 2959 | GlobalSLocOffsetMap.insert( |
| 2960 | std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset |
| 2961 | - SLocSpaceSize,&F)); |
| 2962 | |
| 2963 | // Initialize the remapping table. |
| 2964 | // Invalid stays invalid. |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 2965 | F.SLocRemap.insertOrReplace(std::make_pair(0U, 0)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2966 | // This module. Base was 2 when being compiled. |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 2967 | F.SLocRemap.insertOrReplace(std::make_pair(2U, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2968 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2969 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2970 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
| 2971 | break; |
| 2972 | } |
| 2973 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 2974 | case MODULE_OFFSET_MAP: |
| 2975 | F.ModuleOffsetMap = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2976 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2977 | |
| 2978 | case SOURCE_MANAGER_LINE_TABLE: |
| 2979 | if (ParseLineTable(F, Record)) |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2980 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2981 | break; |
| 2982 | |
| 2983 | case SOURCE_LOCATION_PRELOADS: { |
| 2984 | // Need to transform from the local view (1-based IDs) to the global view, |
| 2985 | // which is based off F.SLocEntryBaseID. |
| 2986 | if (!F.PreloadSLocEntries.empty()) { |
| 2987 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2988 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2989 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2990 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2991 | F.PreloadSLocEntries.swap(Record); |
| 2992 | break; |
| 2993 | } |
| 2994 | |
| 2995 | case EXT_VECTOR_DECLS: |
| 2996 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2997 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2998 | break; |
| 2999 | |
| 3000 | case VTABLE_USES: |
| 3001 | if (Record.size() % 3 != 0) { |
| 3002 | Error("Invalid VTABLE_USES record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3003 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3004 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3005 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3006 | // Later tables overwrite earlier ones. |
| 3007 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 3008 | // the right way to do this. |
| 3009 | VTableUses.clear(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3010 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3011 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 3012 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 3013 | VTableUses.push_back( |
| 3014 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 3015 | VTableUses.push_back(Record[Idx++]); |
| 3016 | } |
| 3017 | break; |
| 3018 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3019 | case PENDING_IMPLICIT_INSTANTIATIONS: |
| 3020 | if (PendingInstantiations.size() % 2 != 0) { |
| 3021 | Error("Invalid existing PendingInstantiations"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3022 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3023 | } |
| 3024 | |
| 3025 | if (Record.size() % 2 != 0) { |
| 3026 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3027 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 3031 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 3032 | PendingInstantiations.push_back( |
| 3033 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3034 | } |
| 3035 | break; |
| 3036 | |
| 3037 | case SEMA_DECL_REFS: |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 3038 | if (Record.size() != 3) { |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 3039 | Error("Invalid SEMA_DECL_REFS block"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3040 | return Failure; |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 3041 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3042 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3043 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
| 3044 | break; |
| 3045 | |
| 3046 | case PPD_ENTITIES_OFFSETS: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3047 | F.PreprocessedEntityOffsets = (const PPEntityOffset *)Blob.data(); |
| 3048 | assert(Blob.size() % sizeof(PPEntityOffset) == 0); |
| 3049 | F.NumPreprocessedEntities = Blob.size() / sizeof(PPEntityOffset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3050 | |
| 3051 | unsigned LocalBasePreprocessedEntityID = Record[0]; |
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 | unsigned StartingID; |
| 3054 | if (!PP.getPreprocessingRecord()) |
| 3055 | PP.createPreprocessingRecord(); |
| 3056 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 3057 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3058 | StartingID |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3059 | = PP.getPreprocessingRecord() |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3060 | ->allocateLoadedEntities(F.NumPreprocessedEntities); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3061 | F.BasePreprocessedEntityID = StartingID; |
| 3062 | |
| 3063 | if (F.NumPreprocessedEntities > 0) { |
| 3064 | // Introduce the global -> local mapping for preprocessed entities in |
| 3065 | // this module. |
| 3066 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3067 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3068 | // Introduce the local -> global mapping for preprocessed entities in |
| 3069 | // this module. |
| 3070 | F.PreprocessedEntityRemap.insertOrReplace( |
| 3071 | std::make_pair(LocalBasePreprocessedEntityID, |
| 3072 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 3073 | } |
| 3074 | |
| 3075 | break; |
| 3076 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3077 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3078 | case DECL_UPDATE_OFFSETS: { |
| 3079 | if (Record.size() % 2 != 0) { |
| 3080 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3081 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3082 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3083 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) { |
| 3084 | GlobalDeclID ID = getGlobalDeclID(F, Record[I]); |
| 3085 | DeclUpdateOffsets[ID].push_back(std::make_pair(&F, Record[I + 1])); |
| 3086 | |
| 3087 | // If we've already loaded the decl, perform the updates when we finish |
| 3088 | // loading this block. |
| 3089 | if (Decl *D = GetExistingDecl(ID)) |
| 3090 | PendingUpdateRecords.push_back(std::make_pair(ID, D)); |
| 3091 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3092 | break; |
| 3093 | } |
| 3094 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3095 | case OBJC_CATEGORIES_MAP: { |
| 3096 | if (F.LocalNumObjCCategoriesInMap != 0) { |
| 3097 | Error("duplicate OBJC_CATEGORIES_MAP record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3098 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3099 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3100 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3101 | F.LocalNumObjCCategoriesInMap = Record[0]; |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3102 | F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3103 | break; |
| 3104 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3105 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3106 | case OBJC_CATEGORIES: |
| 3107 | F.ObjCCategories.swap(Record); |
| 3108 | break; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 3109 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3110 | case CUDA_SPECIAL_DECL_REFS: |
| 3111 | // Later tables overwrite earlier ones. |
| 3112 | // FIXME: Modules will have trouble with this. |
| 3113 | CUDASpecialDeclRefs.clear(); |
| 3114 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3115 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
| 3116 | break; |
| 3117 | |
| 3118 | case HEADER_SEARCH_TABLE: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3119 | F.HeaderFileInfoTableData = Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3120 | F.LocalNumHeaderFileInfos = Record[1]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3121 | if (Record[0]) { |
| 3122 | F.HeaderFileInfoTable |
| 3123 | = HeaderFileInfoLookupTable::Create( |
| 3124 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 3125 | (const unsigned char *)F.HeaderFileInfoTableData, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3126 | HeaderFileInfoTrait(*this, F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3127 | &PP.getHeaderSearchInfo(), |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3128 | Blob.data() + Record[2])); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3129 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3130 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 3131 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 3132 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
| 3133 | } |
| 3134 | break; |
| 3135 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3136 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3137 | case FP_PRAGMA_OPTIONS: |
| 3138 | // Later tables overwrite earlier ones. |
| 3139 | FPPragmaOptions.swap(Record); |
| 3140 | break; |
| 3141 | |
| 3142 | case OPENCL_EXTENSIONS: |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3143 | for (unsigned I = 0, E = Record.size(); I != E; ) { |
| 3144 | auto Name = ReadString(Record, I); |
| 3145 | auto &Opt = OpenCLExtensions.OptMap[Name]; |
Yaxun Liu | cc2741c | 2016-12-18 06:35:06 +0000 | [diff] [blame] | 3146 | Opt.Supported = Record[I++] != 0; |
| 3147 | Opt.Enabled = Record[I++] != 0; |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3148 | Opt.Avail = Record[I++]; |
| 3149 | Opt.Core = Record[I++]; |
| 3150 | } |
| 3151 | break; |
| 3152 | |
| 3153 | case OPENCL_EXTENSION_TYPES: |
| 3154 | for (unsigned I = 0, E = Record.size(); I != E;) { |
| 3155 | auto TypeID = static_cast<::TypeID>(Record[I++]); |
| 3156 | auto *Type = GetType(TypeID).getTypePtr(); |
| 3157 | auto NumExt = static_cast<unsigned>(Record[I++]); |
| 3158 | for (unsigned II = 0; II != NumExt; ++II) { |
| 3159 | auto Ext = ReadString(Record, I); |
| 3160 | OpenCLTypeExtMap[Type].insert(Ext); |
| 3161 | } |
| 3162 | } |
| 3163 | break; |
| 3164 | |
| 3165 | case OPENCL_EXTENSION_DECLS: |
| 3166 | for (unsigned I = 0, E = Record.size(); I != E;) { |
| 3167 | auto DeclID = static_cast<::DeclID>(Record[I++]); |
| 3168 | auto *Decl = GetDecl(DeclID); |
| 3169 | auto NumExt = static_cast<unsigned>(Record[I++]); |
| 3170 | for (unsigned II = 0; II != NumExt; ++II) { |
| 3171 | auto Ext = ReadString(Record, I); |
| 3172 | OpenCLDeclExtMap[Decl].insert(Ext); |
| 3173 | } |
| 3174 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3175 | break; |
| 3176 | |
| 3177 | case TENTATIVE_DEFINITIONS: |
| 3178 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3179 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
| 3180 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3181 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3182 | case KNOWN_NAMESPACES: |
| 3183 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3184 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
| 3185 | break; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3186 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3187 | case UNDEFINED_BUT_USED: |
| 3188 | if (UndefinedButUsed.size() % 2 != 0) { |
| 3189 | Error("Invalid existing UndefinedButUsed"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3190 | return Failure; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | if (Record.size() % 2 != 0) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3194 | Error("invalid undefined-but-used record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3195 | return Failure; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3196 | } |
| 3197 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3198 | UndefinedButUsed.push_back(getGlobalDeclID(F, Record[I++])); |
| 3199 | UndefinedButUsed.push_back( |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3200 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3201 | } |
| 3202 | break; |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 3203 | case DELETE_EXPRS_TO_ANALYZE: |
| 3204 | for (unsigned I = 0, N = Record.size(); I != N;) { |
| 3205 | DelayedDeleteExprs.push_back(getGlobalDeclID(F, Record[I++])); |
| 3206 | const uint64_t Count = Record[I++]; |
| 3207 | DelayedDeleteExprs.push_back(Count); |
| 3208 | for (uint64_t C = 0; C < Count; ++C) { |
| 3209 | DelayedDeleteExprs.push_back(ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3210 | bool IsArrayForm = Record[I++] == 1; |
| 3211 | DelayedDeleteExprs.push_back(IsArrayForm); |
| 3212 | } |
| 3213 | } |
| 3214 | break; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3215 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3216 | case IMPORTED_MODULES: { |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 3217 | if (!F.isModule()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3218 | // If we aren't loading a module (which has its own exports), make |
| 3219 | // all of the imported modules visible. |
| 3220 | // FIXME: Deal with macros-only imports. |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 3221 | for (unsigned I = 0, N = Record.size(); I != N; /**/) { |
| 3222 | unsigned GlobalID = getGlobalSubmoduleID(F, Record[I++]); |
| 3223 | SourceLocation Loc = ReadSourceLocation(F, Record, I); |
Graydon Hoare | 9c98244 | 2017-01-18 20:36:59 +0000 | [diff] [blame] | 3224 | if (GlobalID) { |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 3225 | ImportedModules.push_back(ImportedSubmodule(GlobalID, Loc)); |
Graydon Hoare | 9c98244 | 2017-01-18 20:36:59 +0000 | [diff] [blame] | 3226 | if (DeserializationListener) |
| 3227 | DeserializationListener->ModuleImportRead(GlobalID, Loc); |
| 3228 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3229 | } |
| 3230 | } |
| 3231 | break; |
| 3232 | } |
| 3233 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3234 | case MACRO_OFFSET: { |
| 3235 | if (F.LocalNumMacros != 0) { |
| 3236 | Error("duplicate MACRO_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3237 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3238 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3239 | F.MacroOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3240 | F.LocalNumMacros = Record[0]; |
| 3241 | unsigned LocalBaseMacroID = Record[1]; |
| 3242 | F.BaseMacroID = getTotalNumMacros(); |
| 3243 | |
| 3244 | if (F.LocalNumMacros > 0) { |
| 3245 | // Introduce the global -> local mapping for macros within this module. |
| 3246 | GlobalMacroMap.insert(std::make_pair(getTotalNumMacros() + 1, &F)); |
| 3247 | |
| 3248 | // Introduce the local -> global mapping for macros within this module. |
| 3249 | F.MacroRemap.insertOrReplace( |
| 3250 | std::make_pair(LocalBaseMacroID, |
| 3251 | F.BaseMacroID - LocalBaseMacroID)); |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3252 | |
| 3253 | MacrosLoaded.resize(MacrosLoaded.size() + F.LocalNumMacros); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3254 | } |
| 3255 | break; |
| 3256 | } |
| 3257 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3258 | case LATE_PARSED_TEMPLATE: { |
| 3259 | LateParsedTemplates.append(Record.begin(), Record.end()); |
| 3260 | break; |
| 3261 | } |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 3262 | |
| 3263 | case OPTIMIZE_PRAGMA_OPTIONS: |
| 3264 | if (Record.size() != 1) { |
| 3265 | Error("invalid pragma optimize record"); |
| 3266 | return Failure; |
| 3267 | } |
| 3268 | OptimizeOffPragmaLocation = ReadSourceLocation(F, Record[0]); |
| 3269 | break; |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 3270 | |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 3271 | case MSSTRUCT_PRAGMA_OPTIONS: |
| 3272 | if (Record.size() != 1) { |
| 3273 | Error("invalid pragma ms_struct record"); |
| 3274 | return Failure; |
| 3275 | } |
| 3276 | PragmaMSStructState = Record[0]; |
| 3277 | break; |
| 3278 | |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 3279 | case POINTERS_TO_MEMBERS_PRAGMA_OPTIONS: |
| 3280 | if (Record.size() != 2) { |
| 3281 | Error("invalid pragma ms_struct record"); |
| 3282 | return Failure; |
| 3283 | } |
| 3284 | PragmaMSPointersToMembersState = Record[0]; |
| 3285 | PointersToMembersPragmaLocation = ReadSourceLocation(F, Record[1]); |
| 3286 | break; |
| 3287 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 3288 | case UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES: |
| 3289 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3290 | UnusedLocalTypedefNameCandidates.push_back( |
| 3291 | getGlobalDeclID(F, Record[I])); |
| 3292 | break; |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 3293 | |
| 3294 | case CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH: |
| 3295 | if (Record.size() != 1) { |
| 3296 | Error("invalid cuda pragma options record"); |
| 3297 | return Failure; |
| 3298 | } |
| 3299 | ForceCUDAHostDeviceDepth = Record[0]; |
| 3300 | break; |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 3301 | |
| 3302 | case PACK_PRAGMA_OPTIONS: { |
| 3303 | if (Record.size() < 3) { |
| 3304 | Error("invalid pragma pack record"); |
| 3305 | return Failure; |
| 3306 | } |
| 3307 | PragmaPackCurrentValue = Record[0]; |
| 3308 | PragmaPackCurrentLocation = ReadSourceLocation(F, Record[1]); |
| 3309 | unsigned NumStackEntries = Record[2]; |
| 3310 | unsigned Idx = 3; |
| 3311 | // Reset the stack when importing a new module. |
| 3312 | PragmaPackStack.clear(); |
| 3313 | for (unsigned I = 0; I < NumStackEntries; ++I) { |
| 3314 | PragmaPackStackEntry Entry; |
| 3315 | Entry.Value = Record[Idx++]; |
| 3316 | Entry.Location = ReadSourceLocation(F, Record[Idx++]); |
| 3317 | PragmaPackStrings.push_back(ReadString(Record, Idx)); |
| 3318 | Entry.SlotLabel = PragmaPackStrings.back(); |
| 3319 | PragmaPackStack.push_back(Entry); |
| 3320 | } |
| 3321 | break; |
| 3322 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3323 | } |
| 3324 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3325 | } |
| 3326 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3327 | void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const { |
| 3328 | assert(!F.ModuleOffsetMap.empty() && "no module offset map to read"); |
| 3329 | |
| 3330 | // Additional remapping information. |
| 3331 | const unsigned char *Data = (const unsigned char*)F.ModuleOffsetMap.data(); |
| 3332 | const unsigned char *DataEnd = Data + F.ModuleOffsetMap.size(); |
| 3333 | F.ModuleOffsetMap = StringRef(); |
| 3334 | |
| 3335 | // If we see this entry before SOURCE_LOCATION_OFFSETS, add placeholders. |
| 3336 | if (F.SLocRemap.find(0) == F.SLocRemap.end()) { |
| 3337 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 3338 | F.SLocRemap.insert(std::make_pair(2U, 1)); |
| 3339 | } |
| 3340 | |
| 3341 | // Continuous range maps we may be updating in our module. |
| 3342 | typedef ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 3343 | RemapBuilder; |
| 3344 | RemapBuilder SLocRemap(F.SLocRemap); |
| 3345 | RemapBuilder IdentifierRemap(F.IdentifierRemap); |
| 3346 | RemapBuilder MacroRemap(F.MacroRemap); |
| 3347 | RemapBuilder PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 3348 | RemapBuilder SubmoduleRemap(F.SubmoduleRemap); |
| 3349 | RemapBuilder SelectorRemap(F.SelectorRemap); |
| 3350 | RemapBuilder DeclRemap(F.DeclRemap); |
| 3351 | RemapBuilder TypeRemap(F.TypeRemap); |
| 3352 | |
| 3353 | while (Data < DataEnd) { |
| 3354 | // FIXME: Looking up dependency modules by filename is horrible. |
| 3355 | using namespace llvm::support; |
| 3356 | uint16_t Len = endian::readNext<uint16_t, little, unaligned>(Data); |
| 3357 | StringRef Name = StringRef((const char*)Data, Len); |
| 3358 | Data += Len; |
| 3359 | ModuleFile *OM = ModuleMgr.lookup(Name); |
| 3360 | if (!OM) { |
| 3361 | std::string Msg = |
| 3362 | "SourceLocation remap refers to unknown module, cannot find "; |
| 3363 | Msg.append(Name); |
| 3364 | Error(Msg); |
| 3365 | return; |
| 3366 | } |
| 3367 | |
| 3368 | uint32_t SLocOffset = |
| 3369 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3370 | uint32_t IdentifierIDOffset = |
| 3371 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3372 | uint32_t MacroIDOffset = |
| 3373 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3374 | uint32_t PreprocessedEntityIDOffset = |
| 3375 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3376 | uint32_t SubmoduleIDOffset = |
| 3377 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3378 | uint32_t SelectorIDOffset = |
| 3379 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3380 | uint32_t DeclIDOffset = |
| 3381 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3382 | uint32_t TypeIndexOffset = |
| 3383 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3384 | |
| 3385 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 3386 | |
| 3387 | auto mapOffset = [&](uint32_t Offset, uint32_t BaseOffset, |
| 3388 | RemapBuilder &Remap) { |
| 3389 | if (Offset != None) |
| 3390 | Remap.insert(std::make_pair(Offset, |
| 3391 | static_cast<int>(BaseOffset - Offset))); |
| 3392 | }; |
| 3393 | mapOffset(SLocOffset, OM->SLocEntryBaseOffset, SLocRemap); |
| 3394 | mapOffset(IdentifierIDOffset, OM->BaseIdentifierID, IdentifierRemap); |
| 3395 | mapOffset(MacroIDOffset, OM->BaseMacroID, MacroRemap); |
| 3396 | mapOffset(PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID, |
| 3397 | PreprocessedEntityRemap); |
| 3398 | mapOffset(SubmoduleIDOffset, OM->BaseSubmoduleID, SubmoduleRemap); |
| 3399 | mapOffset(SelectorIDOffset, OM->BaseSelectorID, SelectorRemap); |
| 3400 | mapOffset(DeclIDOffset, OM->BaseDeclID, DeclRemap); |
| 3401 | mapOffset(TypeIndexOffset, OM->BaseTypeIndex, TypeRemap); |
| 3402 | |
| 3403 | // Global -> local mappings. |
| 3404 | F.GlobalToLocalDeclIDs[OM] = DeclIDOffset; |
| 3405 | } |
| 3406 | } |
| 3407 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3408 | ASTReader::ASTReadResult |
| 3409 | ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, |
| 3410 | const ModuleFile *ImportedBy, |
| 3411 | unsigned ClientLoadCapabilities) { |
| 3412 | unsigned Idx = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3413 | F.ModuleMapPath = ReadPath(F, Record, Idx); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3414 | |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 3415 | if (F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule) { |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3416 | // For an explicitly-loaded module, we don't care whether the original |
| 3417 | // module map file exists or matches. |
| 3418 | return Success; |
| 3419 | } |
| 3420 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3421 | // Try to resolve ModuleName in the current header search context and |
| 3422 | // verify that it is found in the same module map file as we saved. If the |
| 3423 | // top-level AST file is a main file, skip this check because there is no |
| 3424 | // usable header search context. |
| 3425 | assert(!F.ModuleName.empty() && |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3426 | "MODULE_NAME should come before MODULE_MAP_FILE"); |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 3427 | if (F.Kind == MK_ImplicitModule && ModuleMgr.begin()->Kind != MK_MainFile) { |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3428 | // An implicitly-loaded module file should have its module listed in some |
| 3429 | // module map file that we've already loaded. |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3430 | Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName); |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3431 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
| 3432 | const FileEntry *ModMap = M ? Map.getModuleMapFileForUniquing(M) : nullptr; |
| 3433 | if (!ModMap) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3434 | assert(ImportedBy && "top-level import should be verified"); |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3435 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) { |
| 3436 | if (auto *ASTFE = M ? M->getASTFile() : nullptr) |
| 3437 | // This module was defined by an imported (explicit) module. |
| 3438 | Diag(diag::err_module_file_conflict) << F.ModuleName << F.FileName |
| 3439 | << ASTFE->getName(); |
| 3440 | else |
| 3441 | // This module was built with a different module map. |
| 3442 | Diag(diag::err_imported_module_not_found) |
| 3443 | << F.ModuleName << F.FileName << ImportedBy->FileName |
| 3444 | << F.ModuleMapPath; |
| 3445 | } |
| 3446 | return OutOfDate; |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3447 | } |
| 3448 | |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3449 | assert(M->Name == F.ModuleName && "found module with different name"); |
| 3450 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3451 | // Check the primary module map file. |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3452 | const FileEntry *StoredModMap = FileMgr.getFile(F.ModuleMapPath); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3453 | if (StoredModMap == nullptr || StoredModMap != ModMap) { |
| 3454 | assert(ModMap && "found module is missing module map file"); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3455 | assert(ImportedBy && "top-level import should be verified"); |
| 3456 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3457 | Diag(diag::err_imported_module_modmap_changed) |
| 3458 | << F.ModuleName << ImportedBy->FileName |
| 3459 | << ModMap->getName() << F.ModuleMapPath; |
| 3460 | return OutOfDate; |
| 3461 | } |
| 3462 | |
| 3463 | llvm::SmallPtrSet<const FileEntry *, 1> AdditionalStoredMaps; |
| 3464 | for (unsigned I = 0, N = Record[Idx++]; I < N; ++I) { |
| 3465 | // FIXME: we should use input files rather than storing names. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3466 | std::string Filename = ReadPath(F, Record, Idx); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3467 | const FileEntry *F = |
| 3468 | FileMgr.getFile(Filename, false, false); |
| 3469 | if (F == nullptr) { |
| 3470 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3471 | Error("could not find file '" + Filename +"' referenced by AST file"); |
| 3472 | return OutOfDate; |
| 3473 | } |
| 3474 | AdditionalStoredMaps.insert(F); |
| 3475 | } |
| 3476 | |
| 3477 | // Check any additional module map files (e.g. module.private.modulemap) |
| 3478 | // that are not in the pcm. |
| 3479 | if (auto *AdditionalModuleMaps = Map.getAdditionalModuleMapFiles(M)) { |
| 3480 | for (const FileEntry *ModMap : *AdditionalModuleMaps) { |
| 3481 | // Remove files that match |
| 3482 | // Note: SmallPtrSet::erase is really remove |
| 3483 | if (!AdditionalStoredMaps.erase(ModMap)) { |
| 3484 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3485 | Diag(diag::err_module_different_modmap) |
| 3486 | << F.ModuleName << /*new*/0 << ModMap->getName(); |
| 3487 | return OutOfDate; |
| 3488 | } |
| 3489 | } |
| 3490 | } |
| 3491 | |
| 3492 | // Check any additional module map files that are in the pcm, but not |
| 3493 | // found in header search. Cases that match are already removed. |
| 3494 | for (const FileEntry *ModMap : AdditionalStoredMaps) { |
| 3495 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3496 | Diag(diag::err_module_different_modmap) |
| 3497 | << F.ModuleName << /*not new*/1 << ModMap->getName(); |
| 3498 | return OutOfDate; |
| 3499 | } |
| 3500 | } |
| 3501 | |
| 3502 | if (Listener) |
| 3503 | Listener->ReadModuleMapFile(F.ModuleMapPath); |
| 3504 | return Success; |
| 3505 | } |
| 3506 | |
| 3507 | |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3508 | /// \brief Move the given method to the back of the global list of methods. |
| 3509 | static void moveMethodToBackOfGlobalList(Sema &S, ObjCMethodDecl *Method) { |
| 3510 | // Find the entry for this selector in the method pool. |
| 3511 | Sema::GlobalMethodPool::iterator Known |
| 3512 | = S.MethodPool.find(Method->getSelector()); |
| 3513 | if (Known == S.MethodPool.end()) |
| 3514 | return; |
| 3515 | |
| 3516 | // Retrieve the appropriate method list. |
| 3517 | ObjCMethodList &Start = Method->isInstanceMethod()? Known->second.first |
| 3518 | : Known->second.second; |
| 3519 | bool Found = false; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3520 | for (ObjCMethodList *List = &Start; List; List = List->getNext()) { |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3521 | if (!Found) { |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3522 | if (List->getMethod() == Method) { |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3523 | Found = true; |
| 3524 | } else { |
| 3525 | // Keep searching. |
| 3526 | continue; |
| 3527 | } |
| 3528 | } |
| 3529 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3530 | if (List->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3531 | List->setMethod(List->getNext()->getMethod()); |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3532 | else |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3533 | List->setMethod(Method); |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3534 | } |
| 3535 | } |
| 3536 | |
Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 3537 | void ASTReader::makeNamesVisible(const HiddenNames &Names, Module *Owner) { |
Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 3538 | assert(Owner->NameVisibility != Module::Hidden && "nothing to make visible?"); |
Richard Smith | 20e883e | 2015-04-29 23:20:19 +0000 | [diff] [blame] | 3539 | for (Decl *D : Names) { |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3540 | bool wasHidden = D->Hidden; |
| 3541 | D->Hidden = false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3542 | |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3543 | if (wasHidden && SemaObj) { |
| 3544 | if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D)) { |
| 3545 | moveMethodToBackOfGlobalList(*SemaObj, Method); |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3546 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3547 | } |
| 3548 | } |
| 3549 | } |
| 3550 | |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3551 | void ASTReader::makeModuleVisible(Module *Mod, |
Argyrios Kyrtzidis | 125df05 | 2013-02-01 16:36:12 +0000 | [diff] [blame] | 3552 | Module::NameVisibilityKind NameVisibility, |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 3553 | SourceLocation ImportLoc) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3554 | llvm::SmallPtrSet<Module *, 4> Visited; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3555 | SmallVector<Module *, 4> Stack; |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3556 | Stack.push_back(Mod); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3557 | while (!Stack.empty()) { |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3558 | Mod = Stack.pop_back_val(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3559 | |
| 3560 | if (NameVisibility <= Mod->NameVisibility) { |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3561 | // This module already has this level of visibility (or greater), so |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3562 | // there is nothing more to do. |
| 3563 | continue; |
| 3564 | } |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3565 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3566 | if (!Mod->isAvailable()) { |
| 3567 | // Modules that aren't available cannot be made visible. |
| 3568 | continue; |
| 3569 | } |
| 3570 | |
| 3571 | // Update the module's name visibility. |
| 3572 | Mod->NameVisibility = NameVisibility; |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3573 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3574 | // If we've already deserialized any names from this module, |
| 3575 | // mark them as visible. |
| 3576 | HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod); |
| 3577 | if (Hidden != HiddenNamesMap.end()) { |
Richard Smith | 57721ac | 2014-07-21 04:10:40 +0000 | [diff] [blame] | 3578 | auto HiddenNames = std::move(*Hidden); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3579 | HiddenNamesMap.erase(Hidden); |
Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 3580 | makeNamesVisible(HiddenNames.second, HiddenNames.first); |
Richard Smith | 57721ac | 2014-07-21 04:10:40 +0000 | [diff] [blame] | 3581 | assert(HiddenNamesMap.find(Mod) == HiddenNamesMap.end() && |
| 3582 | "making names visible added hidden names"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3583 | } |
Dmitri Gribenko | e9bcf5b | 2013-11-04 21:51:33 +0000 | [diff] [blame] | 3584 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3585 | // Push any exported modules onto the stack to be marked as visible. |
Argyrios Kyrtzidis | 8739f7b | 2013-02-19 19:34:40 +0000 | [diff] [blame] | 3586 | SmallVector<Module *, 16> Exports; |
| 3587 | Mod->getExportedModules(Exports); |
| 3588 | for (SmallVectorImpl<Module *>::iterator |
| 3589 | I = Exports.begin(), E = Exports.end(); I != E; ++I) { |
| 3590 | Module *Exported = *I; |
David Blaikie | 82e95a3 | 2014-11-19 07:49:47 +0000 | [diff] [blame] | 3591 | if (Visited.insert(Exported).second) |
Argyrios Kyrtzidis | 8739f7b | 2013-02-19 19:34:40 +0000 | [diff] [blame] | 3592 | Stack.push_back(Exported); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3593 | } |
| 3594 | } |
| 3595 | } |
| 3596 | |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 3597 | /// We've merged the definition \p MergedDef into the existing definition |
| 3598 | /// \p Def. Ensure that \p Def is made visible whenever \p MergedDef is made |
| 3599 | /// visible. |
| 3600 | void ASTReader::mergeDefinitionVisibility(NamedDecl *Def, |
| 3601 | NamedDecl *MergedDef) { |
Benjamin Kramer | a72a70a | 2016-10-17 13:00:44 +0000 | [diff] [blame] | 3602 | // FIXME: This doesn't correctly handle the case where MergedDef is visible |
| 3603 | // in modules other than its owning module. We should instead give the |
| 3604 | // ASTContext a list of merged definitions for Def. |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 3605 | if (Def->isHidden()) { |
| 3606 | // If MergedDef is visible or becomes visible, make the definition visible. |
Benjamin Kramer | a72a70a | 2016-10-17 13:00:44 +0000 | [diff] [blame] | 3607 | if (!MergedDef->isHidden()) |
| 3608 | Def->Hidden = false; |
| 3609 | else if (getContext().getLangOpts().ModulesLocalVisibility) { |
| 3610 | getContext().mergeDefinitionIntoModule( |
| 3611 | Def, MergedDef->getImportedOwningModule(), |
| 3612 | /*NotifyListeners*/ false); |
| 3613 | PendingMergedDefinitionsToDeduplicate.insert(Def); |
| 3614 | } else { |
| 3615 | auto SubmoduleID = MergedDef->getOwningModuleID(); |
| 3616 | assert(SubmoduleID && "hidden definition in no module"); |
| 3617 | HiddenNamesMap[getSubmodule(SubmoduleID)].push_back(Def); |
| 3618 | } |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 3619 | } |
| 3620 | } |
| 3621 | |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3622 | bool ASTReader::loadGlobalIndex() { |
| 3623 | if (GlobalIndex) |
| 3624 | return false; |
| 3625 | |
| 3626 | if (TriedLoadingGlobalIndex || !UseGlobalIndex || |
| 3627 | !Context.getLangOpts().Modules) |
| 3628 | return true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3629 | |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3630 | // Try to load the global index. |
| 3631 | TriedLoadingGlobalIndex = true; |
| 3632 | StringRef ModuleCachePath |
| 3633 | = getPreprocessor().getHeaderSearchInfo().getModuleCachePath(); |
| 3634 | std::pair<GlobalModuleIndex *, GlobalModuleIndex::ErrorCode> Result |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3635 | = GlobalModuleIndex::readIndex(ModuleCachePath); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3636 | if (!Result.first) |
| 3637 | return true; |
| 3638 | |
| 3639 | GlobalIndex.reset(Result.first); |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 3640 | ModuleMgr.setGlobalIndex(GlobalIndex.get()); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3641 | return false; |
| 3642 | } |
| 3643 | |
| 3644 | bool ASTReader::isGlobalIndexUnavailable() const { |
| 3645 | return Context.getLangOpts().Modules && UseGlobalIndex && |
| 3646 | !hasGlobalIndex() && TriedLoadingGlobalIndex; |
| 3647 | } |
| 3648 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3649 | static void updateModuleTimestamp(ModuleFile &MF) { |
| 3650 | // Overwrite the timestamp file contents so that file's mtime changes. |
| 3651 | std::string TimestampFilename = MF.getTimestampFilename(); |
Rafael Espindola | dae941a | 2014-08-25 18:17:04 +0000 | [diff] [blame] | 3652 | std::error_code EC; |
| 3653 | llvm::raw_fd_ostream OS(TimestampFilename, EC, llvm::sys::fs::F_Text); |
| 3654 | if (EC) |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3655 | return; |
| 3656 | OS << "Timestamp file\n"; |
| 3657 | } |
| 3658 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3659 | /// \brief Given a cursor at the start of an AST file, scan ahead and drop the |
| 3660 | /// cursor into the start of the given block ID, returning false on success and |
| 3661 | /// true on failure. |
| 3662 | static bool SkipCursorToBlock(BitstreamCursor &Cursor, unsigned BlockID) { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3663 | while (true) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3664 | llvm::BitstreamEntry Entry = Cursor.advance(); |
| 3665 | switch (Entry.Kind) { |
| 3666 | case llvm::BitstreamEntry::Error: |
| 3667 | case llvm::BitstreamEntry::EndBlock: |
| 3668 | return true; |
| 3669 | |
| 3670 | case llvm::BitstreamEntry::Record: |
| 3671 | // Ignore top-level records. |
| 3672 | Cursor.skipRecord(Entry.ID); |
| 3673 | break; |
| 3674 | |
| 3675 | case llvm::BitstreamEntry::SubBlock: |
| 3676 | if (Entry.ID == BlockID) { |
| 3677 | if (Cursor.EnterSubBlock(BlockID)) |
| 3678 | return true; |
| 3679 | // Found it! |
| 3680 | return false; |
| 3681 | } |
| 3682 | |
| 3683 | if (Cursor.SkipBlock()) |
| 3684 | return true; |
| 3685 | } |
| 3686 | } |
| 3687 | } |
| 3688 | |
Benjamin Kramer | 0772c42 | 2016-02-13 13:42:54 +0000 | [diff] [blame] | 3689 | ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3690 | ModuleKind Type, |
| 3691 | SourceLocation ImportLoc, |
Graydon Hoare | e7196af | 2016-12-09 21:45:49 +0000 | [diff] [blame] | 3692 | unsigned ClientLoadCapabilities, |
| 3693 | SmallVectorImpl<ImportedSubmodule> *Imported) { |
Argyrios Kyrtzidis | dc9fdaf | 2013-05-24 05:44:08 +0000 | [diff] [blame] | 3694 | llvm::SaveAndRestore<SourceLocation> |
| 3695 | SetCurImportLocRAII(CurrentImportLoc, ImportLoc); |
| 3696 | |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 3697 | // Defer any pending actions until we get to the end of reading the AST file. |
| 3698 | Deserializing AnASTFile(this); |
| 3699 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3700 | // Bump the generation number. |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3701 | unsigned PreviousGeneration = incrementGeneration(Context); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3702 | |
| 3703 | unsigned NumModules = ModuleMgr.size(); |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3704 | SmallVector<ImportedModule, 4> Loaded; |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 3705 | switch (ASTReadResult ReadResult = |
| 3706 | ReadASTCore(FileName, Type, ImportLoc, |
| 3707 | /*ImportedBy=*/nullptr, Loaded, 0, 0, |
| 3708 | ASTFileSignature(), ClientLoadCapabilities)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3709 | case Failure: |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3710 | case Missing: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3711 | case OutOfDate: |
| 3712 | case VersionMismatch: |
| 3713 | case ConfigurationMismatch: |
Ben Langmuir | 9801b25 | 2014-06-20 00:24:56 +0000 | [diff] [blame] | 3714 | case HadErrors: { |
| 3715 | llvm::SmallPtrSet<ModuleFile *, 4> LoadedSet; |
| 3716 | for (const ImportedModule &IM : Loaded) |
| 3717 | LoadedSet.insert(IM.Mod); |
| 3718 | |
Duncan P. N. Exon Smith | 8e6bc197 | 2017-01-28 23:02:12 +0000 | [diff] [blame] | 3719 | ModuleMgr.removeModules(ModuleMgr.begin() + NumModules, LoadedSet, |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3720 | Context.getLangOpts().Modules |
Duncan P. N. Exon Smith | 8e6bc197 | 2017-01-28 23:02:12 +0000 | [diff] [blame] | 3721 | ? &PP.getHeaderSearchInfo().getModuleMap() |
| 3722 | : nullptr); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3723 | |
| 3724 | // If we find that any modules are unusable, the global index is going |
| 3725 | // to be out-of-date. Just remove it. |
| 3726 | GlobalIndex.reset(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3727 | ModuleMgr.setGlobalIndex(nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3728 | return ReadResult; |
Ben Langmuir | 9801b25 | 2014-06-20 00:24:56 +0000 | [diff] [blame] | 3729 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3730 | case Success: |
| 3731 | break; |
| 3732 | } |
| 3733 | |
| 3734 | // Here comes stuff that we only do once the entire chain is loaded. |
| 3735 | |
| 3736 | // Load the AST blocks of all of the modules that we loaded. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3737 | for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(), |
| 3738 | MEnd = Loaded.end(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3739 | M != MEnd; ++M) { |
| 3740 | ModuleFile &F = *M->Mod; |
| 3741 | |
| 3742 | // Read the AST block. |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3743 | if (ASTReadResult Result = ReadASTBlock(F, ClientLoadCapabilities)) |
| 3744 | return Result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3745 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3746 | // Read the extension blocks. |
| 3747 | while (!SkipCursorToBlock(F.Stream, EXTENSION_BLOCK_ID)) { |
| 3748 | if (ASTReadResult Result = ReadExtensionBlock(F)) |
| 3749 | return Result; |
| 3750 | } |
| 3751 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3752 | // 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] | 3753 | // bits of all files we've seen. |
| 3754 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 3755 | TotalModulesSizeInBits += F.SizeInBits; |
| 3756 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3757 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3758 | // Preload SLocEntries. |
| 3759 | for (unsigned I = 0, N = F.PreloadSLocEntries.size(); I != N; ++I) { |
| 3760 | int Index = int(F.PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
| 3761 | // Load it through the SourceManager and don't call ReadSLocEntry() |
| 3762 | // directly because the entry may have already been loaded in which case |
| 3763 | // calling ReadSLocEntry() directly would trigger an assertion in |
| 3764 | // SourceManager. |
| 3765 | SourceMgr.getLoadedSLocEntryByID(Index); |
| 3766 | } |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3767 | |
Richard Smith | ea74148 | 2017-05-01 22:10:47 +0000 | [diff] [blame^] | 3768 | // Map the original source file ID into the ID space of the current |
| 3769 | // compilation. |
| 3770 | if (F.OriginalSourceFileID.isValid()) { |
| 3771 | F.OriginalSourceFileID = FileID::get( |
| 3772 | F.SLocEntryBaseID + F.OriginalSourceFileID.getOpaqueValue() - 1); |
| 3773 | } |
| 3774 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3775 | // Preload all the pending interesting identifiers by marking them out of |
| 3776 | // date. |
| 3777 | for (auto Offset : F.PreloadIdentifierOffsets) { |
| 3778 | const unsigned char *Data = reinterpret_cast<const unsigned char *>( |
| 3779 | F.IdentifierTableData + Offset); |
| 3780 | |
| 3781 | ASTIdentifierLookupTrait Trait(*this, F); |
| 3782 | auto KeyDataLen = Trait.ReadKeyDataLength(Data); |
| 3783 | auto Key = Trait.ReadKey(Data, KeyDataLen.first); |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 3784 | auto &II = PP.getIdentifierTable().getOwn(Key); |
| 3785 | II.setOutOfDate(true); |
| 3786 | |
| 3787 | // Mark this identifier as being from an AST file so that we can track |
| 3788 | // whether we need to serialize it. |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 3789 | markIdentifierFromAST(*this, II); |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 3790 | |
| 3791 | // Associate the ID with the identifier so that the writer can reuse it. |
| 3792 | auto ID = Trait.ReadIdentifierID(Data + KeyDataLen.first); |
| 3793 | SetIdentifierInfo(ID, &II); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3794 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3795 | } |
| 3796 | |
Douglas Gregor | 603cd86 | 2013-03-22 18:50:14 +0000 | [diff] [blame] | 3797 | // Setup the import locations and notify the module manager that we've |
| 3798 | // committed to these module files. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3799 | for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(), |
| 3800 | MEnd = Loaded.end(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3801 | M != MEnd; ++M) { |
| 3802 | ModuleFile &F = *M->Mod; |
Douglas Gregor | 603cd86 | 2013-03-22 18:50:14 +0000 | [diff] [blame] | 3803 | |
| 3804 | ModuleMgr.moduleFileAccepted(&F); |
| 3805 | |
| 3806 | // Set the import location. |
Argyrios Kyrtzidis | 71c1af8 | 2013-02-01 16:36:14 +0000 | [diff] [blame] | 3807 | F.DirectImportLoc = ImportLoc; |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 3808 | // FIXME: We assume that locations from PCH / preamble do not need |
| 3809 | // any translation. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3810 | if (!M->ImportedBy) |
| 3811 | F.ImportLoc = M->ImportLoc; |
| 3812 | else |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 3813 | F.ImportLoc = TranslateSourceLocation(*M->ImportedBy, M->ImportLoc); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3814 | } |
| 3815 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3816 | if (!Context.getLangOpts().CPlusPlus || |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 3817 | (Type != MK_ImplicitModule && Type != MK_ExplicitModule && |
| 3818 | Type != MK_PrebuiltModule)) { |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3819 | // Mark all of the identifiers in the identifier table as being out of date, |
| 3820 | // so that various accessors know to check the loaded modules when the |
| 3821 | // identifier is used. |
| 3822 | // |
| 3823 | // For C++ modules, we don't need information on many identifiers (just |
| 3824 | // those that provide macros or are poisoned), so we mark all of |
| 3825 | // the interesting ones via PreloadIdentifierOffsets. |
| 3826 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 3827 | IdEnd = PP.getIdentifierTable().end(); |
| 3828 | Id != IdEnd; ++Id) |
| 3829 | Id->second->setOutOfDate(true); |
| 3830 | } |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 3831 | // Mark selectors as out of date. |
| 3832 | for (auto Sel : SelectorGeneration) |
| 3833 | SelectorOutOfDate[Sel.first] = true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3834 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3835 | // Resolve any unresolved module exports. |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3836 | for (unsigned I = 0, N = UnresolvedModuleRefs.size(); I != N; ++I) { |
| 3837 | UnresolvedModuleRef &Unresolved = UnresolvedModuleRefs[I]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3838 | SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID); |
| 3839 | Module *ResolvedMod = getSubmodule(GlobalID); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3840 | |
| 3841 | switch (Unresolved.Kind) { |
| 3842 | case UnresolvedModuleRef::Conflict: |
| 3843 | if (ResolvedMod) { |
| 3844 | Module::Conflict Conflict; |
| 3845 | Conflict.Other = ResolvedMod; |
| 3846 | Conflict.Message = Unresolved.String.str(); |
| 3847 | Unresolved.Mod->Conflicts.push_back(Conflict); |
| 3848 | } |
| 3849 | continue; |
| 3850 | |
| 3851 | case UnresolvedModuleRef::Import: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3852 | if (ResolvedMod) |
Richard Smith | 38477db | 2015-05-02 00:45:56 +0000 | [diff] [blame] | 3853 | Unresolved.Mod->Imports.insert(ResolvedMod); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3854 | continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3855 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3856 | case UnresolvedModuleRef::Export: |
| 3857 | if (ResolvedMod || Unresolved.IsWildcard) |
| 3858 | Unresolved.Mod->Exports.push_back( |
| 3859 | Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard)); |
| 3860 | continue; |
| 3861 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3862 | } |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3863 | UnresolvedModuleRefs.clear(); |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 3864 | |
Graydon Hoare | e7196af | 2016-12-09 21:45:49 +0000 | [diff] [blame] | 3865 | if (Imported) |
| 3866 | Imported->append(ImportedModules.begin(), |
| 3867 | ImportedModules.end()); |
| 3868 | |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 3869 | // FIXME: How do we load the 'use'd modules? They may not be submodules. |
| 3870 | // Might be unnecessary as use declarations are only used to build the |
| 3871 | // module itself. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3872 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3873 | InitializeContext(); |
| 3874 | |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 3875 | if (SemaObj) |
| 3876 | UpdateSema(); |
| 3877 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3878 | if (DeserializationListener) |
| 3879 | DeserializationListener->ReaderInitialized(this); |
| 3880 | |
| 3881 | ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule(); |
Yaron Keren | 8b56366 | 2015-10-03 10:46:20 +0000 | [diff] [blame] | 3882 | if (PrimaryModule.OriginalSourceFileID.isValid()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3883 | // If this AST file is a precompiled preamble, then set the |
| 3884 | // preamble file ID of the source manager to the file source file |
| 3885 | // from which the preamble was built. |
| 3886 | if (Type == MK_Preamble) { |
| 3887 | SourceMgr.setPreambleFileID(PrimaryModule.OriginalSourceFileID); |
| 3888 | } else if (Type == MK_MainFile) { |
| 3889 | SourceMgr.setMainFileID(PrimaryModule.OriginalSourceFileID); |
| 3890 | } |
| 3891 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3892 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3893 | // For any Objective-C class definitions we have already loaded, make sure |
| 3894 | // that we load any additional categories. |
| 3895 | for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3896 | loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3897 | ObjCClassesLoaded[I], |
| 3898 | PreviousGeneration); |
| 3899 | } |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3900 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3901 | if (PP.getHeaderSearchInfo() |
| 3902 | .getHeaderSearchOpts() |
| 3903 | .ModulesValidateOncePerBuildSession) { |
| 3904 | // Now we are certain that the module and all modules it depends on are |
| 3905 | // up to date. Create or update timestamp files for modules that are |
| 3906 | // located in the module cache (not for PCH files that could be anywhere |
| 3907 | // in the filesystem). |
| 3908 | for (unsigned I = 0, N = Loaded.size(); I != N; ++I) { |
| 3909 | ImportedModule &M = Loaded[I]; |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3910 | if (M.Mod->Kind == MK_ImplicitModule) { |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3911 | updateModuleTimestamp(*M.Mod); |
| 3912 | } |
| 3913 | } |
| 3914 | } |
| 3915 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3916 | return Success; |
| 3917 | } |
| 3918 | |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 3919 | static ASTFileSignature readASTFileSignature(StringRef PCH); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 3920 | |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 3921 | /// \brief Whether \p Stream starts with the AST/PCH file magic number 'CPCH'. |
| 3922 | static bool startsWithASTFileMagic(BitstreamCursor &Stream) { |
Peter Collingbourne | 028eb5a | 2016-11-02 00:08:19 +0000 | [diff] [blame] | 3923 | return Stream.canSkipToPos(4) && |
| 3924 | Stream.Read(8) == 'C' && |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 3925 | Stream.Read(8) == 'P' && |
| 3926 | Stream.Read(8) == 'C' && |
| 3927 | Stream.Read(8) == 'H'; |
| 3928 | } |
| 3929 | |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3930 | static unsigned moduleKindForDiagnostic(ModuleKind Kind) { |
| 3931 | switch (Kind) { |
| 3932 | case MK_PCH: |
| 3933 | return 0; // PCH |
| 3934 | case MK_ImplicitModule: |
| 3935 | case MK_ExplicitModule: |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 3936 | case MK_PrebuiltModule: |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3937 | return 1; // module |
| 3938 | case MK_MainFile: |
| 3939 | case MK_Preamble: |
| 3940 | return 2; // main source file |
| 3941 | } |
| 3942 | llvm_unreachable("unknown module kind"); |
| 3943 | } |
| 3944 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3945 | ASTReader::ASTReadResult |
| 3946 | ASTReader::ReadASTCore(StringRef FileName, |
| 3947 | ModuleKind Type, |
| 3948 | SourceLocation ImportLoc, |
| 3949 | ModuleFile *ImportedBy, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3950 | SmallVectorImpl<ImportedModule> &Loaded, |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3951 | off_t ExpectedSize, time_t ExpectedModTime, |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 3952 | ASTFileSignature ExpectedSignature, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3953 | unsigned ClientLoadCapabilities) { |
| 3954 | ModuleFile *M; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3955 | std::string ErrorStr; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3956 | ModuleManager::AddModuleResult AddResult |
| 3957 | = ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy, |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3958 | getGeneration(), ExpectedSize, ExpectedModTime, |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 3959 | ExpectedSignature, readASTFileSignature, |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3960 | M, ErrorStr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3961 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3962 | switch (AddResult) { |
| 3963 | case ModuleManager::AlreadyLoaded: |
| 3964 | return Success; |
| 3965 | |
| 3966 | case ModuleManager::NewlyLoaded: |
| 3967 | // Load module file below. |
| 3968 | break; |
| 3969 | |
| 3970 | case ModuleManager::Missing: |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3971 | // The module file was missing; if the client can handle that, return |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3972 | // it. |
| 3973 | if (ClientLoadCapabilities & ARR_Missing) |
| 3974 | return Missing; |
| 3975 | |
| 3976 | // Otherwise, return an error. |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3977 | Diag(diag::err_module_file_not_found) << moduleKindForDiagnostic(Type) |
Adrian Prantl | b3b5a73 | 2016-08-29 20:46:59 +0000 | [diff] [blame] | 3978 | << FileName << !ErrorStr.empty() |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3979 | << ErrorStr; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3980 | return Failure; |
| 3981 | |
| 3982 | case ModuleManager::OutOfDate: |
| 3983 | // We couldn't load the module file because it is out-of-date. If the |
| 3984 | // client can handle out-of-date, return it. |
| 3985 | if (ClientLoadCapabilities & ARR_OutOfDate) |
| 3986 | return OutOfDate; |
| 3987 | |
| 3988 | // Otherwise, return an error. |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3989 | Diag(diag::err_module_file_out_of_date) << moduleKindForDiagnostic(Type) |
Adrian Prantl | 9a06a88 | 2016-08-29 20:46:56 +0000 | [diff] [blame] | 3990 | << FileName << !ErrorStr.empty() |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3991 | << ErrorStr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3992 | return Failure; |
| 3993 | } |
| 3994 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3995 | assert(M && "Missing module file"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3996 | |
| 3997 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 3998 | // module? |
| 3999 | if (FileName != "-") { |
| 4000 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 4001 | if (CurrentDir.empty()) CurrentDir = "."; |
| 4002 | } |
| 4003 | |
| 4004 | ModuleFile &F = *M; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4005 | BitstreamCursor &Stream = F.Stream; |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4006 | Stream = BitstreamCursor(PCHContainerRdr.ExtractPCH(*F.Buffer)); |
Adrian Prantl | cbc368c | 2015-02-25 02:44:04 +0000 | [diff] [blame] | 4007 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4008 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4009 | // Sniff for the signature. |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4010 | if (!startsWithASTFileMagic(Stream)) { |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4011 | Diag(diag::err_module_file_invalid) << moduleKindForDiagnostic(Type) |
| 4012 | << FileName; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4013 | return Failure; |
| 4014 | } |
| 4015 | |
| 4016 | // This is used for compatibility with older PCH formats. |
| 4017 | bool HaveReadControlBlock = false; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4018 | while (true) { |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4019 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4020 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4021 | switch (Entry.Kind) { |
| 4022 | case llvm::BitstreamEntry::Error: |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4023 | case llvm::BitstreamEntry::Record: |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4024 | case llvm::BitstreamEntry::EndBlock: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4025 | Error("invalid record at top-level of AST file"); |
| 4026 | return Failure; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4027 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4028 | case llvm::BitstreamEntry::SubBlock: |
| 4029 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4030 | } |
| 4031 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4032 | switch (Entry.ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4033 | case CONTROL_BLOCK_ID: |
| 4034 | HaveReadControlBlock = true; |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4035 | switch (ReadControlBlock(F, Loaded, ImportedBy, ClientLoadCapabilities)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4036 | case Success: |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4037 | // Check that we didn't try to load a non-module AST file as a module. |
| 4038 | // |
| 4039 | // FIXME: Should we also perform the converse check? Loading a module as |
| 4040 | // a PCH file sort of works, but it's a bit wonky. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 4041 | if ((Type == MK_ImplicitModule || Type == MK_ExplicitModule || |
| 4042 | Type == MK_PrebuiltModule) && |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4043 | F.ModuleName.empty()) { |
| 4044 | auto Result = (Type == MK_ImplicitModule) ? OutOfDate : Failure; |
| 4045 | if (Result != OutOfDate || |
| 4046 | (ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 4047 | Diag(diag::err_module_file_not_module) << FileName; |
| 4048 | return Result; |
| 4049 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4050 | break; |
| 4051 | |
| 4052 | case Failure: return Failure; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4053 | case Missing: return Missing; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4054 | case OutOfDate: return OutOfDate; |
| 4055 | case VersionMismatch: return VersionMismatch; |
| 4056 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 4057 | case HadErrors: return HadErrors; |
| 4058 | } |
| 4059 | break; |
Richard Smith | f8c3255 | 2015-09-02 17:45:54 +0000 | [diff] [blame] | 4060 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4061 | case AST_BLOCK_ID: |
| 4062 | if (!HaveReadControlBlock) { |
| 4063 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 4064 | Diag(diag::err_pch_version_too_old); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4065 | return VersionMismatch; |
| 4066 | } |
| 4067 | |
| 4068 | // Record that we've loaded this module. |
| 4069 | Loaded.push_back(ImportedModule(M, ImportedBy, ImportLoc)); |
| 4070 | return Success; |
| 4071 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4072 | case UNHASHED_CONTROL_BLOCK_ID: |
| 4073 | // This block is handled using look-ahead during ReadControlBlock. We |
| 4074 | // shouldn't get here! |
| 4075 | Error("malformed block record in AST file"); |
| 4076 | return Failure; |
| 4077 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4078 | default: |
| 4079 | if (Stream.SkipBlock()) { |
| 4080 | Error("malformed block record in AST file"); |
| 4081 | return Failure; |
| 4082 | } |
| 4083 | break; |
| 4084 | } |
| 4085 | } |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4086 | |
| 4087 | return Success; |
| 4088 | } |
| 4089 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4090 | ASTReader::ASTReadResult |
| 4091 | ASTReader::readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy, |
| 4092 | unsigned ClientLoadCapabilities) { |
| 4093 | const HeaderSearchOptions &HSOpts = |
| 4094 | PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 4095 | bool AllowCompatibleConfigurationMismatch = |
| 4096 | F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule; |
| 4097 | |
| 4098 | ASTReadResult Result = readUnhashedControlBlockImpl( |
| 4099 | &F, F.Data, ClientLoadCapabilities, AllowCompatibleConfigurationMismatch, |
| 4100 | Listener.get(), |
| 4101 | WasImportedBy ? false : HSOpts.ModulesValidateDiagnosticOptions); |
| 4102 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4103 | // If F was directly imported by another module, it's implicitly validated by |
| 4104 | // the importing module. |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4105 | if (DisableValidation || WasImportedBy || |
| 4106 | (AllowConfigurationMismatch && Result == ConfigurationMismatch)) |
| 4107 | return Success; |
| 4108 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4109 | if (Result == Failure) { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4110 | Error("malformed block record in AST file"); |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4111 | return Failure; |
| 4112 | } |
| 4113 | |
| 4114 | if (Result == OutOfDate && F.Kind == MK_ImplicitModule) { |
| 4115 | // If this module has already been finalized in the PCMCache, we're stuck |
| 4116 | // with it; we can only load a single version of each module. |
| 4117 | // |
| 4118 | // This can happen when a module is imported in two contexts: in one, as a |
| 4119 | // user module; in another, as a system module (due to an import from |
| 4120 | // another module marked with the [system] flag). It usually indicates a |
| 4121 | // bug in the module map: this module should also be marked with [system]. |
| 4122 | // |
| 4123 | // If -Wno-system-headers (the default), and the first import is as a |
| 4124 | // system module, then validation will fail during the as-user import, |
| 4125 | // since -Werror flags won't have been validated. However, it's reasonable |
| 4126 | // to treat this consistently as a system module. |
| 4127 | // |
| 4128 | // If -Wsystem-headers, the PCM on disk was built with |
| 4129 | // -Wno-system-headers, and the first import is as a user module, then |
| 4130 | // validation will fail during the as-system import since the PCM on disk |
| 4131 | // doesn't guarantee that -Werror was respected. However, the -Werror |
| 4132 | // flags were checked during the initial as-user import. |
| 4133 | if (PCMCache.isBufferFinal(F.FileName)) { |
| 4134 | Diag(diag::warn_module_system_bit_conflict) << F.FileName; |
| 4135 | return Success; |
| 4136 | } |
| 4137 | } |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4138 | |
| 4139 | return Result; |
| 4140 | } |
| 4141 | |
| 4142 | ASTReader::ASTReadResult ASTReader::readUnhashedControlBlockImpl( |
| 4143 | ModuleFile *F, llvm::StringRef StreamData, unsigned ClientLoadCapabilities, |
| 4144 | bool AllowCompatibleConfigurationMismatch, ASTReaderListener *Listener, |
| 4145 | bool ValidateDiagnosticOptions) { |
| 4146 | // Initialize a stream. |
| 4147 | BitstreamCursor Stream(StreamData); |
| 4148 | |
| 4149 | // Sniff for the signature. |
| 4150 | if (!startsWithASTFileMagic(Stream)) |
| 4151 | return Failure; |
| 4152 | |
| 4153 | // Scan for the UNHASHED_CONTROL_BLOCK_ID block. |
| 4154 | if (SkipCursorToBlock(Stream, UNHASHED_CONTROL_BLOCK_ID)) |
| 4155 | return Failure; |
| 4156 | |
| 4157 | // Read all of the records in the options block. |
| 4158 | RecordData Record; |
| 4159 | ASTReadResult Result = Success; |
| 4160 | while (1) { |
| 4161 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4162 | |
| 4163 | switch (Entry.Kind) { |
| 4164 | case llvm::BitstreamEntry::Error: |
| 4165 | case llvm::BitstreamEntry::SubBlock: |
| 4166 | return Failure; |
| 4167 | |
| 4168 | case llvm::BitstreamEntry::EndBlock: |
| 4169 | return Result; |
| 4170 | |
| 4171 | case llvm::BitstreamEntry::Record: |
| 4172 | // The interesting case. |
| 4173 | break; |
| 4174 | } |
| 4175 | |
| 4176 | // Read and process a record. |
| 4177 | Record.clear(); |
| 4178 | switch ( |
| 4179 | (UnhashedControlBlockRecordTypes)Stream.readRecord(Entry.ID, Record)) { |
| 4180 | case SIGNATURE: { |
| 4181 | if (F) |
| 4182 | std::copy(Record.begin(), Record.end(), F->Signature.data()); |
| 4183 | break; |
| 4184 | } |
| 4185 | case DIAGNOSTIC_OPTIONS: { |
| 4186 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
| 4187 | if (Listener && ValidateDiagnosticOptions && |
| 4188 | !AllowCompatibleConfigurationMismatch && |
| 4189 | ParseDiagnosticOptions(Record, Complain, *Listener)) |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4190 | Result = OutOfDate; // Don't return early. Read the signature. |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4191 | break; |
| 4192 | } |
| 4193 | case DIAG_PRAGMA_MAPPINGS: |
| 4194 | if (!F) |
| 4195 | break; |
| 4196 | if (F->PragmaDiagMappings.empty()) |
| 4197 | F->PragmaDiagMappings.swap(Record); |
| 4198 | else |
| 4199 | F->PragmaDiagMappings.insert(F->PragmaDiagMappings.end(), |
| 4200 | Record.begin(), Record.end()); |
| 4201 | break; |
| 4202 | } |
| 4203 | } |
| 4204 | } |
| 4205 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4206 | /// Parse a record and blob containing module file extension metadata. |
| 4207 | static bool parseModuleFileExtensionMetadata( |
| 4208 | const SmallVectorImpl<uint64_t> &Record, |
| 4209 | StringRef Blob, |
| 4210 | ModuleFileExtensionMetadata &Metadata) { |
| 4211 | if (Record.size() < 4) return true; |
| 4212 | |
| 4213 | Metadata.MajorVersion = Record[0]; |
| 4214 | Metadata.MinorVersion = Record[1]; |
| 4215 | |
| 4216 | unsigned BlockNameLen = Record[2]; |
| 4217 | unsigned UserInfoLen = Record[3]; |
| 4218 | |
| 4219 | if (BlockNameLen + UserInfoLen > Blob.size()) return true; |
| 4220 | |
| 4221 | Metadata.BlockName = std::string(Blob.data(), Blob.data() + BlockNameLen); |
| 4222 | Metadata.UserInfo = std::string(Blob.data() + BlockNameLen, |
| 4223 | Blob.data() + BlockNameLen + UserInfoLen); |
| 4224 | return false; |
| 4225 | } |
| 4226 | |
| 4227 | ASTReader::ASTReadResult ASTReader::ReadExtensionBlock(ModuleFile &F) { |
| 4228 | BitstreamCursor &Stream = F.Stream; |
| 4229 | |
| 4230 | RecordData Record; |
| 4231 | while (true) { |
| 4232 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4233 | switch (Entry.Kind) { |
| 4234 | case llvm::BitstreamEntry::SubBlock: |
| 4235 | if (Stream.SkipBlock()) |
| 4236 | return Failure; |
| 4237 | |
| 4238 | continue; |
| 4239 | |
| 4240 | case llvm::BitstreamEntry::EndBlock: |
| 4241 | return Success; |
| 4242 | |
| 4243 | case llvm::BitstreamEntry::Error: |
| 4244 | return HadErrors; |
| 4245 | |
| 4246 | case llvm::BitstreamEntry::Record: |
| 4247 | break; |
| 4248 | } |
| 4249 | |
| 4250 | Record.clear(); |
| 4251 | StringRef Blob; |
| 4252 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
| 4253 | switch (RecCode) { |
| 4254 | case EXTENSION_METADATA: { |
| 4255 | ModuleFileExtensionMetadata Metadata; |
| 4256 | if (parseModuleFileExtensionMetadata(Record, Blob, Metadata)) |
| 4257 | return Failure; |
| 4258 | |
| 4259 | // Find a module file extension with this block name. |
| 4260 | auto Known = ModuleFileExtensions.find(Metadata.BlockName); |
| 4261 | if (Known == ModuleFileExtensions.end()) break; |
| 4262 | |
| 4263 | // Form a reader. |
| 4264 | if (auto Reader = Known->second->createExtensionReader(Metadata, *this, |
| 4265 | F, Stream)) { |
| 4266 | F.ExtensionReaders.push_back(std::move(Reader)); |
| 4267 | } |
| 4268 | |
| 4269 | break; |
| 4270 | } |
| 4271 | } |
| 4272 | } |
| 4273 | |
| 4274 | return Success; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4275 | } |
| 4276 | |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4277 | void ASTReader::InitializeContext() { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4278 | // If there's a listener, notify them that we "read" the translation unit. |
| 4279 | if (DeserializationListener) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4280 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4281 | Context.getTranslationUnitDecl()); |
| 4282 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4283 | // FIXME: Find a better way to deal with collisions between these |
| 4284 | // built-in types. Right now, we just ignore the problem. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4285 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4286 | // Load the special types. |
| 4287 | if (SpecialTypes.size() >= NumSpecialTypeIDs) { |
| 4288 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 4289 | if (!Context.CFConstantStringTypeDecl) |
| 4290 | Context.setCFConstantStringType(GetType(String)); |
| 4291 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4292 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4293 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 4294 | QualType FileType = GetType(File); |
| 4295 | if (FileType.isNull()) { |
| 4296 | Error("FILE type is NULL"); |
| 4297 | return; |
| 4298 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4299 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4300 | if (!Context.FILEDecl) { |
| 4301 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 4302 | Context.setFILEDecl(Typedef->getDecl()); |
| 4303 | else { |
| 4304 | const TagType *Tag = FileType->getAs<TagType>(); |
| 4305 | if (!Tag) { |
| 4306 | Error("Invalid FILE type in AST file"); |
| 4307 | return; |
| 4308 | } |
| 4309 | Context.setFILEDecl(Tag->getDecl()); |
| 4310 | } |
| 4311 | } |
| 4312 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4313 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4314 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) { |
| 4315 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 4316 | if (Jmp_bufType.isNull()) { |
| 4317 | Error("jmp_buf type is NULL"); |
| 4318 | return; |
| 4319 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4320 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4321 | if (!Context.jmp_bufDecl) { |
| 4322 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 4323 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 4324 | else { |
| 4325 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 4326 | if (!Tag) { |
| 4327 | Error("Invalid jmp_buf type in AST file"); |
| 4328 | return; |
| 4329 | } |
| 4330 | Context.setjmp_bufDecl(Tag->getDecl()); |
| 4331 | } |
| 4332 | } |
| 4333 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4334 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4335 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) { |
| 4336 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 4337 | if (Sigjmp_bufType.isNull()) { |
| 4338 | Error("sigjmp_buf type is NULL"); |
| 4339 | return; |
| 4340 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4341 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4342 | if (!Context.sigjmp_bufDecl) { |
| 4343 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 4344 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 4345 | else { |
| 4346 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 4347 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 4348 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 4349 | } |
| 4350 | } |
| 4351 | } |
| 4352 | |
| 4353 | if (unsigned ObjCIdRedef |
| 4354 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 4355 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 4356 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 4357 | } |
| 4358 | |
| 4359 | if (unsigned ObjCClassRedef |
| 4360 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 4361 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 4362 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 4363 | } |
| 4364 | |
| 4365 | if (unsigned ObjCSelRedef |
| 4366 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 4367 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 4368 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 4369 | } |
| 4370 | |
| 4371 | if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) { |
| 4372 | QualType Ucontext_tType = GetType(Ucontext_t); |
| 4373 | if (Ucontext_tType.isNull()) { |
| 4374 | Error("ucontext_t type is NULL"); |
| 4375 | return; |
| 4376 | } |
| 4377 | |
| 4378 | if (!Context.ucontext_tDecl) { |
| 4379 | if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>()) |
| 4380 | Context.setucontext_tDecl(Typedef->getDecl()); |
| 4381 | else { |
| 4382 | const TagType *Tag = Ucontext_tType->getAs<TagType>(); |
| 4383 | assert(Tag && "Invalid ucontext_t type in AST file"); |
| 4384 | Context.setucontext_tDecl(Tag->getDecl()); |
| 4385 | } |
| 4386 | } |
| 4387 | } |
| 4388 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4389 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4390 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
| 4391 | |
| 4392 | // If there were any CUDA special declarations, deserialize them. |
| 4393 | if (!CUDASpecialDeclRefs.empty()) { |
| 4394 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 4395 | Context.setcudaConfigureCallDecl( |
| 4396 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 4397 | } |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4398 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4399 | // 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] | 4400 | // FIXME: This does not make macro-only imports visible again. |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4401 | for (auto &Import : ImportedModules) { |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4402 | if (Module *Imported = getSubmodule(Import.ID)) { |
Argyrios Kyrtzidis | 125df05 | 2013-02-01 16:36:12 +0000 | [diff] [blame] | 4403 | makeModuleVisible(Imported, Module::AllVisible, |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4404 | /*ImportLoc=*/Import.ImportLoc); |
Ben Langmuir | 6d25fdc | 2016-02-11 17:04:42 +0000 | [diff] [blame] | 4405 | if (Import.ImportLoc.isValid()) |
| 4406 | PP.makeModuleVisible(Imported, Import.ImportLoc); |
| 4407 | // FIXME: should we tell Sema to make the module visible too? |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4408 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4409 | } |
| 4410 | ImportedModules.clear(); |
| 4411 | } |
| 4412 | |
| 4413 | void ASTReader::finalizeForWriting() { |
Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 4414 | // Nothing to do for now. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4415 | } |
| 4416 | |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4417 | /// \brief Reads and return the signature record from \p PCH's control block, or |
| 4418 | /// else returns 0. |
| 4419 | static ASTFileSignature readASTFileSignature(StringRef PCH) { |
| 4420 | BitstreamCursor Stream(PCH); |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4421 | if (!startsWithASTFileMagic(Stream)) |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4422 | return ASTFileSignature(); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4423 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4424 | // Scan for the UNHASHED_CONTROL_BLOCK_ID block. |
| 4425 | if (SkipCursorToBlock(Stream, UNHASHED_CONTROL_BLOCK_ID)) |
| 4426 | return ASTFileSignature(); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4427 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4428 | // Scan for SIGNATURE inside the diagnostic options block. |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4429 | ASTReader::RecordData Record; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4430 | while (true) { |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4431 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
Simon Pilgrim | 0b33f11 | 2016-11-16 16:11:08 +0000 | [diff] [blame] | 4432 | if (Entry.Kind != llvm::BitstreamEntry::Record) |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4433 | return ASTFileSignature(); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4434 | |
| 4435 | Record.clear(); |
| 4436 | StringRef Blob; |
| 4437 | if (SIGNATURE == Stream.readRecord(Entry.ID, Record, &Blob)) |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4438 | return {{{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2], |
| 4439 | (uint32_t)Record[3], (uint32_t)Record[4]}}}; |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4440 | } |
| 4441 | } |
| 4442 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4443 | /// \brief Retrieve the name of the original source file name |
| 4444 | /// directly from the AST file, without actually loading the AST |
| 4445 | /// file. |
Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame] | 4446 | std::string ASTReader::getOriginalSourceFile( |
| 4447 | const std::string &ASTFileName, FileManager &FileMgr, |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 4448 | const PCHContainerReader &PCHContainerRdr, DiagnosticsEngine &Diags) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4449 | // Open the AST file. |
Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 4450 | auto Buffer = FileMgr.getBufferForFile(ASTFileName); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4451 | if (!Buffer) { |
Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 4452 | Diags.Report(diag::err_fe_unable_to_read_pch_file) |
| 4453 | << ASTFileName << Buffer.getError().message(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4454 | return std::string(); |
| 4455 | } |
| 4456 | |
| 4457 | // Initialize the stream |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4458 | BitstreamCursor Stream(PCHContainerRdr.ExtractPCH(**Buffer)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4459 | |
| 4460 | // Sniff for the signature. |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4461 | if (!startsWithASTFileMagic(Stream)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4462 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
| 4463 | return std::string(); |
| 4464 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4465 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4466 | // Scan for the CONTROL_BLOCK_ID block. |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4467 | if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4468 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
| 4469 | return std::string(); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4470 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4471 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4472 | // Scan for ORIGINAL_FILE inside the control block. |
| 4473 | RecordData Record; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4474 | while (true) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4475 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4476 | if (Entry.Kind == llvm::BitstreamEntry::EndBlock) |
| 4477 | return std::string(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4478 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4479 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| 4480 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
| 4481 | return std::string(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4482 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4483 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4484 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4485 | StringRef Blob; |
| 4486 | if (Stream.readRecord(Entry.ID, Record, &Blob) == ORIGINAL_FILE) |
| 4487 | return Blob.str(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4488 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4492 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4493 | class SimplePCHValidator : public ASTReaderListener { |
| 4494 | const LangOptions &ExistingLangOpts; |
| 4495 | const TargetOptions &ExistingTargetOpts; |
| 4496 | const PreprocessorOptions &ExistingPPOpts; |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4497 | std::string ExistingModuleCachePath; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4498 | FileManager &FileMgr; |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4499 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4500 | public: |
| 4501 | SimplePCHValidator(const LangOptions &ExistingLangOpts, |
| 4502 | const TargetOptions &ExistingTargetOpts, |
| 4503 | const PreprocessorOptions &ExistingPPOpts, |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4504 | StringRef ExistingModuleCachePath, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4505 | FileManager &FileMgr) |
| 4506 | : ExistingLangOpts(ExistingLangOpts), |
| 4507 | ExistingTargetOpts(ExistingTargetOpts), |
| 4508 | ExistingPPOpts(ExistingPPOpts), |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4509 | ExistingModuleCachePath(ExistingModuleCachePath), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4510 | FileMgr(FileMgr) |
| 4511 | { |
| 4512 | } |
| 4513 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 4514 | bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, |
| 4515 | bool AllowCompatibleDifferences) override { |
| 4516 | return checkLanguageOptions(ExistingLangOpts, LangOpts, nullptr, |
| 4517 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4518 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4519 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 4520 | bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, |
| 4521 | bool AllowCompatibleDifferences) override { |
| 4522 | return checkTargetOptions(ExistingTargetOpts, TargetOpts, nullptr, |
| 4523 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4524 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4525 | |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4526 | bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 4527 | StringRef SpecificModuleCachePath, |
| 4528 | bool Complain) override { |
| 4529 | return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 4530 | ExistingModuleCachePath, |
| 4531 | nullptr, ExistingLangOpts); |
| 4532 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4533 | |
Craig Topper | 3e89dfe | 2014-03-13 02:13:41 +0000 | [diff] [blame] | 4534 | bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 4535 | bool Complain, |
| 4536 | std::string &SuggestedPredefines) override { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4537 | return checkPreprocessorOptions(ExistingPPOpts, PPOpts, nullptr, FileMgr, |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 4538 | SuggestedPredefines, ExistingLangOpts); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4539 | } |
| 4540 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4541 | |
| 4542 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4543 | |
Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame] | 4544 | bool ASTReader::readASTFileControlBlock( |
| 4545 | StringRef Filename, FileManager &FileMgr, |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 4546 | const PCHContainerReader &PCHContainerRdr, |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4547 | bool FindModuleFileExtensions, |
Manman Ren | 47a4445 | 2016-07-26 17:12:17 +0000 | [diff] [blame] | 4548 | ASTReaderListener &Listener, bool ValidateDiagnosticOptions) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4549 | // Open the AST file. |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 4550 | // FIXME: This allows use of the VFS; we do not allow use of the |
| 4551 | // VFS when actually loading a module. |
Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 4552 | auto Buffer = FileMgr.getBufferForFile(Filename); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4553 | if (!Buffer) { |
| 4554 | return true; |
| 4555 | } |
| 4556 | |
| 4557 | // Initialize the stream |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4558 | StringRef Bytes = PCHContainerRdr.ExtractPCH(**Buffer); |
| 4559 | BitstreamCursor Stream(Bytes); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4560 | |
| 4561 | // Sniff for the signature. |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4562 | if (!startsWithASTFileMagic(Stream)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4563 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4564 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4565 | // Scan for the CONTROL_BLOCK_ID block. |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4566 | if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4567 | return true; |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4568 | |
| 4569 | bool NeedsInputFiles = Listener.needsInputFileVisitation(); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 4570 | bool NeedsSystemInputFiles = Listener.needsSystemInputFileVisitation(); |
Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4571 | bool NeedsImports = Listener.needsImportVisitation(); |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4572 | BitstreamCursor InputFilesCursor; |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4573 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4574 | RecordData Record; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4575 | std::string ModuleDir; |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4576 | bool DoneWithControlBlock = false; |
| 4577 | while (!DoneWithControlBlock) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4578 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4579 | |
| 4580 | switch (Entry.Kind) { |
| 4581 | case llvm::BitstreamEntry::SubBlock: { |
| 4582 | switch (Entry.ID) { |
| 4583 | case OPTIONS_BLOCK_ID: { |
| 4584 | std::string IgnoredSuggestedPredefines; |
| 4585 | if (ReadOptionsBlock(Stream, ARR_ConfigurationMismatch | ARR_OutOfDate, |
| 4586 | /*AllowCompatibleConfigurationMismatch*/ false, |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4587 | Listener, IgnoredSuggestedPredefines) != Success) |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4588 | return true; |
| 4589 | break; |
| 4590 | } |
| 4591 | |
| 4592 | case INPUT_FILES_BLOCK_ID: |
| 4593 | InputFilesCursor = Stream; |
| 4594 | if (Stream.SkipBlock() || |
| 4595 | (NeedsInputFiles && |
| 4596 | ReadBlockAbbrevs(InputFilesCursor, INPUT_FILES_BLOCK_ID))) |
| 4597 | return true; |
| 4598 | break; |
| 4599 | |
| 4600 | default: |
| 4601 | if (Stream.SkipBlock()) |
| 4602 | return true; |
| 4603 | break; |
| 4604 | } |
| 4605 | |
| 4606 | continue; |
| 4607 | } |
| 4608 | |
| 4609 | case llvm::BitstreamEntry::EndBlock: |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4610 | DoneWithControlBlock = true; |
| 4611 | break; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4612 | |
| 4613 | case llvm::BitstreamEntry::Error: |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4614 | return true; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4615 | |
| 4616 | case llvm::BitstreamEntry::Record: |
| 4617 | break; |
| 4618 | } |
| 4619 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4620 | if (DoneWithControlBlock) break; |
| 4621 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4622 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4623 | StringRef Blob; |
| 4624 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4625 | switch ((ControlRecordTypes)RecCode) { |
| 4626 | case METADATA: { |
| 4627 | if (Record[0] != VERSION_MAJOR) |
| 4628 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4629 | |
Douglas Gregor | bf7fc9c | 2013-03-27 16:47:18 +0000 | [diff] [blame] | 4630 | if (Listener.ReadFullVersionInformation(Blob)) |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4631 | return true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4632 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4633 | break; |
| 4634 | } |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 4635 | case MODULE_NAME: |
| 4636 | Listener.ReadModuleName(Blob); |
| 4637 | break; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4638 | case MODULE_DIRECTORY: |
| 4639 | ModuleDir = Blob; |
| 4640 | break; |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 4641 | case MODULE_MAP_FILE: { |
| 4642 | unsigned Idx = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4643 | auto Path = ReadString(Record, Idx); |
| 4644 | ResolveImportedPath(Path, ModuleDir); |
| 4645 | Listener.ReadModuleMapFile(Path); |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 4646 | break; |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 4647 | } |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4648 | case INPUT_FILE_OFFSETS: { |
| 4649 | if (!NeedsInputFiles) |
| 4650 | break; |
| 4651 | |
| 4652 | unsigned NumInputFiles = Record[0]; |
| 4653 | unsigned NumUserFiles = Record[1]; |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 4654 | const uint64_t *InputFileOffs = (const uint64_t *)Blob.data(); |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4655 | for (unsigned I = 0; I != NumInputFiles; ++I) { |
| 4656 | // Go find this input file. |
| 4657 | bool isSystemFile = I >= NumUserFiles; |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 4658 | |
| 4659 | if (isSystemFile && !NeedsSystemInputFiles) |
| 4660 | break; // the rest are system input files |
| 4661 | |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4662 | BitstreamCursor &Cursor = InputFilesCursor; |
| 4663 | SavedStreamPosition SavedPosition(Cursor); |
| 4664 | Cursor.JumpToBit(InputFileOffs[I]); |
| 4665 | |
| 4666 | unsigned Code = Cursor.ReadCode(); |
| 4667 | RecordData Record; |
| 4668 | StringRef Blob; |
| 4669 | bool shouldContinue = false; |
| 4670 | switch ((InputFileRecordTypes)Cursor.readRecord(Code, Record, &Blob)) { |
| 4671 | case INPUT_FILE: |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 4672 | bool Overridden = static_cast<bool>(Record[3]); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4673 | std::string Filename = Blob; |
| 4674 | ResolveImportedPath(Filename, ModuleDir); |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 4675 | shouldContinue = Listener.visitInputFile( |
| 4676 | Filename, isSystemFile, Overridden, /*IsExplicitModule*/false); |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4677 | break; |
| 4678 | } |
| 4679 | if (!shouldContinue) |
| 4680 | break; |
| 4681 | } |
| 4682 | break; |
| 4683 | } |
| 4684 | |
Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4685 | case IMPORTS: { |
| 4686 | if (!NeedsImports) |
| 4687 | break; |
| 4688 | |
| 4689 | unsigned Idx = 0, N = Record.size(); |
| 4690 | while (Idx < N) { |
| 4691 | // Read information about the AST file. |
Richard Smith | 79c98cc | 2014-10-27 23:25:15 +0000 | [diff] [blame] | 4692 | Idx += 5; // ImportLoc, Size, ModTime, Signature |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4693 | std::string Filename = ReadString(Record, Idx); |
| 4694 | ResolveImportedPath(Filename, ModuleDir); |
| 4695 | Listener.visitImport(Filename); |
Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4696 | } |
| 4697 | break; |
| 4698 | } |
| 4699 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4700 | default: |
| 4701 | // No other validation to perform. |
| 4702 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4703 | } |
| 4704 | } |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4705 | |
| 4706 | // Look for module file extension blocks, if requested. |
| 4707 | if (FindModuleFileExtensions) { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4708 | BitstreamCursor SavedStream = Stream; |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4709 | while (!SkipCursorToBlock(Stream, EXTENSION_BLOCK_ID)) { |
| 4710 | bool DoneWithExtensionBlock = false; |
| 4711 | while (!DoneWithExtensionBlock) { |
| 4712 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4713 | |
| 4714 | switch (Entry.Kind) { |
| 4715 | case llvm::BitstreamEntry::SubBlock: |
| 4716 | if (Stream.SkipBlock()) |
| 4717 | return true; |
| 4718 | |
| 4719 | continue; |
| 4720 | |
| 4721 | case llvm::BitstreamEntry::EndBlock: |
| 4722 | DoneWithExtensionBlock = true; |
| 4723 | continue; |
| 4724 | |
| 4725 | case llvm::BitstreamEntry::Error: |
| 4726 | return true; |
| 4727 | |
| 4728 | case llvm::BitstreamEntry::Record: |
| 4729 | break; |
| 4730 | } |
| 4731 | |
| 4732 | Record.clear(); |
| 4733 | StringRef Blob; |
| 4734 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
| 4735 | switch (RecCode) { |
| 4736 | case EXTENSION_METADATA: { |
| 4737 | ModuleFileExtensionMetadata Metadata; |
| 4738 | if (parseModuleFileExtensionMetadata(Record, Blob, Metadata)) |
| 4739 | return true; |
| 4740 | |
| 4741 | Listener.readModuleFileExtension(Metadata); |
| 4742 | break; |
| 4743 | } |
| 4744 | } |
| 4745 | } |
| 4746 | } |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4747 | Stream = SavedStream; |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4748 | } |
| 4749 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4750 | // Scan for the UNHASHED_CONTROL_BLOCK_ID block. |
| 4751 | if (readUnhashedControlBlockImpl( |
| 4752 | nullptr, Bytes, ARR_ConfigurationMismatch | ARR_OutOfDate, |
| 4753 | /*AllowCompatibleConfigurationMismatch*/ false, &Listener, |
| 4754 | ValidateDiagnosticOptions) != Success) |
| 4755 | return true; |
| 4756 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4757 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4758 | } |
| 4759 | |
Benjamin Kramer | f6021ec | 2017-03-21 21:35:04 +0000 | [diff] [blame] | 4760 | bool ASTReader::isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, |
| 4761 | const PCHContainerReader &PCHContainerRdr, |
| 4762 | const LangOptions &LangOpts, |
| 4763 | const TargetOptions &TargetOpts, |
| 4764 | const PreprocessorOptions &PPOpts, |
| 4765 | StringRef ExistingModuleCachePath) { |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4766 | SimplePCHValidator validator(LangOpts, TargetOpts, PPOpts, |
| 4767 | ExistingModuleCachePath, FileMgr); |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 4768 | return !readASTFileControlBlock(Filename, FileMgr, PCHContainerRdr, |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4769 | /*FindModuleFileExtensions=*/false, |
Manman Ren | 47a4445 | 2016-07-26 17:12:17 +0000 | [diff] [blame] | 4770 | validator, |
| 4771 | /*ValidateDiagnosticOptions=*/true); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4772 | } |
| 4773 | |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4774 | ASTReader::ASTReadResult |
| 4775 | ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4776 | // Enter the submodule block. |
| 4777 | if (F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) { |
| 4778 | Error("malformed submodule block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4779 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4780 | } |
| 4781 | |
| 4782 | ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap(); |
| 4783 | bool First = true; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4784 | Module *CurrentModule = nullptr; |
Richard Smith | 145e15a | 2017-04-24 23:12:30 +0000 | [diff] [blame] | 4785 | Module::ModuleKind ModuleKind = Module::ModuleMapModule; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4786 | RecordData Record; |
| 4787 | while (true) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4788 | llvm::BitstreamEntry Entry = F.Stream.advanceSkippingSubblocks(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4789 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4790 | switch (Entry.Kind) { |
| 4791 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 4792 | case llvm::BitstreamEntry::Error: |
| 4793 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4794 | return Failure; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4795 | case llvm::BitstreamEntry::EndBlock: |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4796 | return Success; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4797 | case llvm::BitstreamEntry::Record: |
| 4798 | // The interesting case. |
| 4799 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4800 | } |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4801 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4802 | // Read a record. |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4803 | StringRef Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4804 | Record.clear(); |
Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4805 | auto Kind = F.Stream.readRecord(Entry.ID, Record, &Blob); |
| 4806 | |
| 4807 | if ((Kind == SUBMODULE_METADATA) != First) { |
| 4808 | Error("submodule metadata record should be at beginning of block"); |
| 4809 | return Failure; |
| 4810 | } |
| 4811 | First = false; |
| 4812 | |
| 4813 | // Submodule information is only valid if we have a current module. |
| 4814 | // FIXME: Should we error on these cases? |
| 4815 | if (!CurrentModule && Kind != SUBMODULE_METADATA && |
| 4816 | Kind != SUBMODULE_DEFINITION) |
| 4817 | continue; |
| 4818 | |
| 4819 | switch (Kind) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4820 | default: // Default behavior: ignore. |
| 4821 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4822 | |
Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4823 | case SUBMODULE_DEFINITION: { |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4824 | if (Record.size() < 8) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4825 | Error("malformed module definition"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4826 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4827 | } |
Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4828 | |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4829 | StringRef Name = Blob; |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 4830 | unsigned Idx = 0; |
| 4831 | SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[Idx++]); |
| 4832 | SubmoduleID Parent = getGlobalSubmoduleID(F, Record[Idx++]); |
| 4833 | bool IsFramework = Record[Idx++]; |
| 4834 | bool IsExplicit = Record[Idx++]; |
| 4835 | bool IsSystem = Record[Idx++]; |
| 4836 | bool IsExternC = Record[Idx++]; |
| 4837 | bool InferSubmodules = Record[Idx++]; |
| 4838 | bool InferExplicitSubmodules = Record[Idx++]; |
| 4839 | bool InferExportWildcard = Record[Idx++]; |
| 4840 | bool ConfigMacrosExhaustive = Record[Idx++]; |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4841 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4842 | Module *ParentModule = nullptr; |
Ben Langmuir | 9d6448b | 2014-08-09 00:57:23 +0000 | [diff] [blame] | 4843 | if (Parent) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4844 | ParentModule = getSubmodule(Parent); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4845 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4846 | // Retrieve this (sub)module from the module map, creating it if |
| 4847 | // necessary. |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 4848 | CurrentModule = |
| 4849 | ModMap.findOrCreateModule(Name, ParentModule, IsFramework, IsExplicit) |
| 4850 | .first; |
Ben Langmuir | 9d6448b | 2014-08-09 00:57:23 +0000 | [diff] [blame] | 4851 | |
| 4852 | // FIXME: set the definition loc for CurrentModule, or call |
| 4853 | // ModMap.setInferredModuleAllowedBy() |
| 4854 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4855 | SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS; |
| 4856 | if (GlobalIndex >= SubmodulesLoaded.size() || |
| 4857 | SubmodulesLoaded[GlobalIndex]) { |
| 4858 | Error("too many submodules"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4859 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4860 | } |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4861 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4862 | if (!ParentModule) { |
| 4863 | if (const FileEntry *CurFile = CurrentModule->getASTFile()) { |
| 4864 | if (CurFile != F.File) { |
| 4865 | if (!Diags.isDiagnosticInFlight()) { |
| 4866 | Diag(diag::err_module_file_conflict) |
| 4867 | << CurrentModule->getTopLevelModuleName() |
| 4868 | << CurFile->getName() |
| 4869 | << F.File->getName(); |
| 4870 | } |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4871 | return Failure; |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4872 | } |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4873 | } |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4874 | |
| 4875 | CurrentModule->setASTFile(F.File); |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4876 | } |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4877 | |
Richard Smith | 145e15a | 2017-04-24 23:12:30 +0000 | [diff] [blame] | 4878 | CurrentModule->Kind = ModuleKind; |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 4879 | CurrentModule->Signature = F.Signature; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4880 | CurrentModule->IsFromModuleFile = true; |
| 4881 | CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem; |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 4882 | CurrentModule->IsExternC = IsExternC; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4883 | CurrentModule->InferSubmodules = InferSubmodules; |
| 4884 | CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules; |
| 4885 | CurrentModule->InferExportWildcard = InferExportWildcard; |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4886 | CurrentModule->ConfigMacrosExhaustive = ConfigMacrosExhaustive; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4887 | if (DeserializationListener) |
| 4888 | DeserializationListener->ModuleRead(GlobalID, CurrentModule); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4889 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4890 | SubmodulesLoaded[GlobalIndex] = CurrentModule; |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 4891 | |
Richard Smith | 8a3e39a | 2016-03-28 21:31:09 +0000 | [diff] [blame] | 4892 | // 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] | 4893 | CurrentModule->LinkLibraries.clear(); |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4894 | CurrentModule->ConfigMacros.clear(); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4895 | CurrentModule->UnresolvedConflicts.clear(); |
| 4896 | CurrentModule->Conflicts.clear(); |
Richard Smith | 8a3e39a | 2016-03-28 21:31:09 +0000 | [diff] [blame] | 4897 | |
| 4898 | // The module is available unless it's missing a requirement; relevant |
| 4899 | // requirements will be (re-)added by SUBMODULE_REQUIRES records. |
| 4900 | // Missing headers that were present when the module was built do not |
| 4901 | // make it unavailable -- if we got this far, this must be an explicitly |
| 4902 | // imported module file. |
| 4903 | CurrentModule->Requirements.clear(); |
| 4904 | CurrentModule->MissingHeaders.clear(); |
| 4905 | CurrentModule->IsMissingRequirement = |
| 4906 | ParentModule && ParentModule->IsMissingRequirement; |
| 4907 | CurrentModule->IsAvailable = !CurrentModule->IsMissingRequirement; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4908 | break; |
| 4909 | } |
Richard Smith | 8a3e39a | 2016-03-28 21:31:09 +0000 | [diff] [blame] | 4910 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4911 | case SUBMODULE_UMBRELLA_HEADER: { |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 4912 | std::string Filename = Blob; |
| 4913 | ResolveImportedPath(F, Filename); |
| 4914 | if (auto *Umbrella = PP.getFileManager().getFile(Filename)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4915 | if (!CurrentModule->getUmbrellaHeader()) |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 4916 | ModMap.setUmbrellaHeader(CurrentModule, Umbrella, Blob); |
| 4917 | else if (CurrentModule->getUmbrellaHeader().Entry != Umbrella) { |
Bruno Cardoso Lopes | 573b13f | 2017-03-22 00:11:21 +0000 | [diff] [blame] | 4918 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 4919 | Error("mismatched umbrella headers in submodule"); |
| 4920 | return OutOfDate; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4921 | } |
| 4922 | } |
| 4923 | break; |
| 4924 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4925 | |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 4926 | case SUBMODULE_HEADER: |
| 4927 | case SUBMODULE_EXCLUDED_HEADER: |
| 4928 | case SUBMODULE_PRIVATE_HEADER: |
| 4929 | // We lazily associate headers with their modules via the HeaderInfo table. |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 4930 | // FIXME: Re-evaluate this section; maybe only store InputFile IDs instead |
| 4931 | // of complete filenames or remove it entirely. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 4932 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4933 | |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 4934 | case SUBMODULE_TEXTUAL_HEADER: |
| 4935 | case SUBMODULE_PRIVATE_TEXTUAL_HEADER: |
| 4936 | // FIXME: Textual headers are not marked in the HeaderInfo table. Load |
| 4937 | // them here. |
| 4938 | break; |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 4939 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4940 | case SUBMODULE_TOPHEADER: { |
Argyrios Kyrtzidis | 3c5305c | 2013-03-13 21:13:43 +0000 | [diff] [blame] | 4941 | CurrentModule->addTopHeaderFilename(Blob); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4942 | break; |
| 4943 | } |
| 4944 | |
| 4945 | case SUBMODULE_UMBRELLA_DIR: { |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 4946 | std::string Dirname = Blob; |
| 4947 | ResolveImportedPath(F, Dirname); |
| 4948 | if (auto *Umbrella = PP.getFileManager().getDirectory(Dirname)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4949 | if (!CurrentModule->getUmbrellaDir()) |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 4950 | ModMap.setUmbrellaDir(CurrentModule, Umbrella, Blob); |
| 4951 | else if (CurrentModule->getUmbrellaDir().Entry != Umbrella) { |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4952 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 4953 | Error("mismatched umbrella directories in submodule"); |
| 4954 | return OutOfDate; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4955 | } |
| 4956 | } |
| 4957 | break; |
| 4958 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4959 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4960 | case SUBMODULE_METADATA: { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4961 | F.BaseSubmoduleID = getTotalNumSubmodules(); |
| 4962 | F.LocalNumSubmodules = Record[0]; |
| 4963 | unsigned LocalBaseSubmoduleID = Record[1]; |
| 4964 | if (F.LocalNumSubmodules > 0) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4965 | // Introduce the global -> local mapping for submodules within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4966 | // module. |
| 4967 | GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4968 | |
| 4969 | // Introduce the local -> global mapping for submodules within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4970 | // module. |
| 4971 | F.SubmoduleRemap.insertOrReplace( |
| 4972 | std::make_pair(LocalBaseSubmoduleID, |
| 4973 | F.BaseSubmoduleID - LocalBaseSubmoduleID)); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 4974 | |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 4975 | SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules); |
| 4976 | } |
Richard Smith | 145e15a | 2017-04-24 23:12:30 +0000 | [diff] [blame] | 4977 | ModuleKind = (Module::ModuleKind)Record[2]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4978 | break; |
| 4979 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4980 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4981 | case SUBMODULE_IMPORTS: { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4982 | for (unsigned Idx = 0; Idx != Record.size(); ++Idx) { |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4983 | UnresolvedModuleRef Unresolved; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4984 | Unresolved.File = &F; |
| 4985 | Unresolved.Mod = CurrentModule; |
| 4986 | Unresolved.ID = Record[Idx]; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4987 | Unresolved.Kind = UnresolvedModuleRef::Import; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4988 | Unresolved.IsWildcard = false; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4989 | UnresolvedModuleRefs.push_back(Unresolved); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4990 | } |
| 4991 | break; |
| 4992 | } |
| 4993 | |
| 4994 | case SUBMODULE_EXPORTS: { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4995 | for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) { |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4996 | UnresolvedModuleRef Unresolved; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4997 | Unresolved.File = &F; |
| 4998 | Unresolved.Mod = CurrentModule; |
| 4999 | Unresolved.ID = Record[Idx]; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5000 | Unresolved.Kind = UnresolvedModuleRef::Export; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5001 | Unresolved.IsWildcard = Record[Idx + 1]; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5002 | UnresolvedModuleRefs.push_back(Unresolved); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5003 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5004 | |
| 5005 | // 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] | 5006 | // the parsed, unresolved exports around. |
| 5007 | CurrentModule->UnresolvedExports.clear(); |
| 5008 | break; |
| 5009 | } |
| 5010 | case SUBMODULE_REQUIRES: { |
Richard Smith | a3feee2 | 2013-10-28 22:18:19 +0000 | [diff] [blame] | 5011 | CurrentModule->addRequirement(Blob, Record[0], Context.getLangOpts(), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5012 | Context.getTargetInfo()); |
| 5013 | break; |
| 5014 | } |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5015 | |
| 5016 | case SUBMODULE_LINK_LIBRARY: |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5017 | CurrentModule->LinkLibraries.push_back( |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5018 | Module::LinkLibrary(Blob, Record[0])); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5019 | break; |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 5020 | |
| 5021 | case SUBMODULE_CONFIG_MACRO: |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 5022 | CurrentModule->ConfigMacros.push_back(Blob.str()); |
| 5023 | break; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5024 | |
| 5025 | case SUBMODULE_CONFLICT: { |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5026 | UnresolvedModuleRef Unresolved; |
| 5027 | Unresolved.File = &F; |
| 5028 | Unresolved.Mod = CurrentModule; |
| 5029 | Unresolved.ID = Record[0]; |
| 5030 | Unresolved.Kind = UnresolvedModuleRef::Conflict; |
| 5031 | Unresolved.IsWildcard = false; |
| 5032 | Unresolved.String = Blob; |
| 5033 | UnresolvedModuleRefs.push_back(Unresolved); |
| 5034 | break; |
| 5035 | } |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 5036 | |
| 5037 | case SUBMODULE_INITIALIZERS: |
| 5038 | SmallVector<uint32_t, 16> Inits; |
| 5039 | for (auto &ID : Record) |
| 5040 | Inits.push_back(getGlobalDeclID(F, ID)); |
| 5041 | Context.addLazyModuleInitializers(CurrentModule, Inits); |
| 5042 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5043 | } |
| 5044 | } |
| 5045 | } |
| 5046 | |
| 5047 | /// \brief Parse the record that corresponds to a LangOptions data |
| 5048 | /// structure. |
| 5049 | /// |
| 5050 | /// This routine parses the language options from the AST file and then gives |
| 5051 | /// them to the AST listener if one is set. |
| 5052 | /// |
| 5053 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
| 5054 | bool ASTReader::ParseLanguageOptions(const RecordData &Record, |
| 5055 | bool Complain, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 5056 | ASTReaderListener &Listener, |
| 5057 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5058 | LangOptions LangOpts; |
| 5059 | unsigned Idx = 0; |
| 5060 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 5061 | LangOpts.Name = Record[Idx++]; |
| 5062 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 5063 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 5064 | #include "clang/Basic/LangOptions.def" |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 5065 | #define SANITIZER(NAME, ID) \ |
| 5066 | LangOpts.Sanitize.set(SanitizerKind::ID, Record[Idx++]); |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 5067 | #include "clang/Basic/Sanitizers.def" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5068 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 5069 | for (unsigned N = Record[Idx++]; N; --N) |
| 5070 | LangOpts.ModuleFeatures.push_back(ReadString(Record, Idx)); |
| 5071 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5072 | ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++]; |
| 5073 | VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx); |
| 5074 | LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 5075 | |
Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 5076 | LangOpts.CurrentModule = ReadString(Record, Idx); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 5077 | |
| 5078 | // Comment options. |
| 5079 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5080 | LangOpts.CommentOpts.BlockCommandNames.push_back( |
| 5081 | ReadString(Record, Idx)); |
| 5082 | } |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 5083 | LangOpts.CommentOpts.ParseAllComments = Record[Idx++]; |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 5084 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 5085 | // OpenMP offloading options. |
| 5086 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5087 | LangOpts.OMPTargetTriples.push_back(llvm::Triple(ReadString(Record, Idx))); |
| 5088 | } |
| 5089 | |
| 5090 | LangOpts.OMPHostIRFile = ReadString(Record, Idx); |
| 5091 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 5092 | return Listener.ReadLanguageOptions(LangOpts, Complain, |
| 5093 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5094 | } |
| 5095 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 5096 | bool ASTReader::ParseTargetOptions(const RecordData &Record, bool Complain, |
| 5097 | ASTReaderListener &Listener, |
| 5098 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5099 | unsigned Idx = 0; |
| 5100 | TargetOptions TargetOpts; |
| 5101 | TargetOpts.Triple = ReadString(Record, Idx); |
| 5102 | TargetOpts.CPU = ReadString(Record, Idx); |
| 5103 | TargetOpts.ABI = ReadString(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5104 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5105 | TargetOpts.FeaturesAsWritten.push_back(ReadString(Record, Idx)); |
| 5106 | } |
| 5107 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5108 | TargetOpts.Features.push_back(ReadString(Record, Idx)); |
| 5109 | } |
| 5110 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 5111 | return Listener.ReadTargetOptions(TargetOpts, Complain, |
| 5112 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5113 | } |
| 5114 | |
| 5115 | bool ASTReader::ParseDiagnosticOptions(const RecordData &Record, bool Complain, |
| 5116 | ASTReaderListener &Listener) { |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5117 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5118 | unsigned Idx = 0; |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5119 | #define DIAGOPT(Name, Bits, Default) DiagOpts->Name = Record[Idx++]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5120 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5121 | DiagOpts->set##Name(static_cast<Type>(Record[Idx++])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5122 | #include "clang/Basic/DiagnosticOptions.def" |
| 5123 | |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 5124 | for (unsigned N = Record[Idx++]; N; --N) |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5125 | DiagOpts->Warnings.push_back(ReadString(Record, Idx)); |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 5126 | for (unsigned N = Record[Idx++]; N; --N) |
| 5127 | DiagOpts->Remarks.push_back(ReadString(Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5128 | |
| 5129 | return Listener.ReadDiagnosticOptions(DiagOpts, Complain); |
| 5130 | } |
| 5131 | |
| 5132 | bool ASTReader::ParseFileSystemOptions(const RecordData &Record, bool Complain, |
| 5133 | ASTReaderListener &Listener) { |
| 5134 | FileSystemOptions FSOpts; |
| 5135 | unsigned Idx = 0; |
| 5136 | FSOpts.WorkingDir = ReadString(Record, Idx); |
| 5137 | return Listener.ReadFileSystemOptions(FSOpts, Complain); |
| 5138 | } |
| 5139 | |
| 5140 | bool ASTReader::ParseHeaderSearchOptions(const RecordData &Record, |
| 5141 | bool Complain, |
| 5142 | ASTReaderListener &Listener) { |
| 5143 | HeaderSearchOptions HSOpts; |
| 5144 | unsigned Idx = 0; |
| 5145 | HSOpts.Sysroot = ReadString(Record, Idx); |
| 5146 | |
| 5147 | // Include entries. |
| 5148 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5149 | std::string Path = ReadString(Record, Idx); |
| 5150 | frontend::IncludeDirGroup Group |
| 5151 | = static_cast<frontend::IncludeDirGroup>(Record[Idx++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5152 | bool IsFramework = Record[Idx++]; |
| 5153 | bool IgnoreSysRoot = Record[Idx++]; |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 5154 | HSOpts.UserEntries.emplace_back(std::move(Path), Group, IsFramework, |
| 5155 | IgnoreSysRoot); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5156 | } |
| 5157 | |
| 5158 | // System header prefixes. |
| 5159 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5160 | std::string Prefix = ReadString(Record, Idx); |
| 5161 | bool IsSystemHeader = Record[Idx++]; |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 5162 | HSOpts.SystemHeaderPrefixes.emplace_back(std::move(Prefix), IsSystemHeader); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5163 | } |
| 5164 | |
| 5165 | HSOpts.ResourceDir = ReadString(Record, Idx); |
| 5166 | HSOpts.ModuleCachePath = ReadString(Record, Idx); |
Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 5167 | HSOpts.ModuleUserBuildPath = ReadString(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5168 | HSOpts.DisableModuleHash = Record[Idx++]; |
| 5169 | HSOpts.UseBuiltinIncludes = Record[Idx++]; |
| 5170 | HSOpts.UseStandardSystemIncludes = Record[Idx++]; |
| 5171 | HSOpts.UseStandardCXXIncludes = Record[Idx++]; |
| 5172 | HSOpts.UseLibcxx = Record[Idx++]; |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 5173 | std::string SpecificModuleCachePath = ReadString(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5174 | |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 5175 | return Listener.ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 5176 | Complain); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5177 | } |
| 5178 | |
| 5179 | bool ASTReader::ParsePreprocessorOptions(const RecordData &Record, |
| 5180 | bool Complain, |
| 5181 | ASTReaderListener &Listener, |
| 5182 | std::string &SuggestedPredefines) { |
| 5183 | PreprocessorOptions PPOpts; |
| 5184 | unsigned Idx = 0; |
| 5185 | |
| 5186 | // Macro definitions/undefs |
| 5187 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5188 | std::string Macro = ReadString(Record, Idx); |
| 5189 | bool IsUndef = Record[Idx++]; |
| 5190 | PPOpts.Macros.push_back(std::make_pair(Macro, IsUndef)); |
| 5191 | } |
| 5192 | |
| 5193 | // Includes |
| 5194 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5195 | PPOpts.Includes.push_back(ReadString(Record, Idx)); |
| 5196 | } |
| 5197 | |
| 5198 | // Macro Includes |
| 5199 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5200 | PPOpts.MacroIncludes.push_back(ReadString(Record, Idx)); |
| 5201 | } |
| 5202 | |
| 5203 | PPOpts.UsePredefines = Record[Idx++]; |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 5204 | PPOpts.DetailedRecord = Record[Idx++]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5205 | PPOpts.ImplicitPCHInclude = ReadString(Record, Idx); |
| 5206 | PPOpts.ImplicitPTHInclude = ReadString(Record, Idx); |
| 5207 | PPOpts.ObjCXXARCStandardLibrary = |
| 5208 | static_cast<ObjCXXARCStandardLibraryKind>(Record[Idx++]); |
| 5209 | SuggestedPredefines.clear(); |
| 5210 | return Listener.ReadPreprocessorOptions(PPOpts, Complain, |
| 5211 | SuggestedPredefines); |
| 5212 | } |
| 5213 | |
| 5214 | std::pair<ModuleFile *, unsigned> |
| 5215 | ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { |
| 5216 | GlobalPreprocessedEntityMapType::iterator |
| 5217 | I = GlobalPreprocessedEntityMap.find(GlobalIndex); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5218 | assert(I != GlobalPreprocessedEntityMap.end() && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5219 | "Corrupted global preprocessed entity map"); |
| 5220 | ModuleFile *M = I->second; |
| 5221 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; |
| 5222 | return std::make_pair(M, LocalIndex); |
| 5223 | } |
| 5224 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5225 | llvm::iterator_range<PreprocessingRecord::iterator> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5226 | ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const { |
| 5227 | if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord()) |
| 5228 | return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID, |
| 5229 | Mod.NumPreprocessedEntities); |
| 5230 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5231 | return llvm::make_range(PreprocessingRecord::iterator(), |
| 5232 | PreprocessingRecord::iterator()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5233 | } |
| 5234 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5235 | llvm::iterator_range<ASTReader::ModuleDeclIterator> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5236 | ASTReader::getModuleFileLevelDecls(ModuleFile &Mod) { |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5237 | return llvm::make_range( |
| 5238 | ModuleDeclIterator(this, &Mod, Mod.FileSortedDecls), |
| 5239 | ModuleDeclIterator(this, &Mod, |
| 5240 | Mod.FileSortedDecls + Mod.NumFileSortedDecls)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5241 | } |
| 5242 | |
| 5243 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { |
| 5244 | PreprocessedEntityID PPID = Index+1; |
| 5245 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 5246 | ModuleFile &M = *PPInfo.first; |
| 5247 | unsigned LocalIndex = PPInfo.second; |
| 5248 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 5249 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5250 | if (!PP.getPreprocessingRecord()) { |
| 5251 | Error("no preprocessing record"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5252 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5253 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5254 | |
| 5255 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5256 | M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset); |
| 5257 | |
| 5258 | llvm::BitstreamEntry Entry = |
| 5259 | M.PreprocessorDetailCursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd); |
| 5260 | if (Entry.Kind != llvm::BitstreamEntry::Record) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5261 | return nullptr; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5262 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5263 | // Read the record. |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 5264 | SourceRange Range(TranslateSourceLocation(M, PPOffs.getBegin()), |
| 5265 | TranslateSourceLocation(M, PPOffs.getEnd())); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5266 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5267 | StringRef Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5268 | RecordData Record; |
| 5269 | PreprocessorDetailRecordTypes RecType = |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5270 | (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.readRecord( |
| 5271 | Entry.ID, Record, &Blob); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5272 | switch (RecType) { |
| 5273 | case PPD_MACRO_EXPANSION: { |
| 5274 | bool isBuiltin = Record[0]; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5275 | IdentifierInfo *Name = nullptr; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5276 | MacroDefinitionRecord *Def = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5277 | if (isBuiltin) |
| 5278 | Name = getLocalIdentifier(M, Record[1]); |
| 5279 | else { |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5280 | PreprocessedEntityID GlobalID = |
| 5281 | getGlobalPreprocessedEntityID(M, Record[1]); |
| 5282 | Def = cast<MacroDefinitionRecord>( |
| 5283 | PPRec.getLoadedPreprocessedEntity(GlobalID - 1)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5284 | } |
| 5285 | |
| 5286 | MacroExpansion *ME; |
| 5287 | if (isBuiltin) |
| 5288 | ME = new (PPRec) MacroExpansion(Name, Range); |
| 5289 | else |
| 5290 | ME = new (PPRec) MacroExpansion(Def, Range); |
| 5291 | |
| 5292 | return ME; |
| 5293 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5294 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5295 | case PPD_MACRO_DEFINITION: { |
| 5296 | // Decode the identifier info and then check again; if the macro is |
| 5297 | // still defined and associated with the identifier, |
| 5298 | IdentifierInfo *II = getLocalIdentifier(M, Record[0]); |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5299 | MacroDefinitionRecord *MD = new (PPRec) MacroDefinitionRecord(II, Range); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5300 | |
| 5301 | if (DeserializationListener) |
| 5302 | DeserializationListener->MacroDefinitionRead(PPID, MD); |
| 5303 | |
| 5304 | return MD; |
| 5305 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5306 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5307 | case PPD_INCLUSION_DIRECTIVE: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5308 | const char *FullFileNameStart = Blob.data() + Record[0]; |
| 5309 | StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5310 | const FileEntry *File = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5311 | if (!FullFileName.empty()) |
| 5312 | File = PP.getFileManager().getFile(FullFileName); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5313 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5314 | // FIXME: Stable encoding |
| 5315 | InclusionDirective::InclusionKind Kind |
| 5316 | = static_cast<InclusionDirective::InclusionKind>(Record[2]); |
| 5317 | InclusionDirective *ID |
| 5318 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5319 | StringRef(Blob.data(), Record[0]), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5320 | Record[1], Record[3], |
| 5321 | File, |
| 5322 | Range); |
| 5323 | return ID; |
| 5324 | } |
| 5325 | } |
| 5326 | |
| 5327 | llvm_unreachable("Invalid PreprocessorDetailRecordTypes"); |
| 5328 | } |
| 5329 | |
| 5330 | /// \brief \arg SLocMapI points at a chunk of a module that contains no |
| 5331 | /// preprocessed entities or the entities it contains are not the ones we are |
| 5332 | /// looking for. Find the next module that contains entities and return the ID |
| 5333 | /// of the first entry. |
| 5334 | PreprocessedEntityID ASTReader::findNextPreprocessedEntity( |
| 5335 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const { |
| 5336 | ++SLocMapI; |
| 5337 | for (GlobalSLocOffsetMapType::const_iterator |
| 5338 | EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) { |
| 5339 | ModuleFile &M = *SLocMapI->second; |
| 5340 | if (M.NumPreprocessedEntities) |
| 5341 | return M.BasePreprocessedEntityID; |
| 5342 | } |
| 5343 | |
| 5344 | return getTotalNumPreprocessedEntities(); |
| 5345 | } |
| 5346 | |
| 5347 | namespace { |
| 5348 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5349 | struct PPEntityComp { |
| 5350 | const ASTReader &Reader; |
| 5351 | ModuleFile &M; |
| 5352 | |
| 5353 | PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) { } |
| 5354 | |
| 5355 | bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const { |
| 5356 | SourceLocation LHS = getLoc(L); |
| 5357 | SourceLocation RHS = getLoc(R); |
| 5358 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5359 | } |
| 5360 | |
| 5361 | bool operator()(const PPEntityOffset &L, SourceLocation RHS) const { |
| 5362 | SourceLocation LHS = getLoc(L); |
| 5363 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5364 | } |
| 5365 | |
| 5366 | bool operator()(SourceLocation LHS, const PPEntityOffset &R) const { |
| 5367 | SourceLocation RHS = getLoc(R); |
| 5368 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5369 | } |
| 5370 | |
| 5371 | SourceLocation getLoc(const PPEntityOffset &PPE) const { |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5372 | return Reader.TranslateSourceLocation(M, PPE.getBegin()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5373 | } |
| 5374 | }; |
| 5375 | |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5376 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5377 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5378 | PreprocessedEntityID ASTReader::findPreprocessedEntity(SourceLocation Loc, |
| 5379 | bool EndsAfter) const { |
| 5380 | if (SourceMgr.isLocalSourceLocation(Loc)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5381 | return getTotalNumPreprocessedEntities(); |
| 5382 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5383 | GlobalSLocOffsetMapType::const_iterator SLocMapI = GlobalSLocOffsetMap.find( |
| 5384 | SourceManager::MaxLoadedOffset - Loc.getOffset() - 1); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5385 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 5386 | "Corrupted global sloc offset map"); |
| 5387 | |
| 5388 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 5389 | return findNextPreprocessedEntity(SLocMapI); |
| 5390 | |
| 5391 | ModuleFile &M = *SLocMapI->second; |
| 5392 | typedef const PPEntityOffset *pp_iterator; |
| 5393 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 5394 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
| 5395 | |
| 5396 | size_t Count = M.NumPreprocessedEntities; |
| 5397 | size_t Half; |
| 5398 | pp_iterator First = pp_begin; |
| 5399 | pp_iterator PPI; |
| 5400 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5401 | if (EndsAfter) { |
| 5402 | PPI = std::upper_bound(pp_begin, pp_end, Loc, |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5403 | PPEntityComp(*this, M)); |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5404 | } else { |
| 5405 | // Do a binary search manually instead of using std::lower_bound because |
| 5406 | // The end locations of entities may be unordered (when a macro expansion |
| 5407 | // is inside another macro argument), but for this case it is not important |
| 5408 | // whether we get the first macro expansion or its containing macro. |
| 5409 | while (Count > 0) { |
| 5410 | Half = Count / 2; |
| 5411 | PPI = First; |
| 5412 | std::advance(PPI, Half); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5413 | if (SourceMgr.isBeforeInTranslationUnit( |
| 5414 | TranslateSourceLocation(M, PPI->getEnd()), Loc)) { |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5415 | First = PPI; |
| 5416 | ++First; |
| 5417 | Count = Count - Half - 1; |
| 5418 | } else |
| 5419 | Count = Half; |
| 5420 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5421 | } |
| 5422 | |
| 5423 | if (PPI == pp_end) |
| 5424 | return findNextPreprocessedEntity(SLocMapI); |
| 5425 | |
| 5426 | return M.BasePreprocessedEntityID + (PPI - pp_begin); |
| 5427 | } |
| 5428 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5429 | /// \brief Returns a pair of [Begin, End) indices of preallocated |
| 5430 | /// preprocessed entities that \arg Range encompasses. |
| 5431 | std::pair<unsigned, unsigned> |
| 5432 | ASTReader::findPreprocessedEntitiesInRange(SourceRange Range) { |
| 5433 | if (Range.isInvalid()) |
| 5434 | return std::make_pair(0,0); |
| 5435 | assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); |
| 5436 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5437 | PreprocessedEntityID BeginID = |
| 5438 | findPreprocessedEntity(Range.getBegin(), false); |
| 5439 | PreprocessedEntityID EndID = findPreprocessedEntity(Range.getEnd(), true); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5440 | return std::make_pair(BeginID, EndID); |
| 5441 | } |
| 5442 | |
| 5443 | /// \brief Optionally returns true or false if the preallocated preprocessed |
| 5444 | /// entity with index \arg Index came from file \arg FID. |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5445 | Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5446 | FileID FID) { |
| 5447 | if (FID.isInvalid()) |
| 5448 | return false; |
| 5449 | |
| 5450 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 5451 | ModuleFile &M = *PPInfo.first; |
| 5452 | unsigned LocalIndex = PPInfo.second; |
| 5453 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5454 | |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 5455 | SourceLocation Loc = TranslateSourceLocation(M, PPOffs.getBegin()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5456 | if (Loc.isInvalid()) |
| 5457 | return false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5458 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5459 | if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) |
| 5460 | return true; |
| 5461 | else |
| 5462 | return false; |
| 5463 | } |
| 5464 | |
| 5465 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5466 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5467 | /// \brief Visitor used to search for information about a header file. |
| 5468 | class HeaderFileInfoVisitor { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5469 | const FileEntry *FE; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5470 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5471 | Optional<HeaderFileInfo> HFI; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5472 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5473 | public: |
Argyrios Kyrtzidis | 61a3896 | 2013-03-06 18:12:44 +0000 | [diff] [blame] | 5474 | explicit HeaderFileInfoVisitor(const FileEntry *FE) |
| 5475 | : FE(FE) { } |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 5476 | |
| 5477 | bool operator()(ModuleFile &M) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5478 | HeaderFileInfoLookupTable *Table |
| 5479 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 5480 | if (!Table) |
| 5481 | return false; |
| 5482 | |
| 5483 | // 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] | 5484 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5485 | if (Pos == Table->end()) |
| 5486 | return false; |
| 5487 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 5488 | HFI = *Pos; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5489 | return true; |
| 5490 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5491 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5492 | Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5493 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5494 | |
| 5495 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5496 | |
| 5497 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Argyrios Kyrtzidis | 61a3896 | 2013-03-06 18:12:44 +0000 | [diff] [blame] | 5498 | HeaderFileInfoVisitor Visitor(FE); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 5499 | ModuleMgr.visit(Visitor); |
Argyrios Kyrtzidis | 1054bbf | 2013-05-08 23:46:55 +0000 | [diff] [blame] | 5500 | if (Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5501 | return *HFI; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5502 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5503 | return HeaderFileInfo(); |
| 5504 | } |
| 5505 | |
| 5506 | void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5507 | using DiagState = DiagnosticsEngine::DiagState; |
| 5508 | SmallVector<DiagState *, 32> DiagStates; |
| 5509 | |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 5510 | for (ModuleFile &F : ModuleMgr) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5511 | unsigned Idx = 0; |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5512 | auto &Record = F.PragmaDiagMappings; |
| 5513 | if (Record.empty()) |
| 5514 | continue; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5515 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5516 | DiagStates.clear(); |
| 5517 | |
| 5518 | auto ReadDiagState = |
| 5519 | [&](const DiagState &BasedOn, SourceLocation Loc, |
| 5520 | bool IncludeNonPragmaStates) -> DiagnosticsEngine::DiagState * { |
| 5521 | unsigned BackrefID = Record[Idx++]; |
| 5522 | if (BackrefID != 0) |
| 5523 | return DiagStates[BackrefID - 1]; |
| 5524 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5525 | // A new DiagState was created here. |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5526 | Diag.DiagStates.push_back(BasedOn); |
| 5527 | DiagState *NewState = &Diag.DiagStates.back(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5528 | DiagStates.push_back(NewState); |
Duncan P. N. Exon Smith | 3cb183b | 2017-03-14 19:31:27 +0000 | [diff] [blame] | 5529 | unsigned Size = Record[Idx++]; |
| 5530 | assert(Idx + Size * 2 <= Record.size() && |
| 5531 | "Invalid data, not enough diag/map pairs"); |
| 5532 | while (Size--) { |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5533 | unsigned DiagID = Record[Idx++]; |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5534 | unsigned SeverityAndUpgradedFromWarning = Record[Idx++]; |
| 5535 | bool WasUpgradedFromWarning = |
| 5536 | DiagnosticMapping::deserializeUpgradedFromWarning( |
| 5537 | SeverityAndUpgradedFromWarning); |
| 5538 | DiagnosticMapping NewMapping = |
| 5539 | Diag.makeUserMapping(DiagnosticMapping::deserializeSeverity( |
| 5540 | SeverityAndUpgradedFromWarning), |
| 5541 | Loc); |
| 5542 | if (!NewMapping.isPragma() && !IncludeNonPragmaStates) |
| 5543 | continue; |
| 5544 | |
| 5545 | DiagnosticMapping &Mapping = NewState->getOrAddMapping(DiagID); |
| 5546 | |
| 5547 | // If this mapping was specified as a warning but the severity was |
| 5548 | // upgraded due to diagnostic settings, simulate the current diagnostic |
| 5549 | // settings (and use a warning). |
| 5550 | if (WasUpgradedFromWarning && !Mapping.isErrorOrFatal()) { |
| 5551 | Mapping = Diag.makeUserMapping(diag::Severity::Warning, Loc); |
| 5552 | continue; |
| 5553 | } |
| 5554 | |
| 5555 | // Use the deserialized mapping verbatim. |
| 5556 | Mapping = NewMapping; |
| 5557 | Mapping.setUpgradedFromWarning(WasUpgradedFromWarning); |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5558 | } |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5559 | return NewState; |
| 5560 | }; |
| 5561 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5562 | // Read the first state. |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5563 | DiagState *FirstState; |
| 5564 | if (F.Kind == MK_ImplicitModule) { |
| 5565 | // Implicitly-built modules are reused with different diagnostic |
| 5566 | // settings. Use the initial diagnostic state from Diag to simulate this |
| 5567 | // compilation's diagnostic settings. |
| 5568 | FirstState = Diag.DiagStatesByLoc.FirstDiagState; |
| 5569 | DiagStates.push_back(FirstState); |
| 5570 | |
| 5571 | // Skip the initial diagnostic state from the serialized module. |
| 5572 | assert(Record[0] == 0 && |
| 5573 | "Invalid data, unexpected backref in initial state"); |
| 5574 | Idx = 2 + Record[1] * 2; |
| 5575 | assert(Idx < Record.size() && |
| 5576 | "Invalid data, not enough state change pairs in initial state"); |
| 5577 | } else { |
| 5578 | FirstState = ReadDiagState( |
| 5579 | F.isModule() ? DiagState() : *Diag.DiagStatesByLoc.CurDiagState, |
| 5580 | SourceLocation(), F.isModule()); |
Richard Smith | ea74148 | 2017-05-01 22:10:47 +0000 | [diff] [blame^] | 5581 | |
| 5582 | // For an explicit module, set up the root buffer of the module to start |
| 5583 | // with the initial diagnostic state of the module itself, to cover files |
| 5584 | // that contain no explicit transitions. |
| 5585 | if (F.isModule()) |
| 5586 | Diag.DiagStatesByLoc.Files[F.OriginalSourceFileID] |
| 5587 | .StateTransitions.push_back({FirstState, 0}); |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5588 | } |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5589 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5590 | // Read the state transitions. |
| 5591 | unsigned NumLocations = Record[Idx++]; |
| 5592 | while (NumLocations--) { |
| 5593 | assert(Idx < Record.size() && |
| 5594 | "Invalid data, missing pragma diagnostic states"); |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5595 | SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]); |
| 5596 | auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc); |
| 5597 | assert(IDAndOffset.second == 0 && "not a start location for a FileID"); |
| 5598 | unsigned Transitions = Record[Idx++]; |
| 5599 | |
| 5600 | // Note that we don't need to set up Parent/ParentOffset here, because |
| 5601 | // we won't be changing the diagnostic state within imported FileIDs |
| 5602 | // (other than perhaps appending to the main source file, which has no |
| 5603 | // parent). |
| 5604 | auto &F = Diag.DiagStatesByLoc.Files[IDAndOffset.first]; |
| 5605 | F.StateTransitions.reserve(F.StateTransitions.size() + Transitions); |
| 5606 | for (unsigned I = 0; I != Transitions; ++I) { |
| 5607 | unsigned Offset = Record[Idx++]; |
| 5608 | auto *State = |
| 5609 | ReadDiagState(*FirstState, Loc.getLocWithOffset(Offset), false); |
| 5610 | F.StateTransitions.push_back({State, Offset}); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5611 | } |
| 5612 | } |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5613 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5614 | // Read the final state. |
| 5615 | assert(Idx < Record.size() && |
| 5616 | "Invalid data, missing final pragma diagnostic state"); |
| 5617 | SourceLocation CurStateLoc = |
| 5618 | ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
| 5619 | auto *CurState = ReadDiagState(*FirstState, CurStateLoc, false); |
| 5620 | |
| 5621 | if (!F.isModule()) { |
| 5622 | Diag.DiagStatesByLoc.CurDiagState = CurState; |
| 5623 | Diag.DiagStatesByLoc.CurDiagStateLoc = CurStateLoc; |
| 5624 | |
| 5625 | // Preserve the property that the imaginary root file describes the |
| 5626 | // current state. |
| 5627 | auto &T = Diag.DiagStatesByLoc.Files[FileID()].StateTransitions; |
| 5628 | if (T.empty()) |
| 5629 | T.push_back({CurState, 0}); |
| 5630 | else |
| 5631 | T[0].State = CurState; |
| 5632 | } |
| 5633 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5634 | // Don't try to read these mappings again. |
| 5635 | Record.clear(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5636 | } |
| 5637 | } |
| 5638 | |
| 5639 | /// \brief Get the correct cursor and offset for loading a type. |
| 5640 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
| 5641 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
| 5642 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
| 5643 | ModuleFile *M = I->second; |
| 5644 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
| 5645 | } |
| 5646 | |
| 5647 | /// \brief Read and return the type with the given index.. |
| 5648 | /// |
| 5649 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 5650 | /// routine actually reads the record corresponding to the type at the given |
| 5651 | /// location. It is a helper routine for GetType, which deals with reading type |
| 5652 | /// IDs. |
| 5653 | QualType ASTReader::readTypeRecord(unsigned Index) { |
| 5654 | RecordLocation Loc = TypeCursorForIndex(Index); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5655 | BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5656 | |
| 5657 | // Keep track of where we are in the stream, then jump back there |
| 5658 | // after reading this type. |
| 5659 | SavedStreamPosition SavedPosition(DeclsCursor); |
| 5660 | |
| 5661 | ReadingKindTracker ReadingKind(Read_Type, *this); |
| 5662 | |
| 5663 | // Note that we are loading a type record. |
| 5664 | Deserializing AType(this); |
| 5665 | |
| 5666 | unsigned Idx = 0; |
| 5667 | DeclsCursor.JumpToBit(Loc.Offset); |
| 5668 | RecordData Record; |
| 5669 | unsigned Code = DeclsCursor.ReadCode(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5670 | switch ((TypeCode)DeclsCursor.readRecord(Code, Record)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5671 | case TYPE_EXT_QUAL: { |
| 5672 | if (Record.size() != 2) { |
| 5673 | Error("Incorrect encoding of extended qualifier type"); |
| 5674 | return QualType(); |
| 5675 | } |
| 5676 | QualType Base = readType(*Loc.F, Record, Idx); |
| 5677 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
| 5678 | return Context.getQualifiedType(Base, Quals); |
| 5679 | } |
| 5680 | |
| 5681 | case TYPE_COMPLEX: { |
| 5682 | if (Record.size() != 1) { |
| 5683 | Error("Incorrect encoding of complex type"); |
| 5684 | return QualType(); |
| 5685 | } |
| 5686 | QualType ElemType = readType(*Loc.F, Record, Idx); |
| 5687 | return Context.getComplexType(ElemType); |
| 5688 | } |
| 5689 | |
| 5690 | case TYPE_POINTER: { |
| 5691 | if (Record.size() != 1) { |
| 5692 | Error("Incorrect encoding of pointer type"); |
| 5693 | return QualType(); |
| 5694 | } |
| 5695 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5696 | return Context.getPointerType(PointeeType); |
| 5697 | } |
| 5698 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 5699 | case TYPE_DECAYED: { |
| 5700 | if (Record.size() != 1) { |
| 5701 | Error("Incorrect encoding of decayed type"); |
| 5702 | return QualType(); |
| 5703 | } |
| 5704 | QualType OriginalType = readType(*Loc.F, Record, Idx); |
| 5705 | QualType DT = Context.getAdjustedParameterType(OriginalType); |
| 5706 | if (!isa<DecayedType>(DT)) |
| 5707 | Error("Decayed type does not decay"); |
| 5708 | return DT; |
| 5709 | } |
| 5710 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 5711 | case TYPE_ADJUSTED: { |
| 5712 | if (Record.size() != 2) { |
| 5713 | Error("Incorrect encoding of adjusted type"); |
| 5714 | return QualType(); |
| 5715 | } |
| 5716 | QualType OriginalTy = readType(*Loc.F, Record, Idx); |
| 5717 | QualType AdjustedTy = readType(*Loc.F, Record, Idx); |
| 5718 | return Context.getAdjustedType(OriginalTy, AdjustedTy); |
| 5719 | } |
| 5720 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5721 | case TYPE_BLOCK_POINTER: { |
| 5722 | if (Record.size() != 1) { |
| 5723 | Error("Incorrect encoding of block pointer type"); |
| 5724 | return QualType(); |
| 5725 | } |
| 5726 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5727 | return Context.getBlockPointerType(PointeeType); |
| 5728 | } |
| 5729 | |
| 5730 | case TYPE_LVALUE_REFERENCE: { |
| 5731 | if (Record.size() != 2) { |
| 5732 | Error("Incorrect encoding of lvalue reference type"); |
| 5733 | return QualType(); |
| 5734 | } |
| 5735 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5736 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
| 5737 | } |
| 5738 | |
| 5739 | case TYPE_RVALUE_REFERENCE: { |
| 5740 | if (Record.size() != 1) { |
| 5741 | Error("Incorrect encoding of rvalue reference type"); |
| 5742 | return QualType(); |
| 5743 | } |
| 5744 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5745 | return Context.getRValueReferenceType(PointeeType); |
| 5746 | } |
| 5747 | |
| 5748 | case TYPE_MEMBER_POINTER: { |
| 5749 | if (Record.size() != 2) { |
| 5750 | Error("Incorrect encoding of member pointer type"); |
| 5751 | return QualType(); |
| 5752 | } |
| 5753 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5754 | QualType ClassType = readType(*Loc.F, Record, Idx); |
| 5755 | if (PointeeType.isNull() || ClassType.isNull()) |
| 5756 | return QualType(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5757 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5758 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
| 5759 | } |
| 5760 | |
| 5761 | case TYPE_CONSTANT_ARRAY: { |
| 5762 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5763 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 5764 | unsigned IndexTypeQuals = Record[2]; |
| 5765 | unsigned Idx = 3; |
| 5766 | llvm::APInt Size = ReadAPInt(Record, Idx); |
| 5767 | return Context.getConstantArrayType(ElementType, Size, |
| 5768 | ASM, IndexTypeQuals); |
| 5769 | } |
| 5770 | |
| 5771 | case TYPE_INCOMPLETE_ARRAY: { |
| 5772 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5773 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 5774 | unsigned IndexTypeQuals = Record[2]; |
| 5775 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
| 5776 | } |
| 5777 | |
| 5778 | case TYPE_VARIABLE_ARRAY: { |
| 5779 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5780 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 5781 | unsigned IndexTypeQuals = Record[2]; |
| 5782 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 5783 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 5784 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
| 5785 | ASM, IndexTypeQuals, |
| 5786 | SourceRange(LBLoc, RBLoc)); |
| 5787 | } |
| 5788 | |
| 5789 | case TYPE_VECTOR: { |
| 5790 | if (Record.size() != 3) { |
| 5791 | Error("incorrect encoding of vector type in AST file"); |
| 5792 | return QualType(); |
| 5793 | } |
| 5794 | |
| 5795 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5796 | unsigned NumElements = Record[1]; |
| 5797 | unsigned VecKind = Record[2]; |
| 5798 | return Context.getVectorType(ElementType, NumElements, |
| 5799 | (VectorType::VectorKind)VecKind); |
| 5800 | } |
| 5801 | |
| 5802 | case TYPE_EXT_VECTOR: { |
| 5803 | if (Record.size() != 3) { |
| 5804 | Error("incorrect encoding of extended vector type in AST file"); |
| 5805 | return QualType(); |
| 5806 | } |
| 5807 | |
| 5808 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5809 | unsigned NumElements = Record[1]; |
| 5810 | return Context.getExtVectorType(ElementType, NumElements); |
| 5811 | } |
| 5812 | |
| 5813 | case TYPE_FUNCTION_NO_PROTO: { |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5814 | if (Record.size() != 7) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5815 | Error("incorrect encoding of no-proto function type"); |
| 5816 | return QualType(); |
| 5817 | } |
| 5818 | QualType ResultType = readType(*Loc.F, Record, Idx); |
| 5819 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5820 | (CallingConv)Record[4], Record[5], Record[6]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5821 | return Context.getFunctionNoProtoType(ResultType, Info); |
| 5822 | } |
| 5823 | |
| 5824 | case TYPE_FUNCTION_PROTO: { |
| 5825 | QualType ResultType = readType(*Loc.F, Record, Idx); |
| 5826 | |
| 5827 | FunctionProtoType::ExtProtoInfo EPI; |
| 5828 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
| 5829 | /*hasregparm*/ Record[2], |
| 5830 | /*regparm*/ Record[3], |
| 5831 | static_cast<CallingConv>(Record[4]), |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5832 | /*produces*/ Record[5], |
| 5833 | /*nocallersavedregs*/ Record[6]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5834 | |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5835 | unsigned Idx = 7; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5836 | |
| 5837 | EPI.Variadic = Record[Idx++]; |
| 5838 | EPI.HasTrailingReturn = Record[Idx++]; |
| 5839 | EPI.TypeQuals = Record[Idx++]; |
| 5840 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5841 | SmallVector<QualType, 8> ExceptionStorage; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 5842 | readExceptionSpec(*Loc.F, ExceptionStorage, EPI.ExceptionSpec, Record, Idx); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 5843 | |
| 5844 | unsigned NumParams = Record[Idx++]; |
| 5845 | SmallVector<QualType, 16> ParamTypes; |
| 5846 | for (unsigned I = 0; I != NumParams; ++I) |
| 5847 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
| 5848 | |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 5849 | SmallVector<FunctionProtoType::ExtParameterInfo, 4> ExtParameterInfos; |
| 5850 | if (Idx != Record.size()) { |
| 5851 | for (unsigned I = 0; I != NumParams; ++I) |
| 5852 | ExtParameterInfos.push_back( |
| 5853 | FunctionProtoType::ExtParameterInfo |
| 5854 | ::getFromOpaqueValue(Record[Idx++])); |
| 5855 | EPI.ExtParameterInfos = ExtParameterInfos.data(); |
| 5856 | } |
| 5857 | |
| 5858 | assert(Idx == Record.size()); |
| 5859 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 5860 | return Context.getFunctionType(ResultType, ParamTypes, EPI); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5861 | } |
| 5862 | |
| 5863 | case TYPE_UNRESOLVED_USING: { |
| 5864 | unsigned Idx = 0; |
| 5865 | return Context.getTypeDeclType( |
| 5866 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 5867 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5868 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5869 | case TYPE_TYPEDEF: { |
| 5870 | if (Record.size() != 2) { |
| 5871 | Error("incorrect encoding of typedef type"); |
| 5872 | return QualType(); |
| 5873 | } |
| 5874 | unsigned Idx = 0; |
| 5875 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
| 5876 | QualType Canonical = readType(*Loc.F, Record, Idx); |
| 5877 | if (!Canonical.isNull()) |
| 5878 | Canonical = Context.getCanonicalType(Canonical); |
| 5879 | return Context.getTypedefType(Decl, Canonical); |
| 5880 | } |
| 5881 | |
| 5882 | case TYPE_TYPEOF_EXPR: |
| 5883 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
| 5884 | |
| 5885 | case TYPE_TYPEOF: { |
| 5886 | if (Record.size() != 1) { |
| 5887 | Error("incorrect encoding of typeof(type) in AST file"); |
| 5888 | return QualType(); |
| 5889 | } |
| 5890 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 5891 | return Context.getTypeOfType(UnderlyingType); |
| 5892 | } |
| 5893 | |
| 5894 | case TYPE_DECLTYPE: { |
| 5895 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 5896 | return Context.getDecltypeType(ReadExpr(*Loc.F), UnderlyingType); |
| 5897 | } |
| 5898 | |
| 5899 | case TYPE_UNARY_TRANSFORM: { |
| 5900 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 5901 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 5902 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
| 5903 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
| 5904 | } |
| 5905 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 5906 | case TYPE_AUTO: { |
| 5907 | QualType Deduced = readType(*Loc.F, Record, Idx); |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 5908 | AutoTypeKeyword Keyword = (AutoTypeKeyword)Record[Idx++]; |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 5909 | bool IsDependent = Deduced.isNull() ? Record[Idx++] : false; |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 5910 | return Context.getAutoType(Deduced, Keyword, IsDependent); |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 5911 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5912 | |
Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 5913 | case TYPE_DEDUCED_TEMPLATE_SPECIALIZATION: { |
| 5914 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
| 5915 | QualType Deduced = readType(*Loc.F, Record, Idx); |
| 5916 | bool IsDependent = Deduced.isNull() ? Record[Idx++] : false; |
| 5917 | return Context.getDeducedTemplateSpecializationType(Name, Deduced, |
| 5918 | IsDependent); |
| 5919 | } |
| 5920 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5921 | case TYPE_RECORD: { |
| 5922 | if (Record.size() != 2) { |
| 5923 | Error("incorrect encoding of record type"); |
| 5924 | return QualType(); |
| 5925 | } |
| 5926 | unsigned Idx = 0; |
| 5927 | bool IsDependent = Record[Idx++]; |
| 5928 | RecordDecl *RD = ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx); |
| 5929 | RD = cast_or_null<RecordDecl>(RD->getCanonicalDecl()); |
| 5930 | QualType T = Context.getRecordType(RD); |
| 5931 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 5932 | return T; |
| 5933 | } |
| 5934 | |
| 5935 | case TYPE_ENUM: { |
| 5936 | if (Record.size() != 2) { |
| 5937 | Error("incorrect encoding of enum type"); |
| 5938 | return QualType(); |
| 5939 | } |
| 5940 | unsigned Idx = 0; |
| 5941 | bool IsDependent = Record[Idx++]; |
| 5942 | QualType T |
| 5943 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
| 5944 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 5945 | return T; |
| 5946 | } |
| 5947 | |
| 5948 | case TYPE_ATTRIBUTED: { |
| 5949 | if (Record.size() != 3) { |
| 5950 | Error("incorrect encoding of attributed type"); |
| 5951 | return QualType(); |
| 5952 | } |
| 5953 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 5954 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
| 5955 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 5956 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
| 5957 | } |
| 5958 | |
| 5959 | case TYPE_PAREN: { |
| 5960 | if (Record.size() != 1) { |
| 5961 | Error("incorrect encoding of paren type"); |
| 5962 | return QualType(); |
| 5963 | } |
| 5964 | QualType InnerType = readType(*Loc.F, Record, Idx); |
| 5965 | return Context.getParenType(InnerType); |
| 5966 | } |
| 5967 | |
| 5968 | case TYPE_PACK_EXPANSION: { |
| 5969 | if (Record.size() != 2) { |
| 5970 | Error("incorrect encoding of pack expansion type"); |
| 5971 | return QualType(); |
| 5972 | } |
| 5973 | QualType Pattern = readType(*Loc.F, Record, Idx); |
| 5974 | if (Pattern.isNull()) |
| 5975 | return QualType(); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5976 | Optional<unsigned> NumExpansions; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5977 | if (Record[1]) |
| 5978 | NumExpansions = Record[1] - 1; |
| 5979 | return Context.getPackExpansionType(Pattern, NumExpansions); |
| 5980 | } |
| 5981 | |
| 5982 | case TYPE_ELABORATED: { |
| 5983 | unsigned Idx = 0; |
| 5984 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 5985 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
| 5986 | QualType NamedType = readType(*Loc.F, Record, Idx); |
| 5987 | return Context.getElaboratedType(Keyword, NNS, NamedType); |
| 5988 | } |
| 5989 | |
| 5990 | case TYPE_OBJC_INTERFACE: { |
| 5991 | unsigned Idx = 0; |
| 5992 | ObjCInterfaceDecl *ItfD |
| 5993 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
| 5994 | return Context.getObjCInterfaceType(ItfD->getCanonicalDecl()); |
| 5995 | } |
| 5996 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 5997 | case TYPE_OBJC_TYPE_PARAM: { |
| 5998 | unsigned Idx = 0; |
| 5999 | ObjCTypeParamDecl *Decl |
| 6000 | = ReadDeclAs<ObjCTypeParamDecl>(*Loc.F, Record, Idx); |
| 6001 | unsigned NumProtos = Record[Idx++]; |
| 6002 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 6003 | for (unsigned I = 0; I != NumProtos; ++I) |
| 6004 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
| 6005 | return Context.getObjCTypeParamType(Decl, Protos); |
| 6006 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6007 | case TYPE_OBJC_OBJECT: { |
| 6008 | unsigned Idx = 0; |
| 6009 | QualType Base = readType(*Loc.F, Record, Idx); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6010 | unsigned NumTypeArgs = Record[Idx++]; |
| 6011 | SmallVector<QualType, 4> TypeArgs; |
| 6012 | for (unsigned I = 0; I != NumTypeArgs; ++I) |
| 6013 | TypeArgs.push_back(readType(*Loc.F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6014 | unsigned NumProtos = Record[Idx++]; |
| 6015 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 6016 | for (unsigned I = 0; I != NumProtos; ++I) |
| 6017 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 6018 | bool IsKindOf = Record[Idx++]; |
| 6019 | return Context.getObjCObjectType(Base, TypeArgs, Protos, IsKindOf); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | case TYPE_OBJC_OBJECT_POINTER: { |
| 6023 | unsigned Idx = 0; |
| 6024 | QualType Pointee = readType(*Loc.F, Record, Idx); |
| 6025 | return Context.getObjCObjectPointerType(Pointee); |
| 6026 | } |
| 6027 | |
| 6028 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
| 6029 | unsigned Idx = 0; |
| 6030 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 6031 | QualType Replacement = readType(*Loc.F, Record, Idx); |
Stephan Tolksdorf | e96f8b3 | 2014-03-15 10:23:27 +0000 | [diff] [blame] | 6032 | return Context.getSubstTemplateTypeParmType( |
| 6033 | cast<TemplateTypeParmType>(Parm), |
| 6034 | Context.getCanonicalType(Replacement)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6035 | } |
| 6036 | |
| 6037 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 6038 | unsigned Idx = 0; |
| 6039 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 6040 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 6041 | return Context.getSubstTemplateTypeParmPackType( |
| 6042 | cast<TemplateTypeParmType>(Parm), |
| 6043 | ArgPack); |
| 6044 | } |
| 6045 | |
| 6046 | case TYPE_INJECTED_CLASS_NAME: { |
| 6047 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
| 6048 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
| 6049 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
| 6050 | // for AST reading, too much interdependencies. |
Richard Smith | 6377f8f | 2014-10-21 21:15:18 +0000 | [diff] [blame] | 6051 | const Type *T = nullptr; |
| 6052 | for (auto *DI = D; DI; DI = DI->getPreviousDecl()) { |
| 6053 | if (const Type *Existing = DI->getTypeForDecl()) { |
| 6054 | T = Existing; |
| 6055 | break; |
| 6056 | } |
| 6057 | } |
| 6058 | if (!T) { |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 6059 | T = new (Context, TypeAlignment) InjectedClassNameType(D, TST); |
Richard Smith | 6377f8f | 2014-10-21 21:15:18 +0000 | [diff] [blame] | 6060 | for (auto *DI = D; DI; DI = DI->getPreviousDecl()) |
| 6061 | DI->setTypeForDecl(T); |
| 6062 | } |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 6063 | return QualType(T, 0); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6064 | } |
| 6065 | |
| 6066 | case TYPE_TEMPLATE_TYPE_PARM: { |
| 6067 | unsigned Idx = 0; |
| 6068 | unsigned Depth = Record[Idx++]; |
| 6069 | unsigned Index = Record[Idx++]; |
| 6070 | bool Pack = Record[Idx++]; |
| 6071 | TemplateTypeParmDecl *D |
| 6072 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
| 6073 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
| 6074 | } |
| 6075 | |
| 6076 | case TYPE_DEPENDENT_NAME: { |
| 6077 | unsigned Idx = 0; |
| 6078 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 6079 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 6080 | const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6081 | QualType Canon = readType(*Loc.F, Record, Idx); |
| 6082 | if (!Canon.isNull()) |
| 6083 | Canon = Context.getCanonicalType(Canon); |
| 6084 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
| 6085 | } |
| 6086 | |
| 6087 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
| 6088 | unsigned Idx = 0; |
| 6089 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 6090 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 6091 | const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6092 | unsigned NumArgs = Record[Idx++]; |
| 6093 | SmallVector<TemplateArgument, 8> Args; |
| 6094 | Args.reserve(NumArgs); |
| 6095 | while (NumArgs--) |
| 6096 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
| 6097 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 6098 | Args); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6099 | } |
| 6100 | |
| 6101 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
| 6102 | unsigned Idx = 0; |
| 6103 | |
| 6104 | // ArrayType |
| 6105 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 6106 | ArrayType::ArraySizeModifier ASM |
| 6107 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 6108 | unsigned IndexTypeQuals = Record[Idx++]; |
| 6109 | |
| 6110 | // DependentSizedArrayType |
| 6111 | Expr *NumElts = ReadExpr(*Loc.F); |
| 6112 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
| 6113 | |
| 6114 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 6115 | IndexTypeQuals, Brackets); |
| 6116 | } |
| 6117 | |
| 6118 | case TYPE_TEMPLATE_SPECIALIZATION: { |
| 6119 | unsigned Idx = 0; |
| 6120 | bool IsDependent = Record[Idx++]; |
| 6121 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
| 6122 | SmallVector<TemplateArgument, 8> Args; |
| 6123 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
| 6124 | QualType Underlying = readType(*Loc.F, Record, Idx); |
| 6125 | QualType T; |
| 6126 | if (Underlying.isNull()) |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 6127 | T = Context.getCanonicalTemplateSpecializationType(Name, Args); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6128 | else |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 6129 | T = Context.getTemplateSpecializationType(Name, Args, Underlying); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6130 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 6131 | return T; |
| 6132 | } |
| 6133 | |
| 6134 | case TYPE_ATOMIC: { |
| 6135 | if (Record.size() != 1) { |
| 6136 | Error("Incorrect encoding of atomic type"); |
| 6137 | return QualType(); |
| 6138 | } |
| 6139 | QualType ValueType = readType(*Loc.F, Record, Idx); |
| 6140 | return Context.getAtomicType(ValueType); |
| 6141 | } |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6142 | |
Joey Gouly | e3c85de | 2016-12-01 11:30:49 +0000 | [diff] [blame] | 6143 | case TYPE_PIPE: { |
| 6144 | if (Record.size() != 2) { |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6145 | Error("Incorrect encoding of pipe type"); |
| 6146 | return QualType(); |
| 6147 | } |
| 6148 | |
| 6149 | // Reading the pipe element type. |
| 6150 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Joey Gouly | e3c85de | 2016-12-01 11:30:49 +0000 | [diff] [blame] | 6151 | unsigned ReadOnly = Record[1]; |
| 6152 | return Context.getPipeType(ElementType, ReadOnly); |
Joey Gouly | 5788b78 | 2016-11-18 14:10:54 +0000 | [diff] [blame] | 6153 | } |
| 6154 | |
Alex Lorenz | 00aee43 | 2017-03-22 10:04:48 +0000 | [diff] [blame] | 6155 | case TYPE_DEPENDENT_SIZED_EXT_VECTOR: { |
| 6156 | unsigned Idx = 0; |
| 6157 | |
| 6158 | // DependentSizedExtVectorType |
| 6159 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 6160 | Expr *SizeExpr = ReadExpr(*Loc.F); |
| 6161 | SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx); |
| 6162 | |
| 6163 | return Context.getDependentSizedExtVectorType(ElementType, SizeExpr, |
| 6164 | AttrLoc); |
| 6165 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6166 | } |
| 6167 | llvm_unreachable("Invalid TypeCode!"); |
| 6168 | } |
| 6169 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6170 | void ASTReader::readExceptionSpec(ModuleFile &ModuleFile, |
| 6171 | SmallVectorImpl<QualType> &Exceptions, |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6172 | FunctionProtoType::ExceptionSpecInfo &ESI, |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6173 | const RecordData &Record, unsigned &Idx) { |
| 6174 | ExceptionSpecificationType EST = |
| 6175 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6176 | ESI.Type = EST; |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6177 | if (EST == EST_Dynamic) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6178 | for (unsigned I = 0, N = Record[Idx++]; I != N; ++I) |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6179 | Exceptions.push_back(readType(ModuleFile, Record, Idx)); |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6180 | ESI.Exceptions = Exceptions; |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6181 | } else if (EST == EST_ComputedNoexcept) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6182 | ESI.NoexceptExpr = ReadExpr(ModuleFile); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6183 | } else if (EST == EST_Uninstantiated) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6184 | ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
| 6185 | ESI.SourceTemplate = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6186 | } else if (EST == EST_Unevaluated) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6187 | ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6188 | } |
| 6189 | } |
| 6190 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6191 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6192 | ModuleFile *F; |
| 6193 | ASTReader *Reader; |
| 6194 | const ASTReader::RecordData &Record; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6195 | unsigned &Idx; |
| 6196 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6197 | SourceLocation ReadSourceLocation() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6198 | return Reader->ReadSourceLocation(*F, Record, Idx); |
| 6199 | } |
| 6200 | |
| 6201 | TypeSourceInfo *GetTypeSourceInfo() { |
| 6202 | return Reader->GetTypeSourceInfo(*F, Record, Idx); |
| 6203 | } |
| 6204 | |
| 6205 | NestedNameSpecifierLoc ReadNestedNameSpecifierLoc() { |
| 6206 | return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6207 | } |
| 6208 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6209 | public: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6210 | TypeLocReader(ModuleFile &F, ASTReader &Reader, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6211 | const ASTReader::RecordData &Record, unsigned &Idx) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6212 | : F(&F), Reader(&Reader), Record(Record), Idx(Idx) {} |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6213 | |
| 6214 | // We want compile-time assurance that we've enumerated all of |
| 6215 | // these, so unfortunately we have to declare them first, then |
| 6216 | // define them out-of-line. |
| 6217 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 6218 | #define TYPELOC(CLASS, PARENT) \ |
| 6219 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
| 6220 | #include "clang/AST/TypeLocNodes.def" |
| 6221 | |
| 6222 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 6223 | void VisitArrayTypeLoc(ArrayTypeLoc); |
| 6224 | }; |
| 6225 | |
| 6226 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 6227 | // nothing to do |
| 6228 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6229 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6230 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6231 | TL.setBuiltinLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6232 | if (TL.needsExtraLocalData()) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6233 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 6234 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 6235 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 6236 | TL.setModeAttr(Record[Idx++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6237 | } |
| 6238 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6239 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6240 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6241 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6242 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6243 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6244 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6245 | TL.setStarLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6246 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6247 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 6248 | void TypeLocReader::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 6249 | // nothing to do |
| 6250 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6251 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 6252 | void TypeLocReader::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 6253 | // nothing to do |
| 6254 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6255 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6256 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6257 | TL.setCaretLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6258 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6259 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6260 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6261 | TL.setAmpLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6262 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6263 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6264 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6265 | TL.setAmpAmpLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6266 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6267 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6268 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6269 | TL.setStarLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6270 | TL.setClassTInfo(GetTypeSourceInfo()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6271 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6272 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6273 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6274 | TL.setLBracketLoc(ReadSourceLocation()); |
| 6275 | TL.setRBracketLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6276 | if (Record[Idx++]) |
| 6277 | TL.setSizeExpr(Reader->ReadExpr(*F)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6278 | else |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6279 | TL.setSizeExpr(nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6280 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6281 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6282 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 6283 | VisitArrayTypeLoc(TL); |
| 6284 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6285 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6286 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 6287 | VisitArrayTypeLoc(TL); |
| 6288 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6289 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6290 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 6291 | VisitArrayTypeLoc(TL); |
| 6292 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6293 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6294 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 6295 | DependentSizedArrayTypeLoc TL) { |
| 6296 | VisitArrayTypeLoc(TL); |
| 6297 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6298 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6299 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 6300 | DependentSizedExtVectorTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6301 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6302 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6303 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6304 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6305 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6306 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6307 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6308 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6309 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6310 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6311 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6312 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6313 | TL.setLocalRangeBegin(ReadSourceLocation()); |
| 6314 | TL.setLParenLoc(ReadSourceLocation()); |
| 6315 | TL.setRParenLoc(ReadSourceLocation()); |
Malcolm Parsons | a3220ce | 2017-01-12 16:11:28 +0000 | [diff] [blame] | 6316 | TL.setExceptionSpecRange(SourceRange(Reader->ReadSourceLocation(*F, Record, Idx), |
| 6317 | Reader->ReadSourceLocation(*F, Record, Idx))); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6318 | TL.setLocalRangeEnd(ReadSourceLocation()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 6319 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6320 | TL.setParam(i, Reader->ReadDeclAs<ParmVarDecl>(*F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6321 | } |
| 6322 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6323 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6324 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 6325 | VisitFunctionTypeLoc(TL); |
| 6326 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6327 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6328 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 6329 | VisitFunctionTypeLoc(TL); |
| 6330 | } |
| 6331 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6332 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6333 | } |
| 6334 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6335 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6336 | } |
| 6337 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6338 | TL.setTypeofLoc(ReadSourceLocation()); |
| 6339 | TL.setLParenLoc(ReadSourceLocation()); |
| 6340 | TL.setRParenLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6341 | } |
| 6342 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6343 | TL.setTypeofLoc(ReadSourceLocation()); |
| 6344 | TL.setLParenLoc(ReadSourceLocation()); |
| 6345 | TL.setRParenLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6346 | TL.setUnderlyingTInfo(GetTypeSourceInfo()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6347 | } |
| 6348 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6349 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6350 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6351 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6352 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6353 | TL.setKWLoc(ReadSourceLocation()); |
| 6354 | TL.setLParenLoc(ReadSourceLocation()); |
| 6355 | TL.setRParenLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6356 | TL.setUnderlyingTInfo(GetTypeSourceInfo()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6357 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6358 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6359 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6360 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6361 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6362 | |
Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 6363 | void TypeLocReader::VisitDeducedTemplateSpecializationTypeLoc( |
| 6364 | DeducedTemplateSpecializationTypeLoc TL) { |
| 6365 | TL.setTemplateNameLoc(ReadSourceLocation()); |
| 6366 | } |
| 6367 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6368 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6369 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6370 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6371 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6372 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6373 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6374 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6375 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6376 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6377 | TL.setAttrNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6378 | if (TL.hasAttrOperand()) { |
| 6379 | SourceRange range; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6380 | range.setBegin(ReadSourceLocation()); |
| 6381 | range.setEnd(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6382 | TL.setAttrOperandParensRange(range); |
| 6383 | } |
| 6384 | if (TL.hasAttrExprOperand()) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6385 | if (Record[Idx++]) |
| 6386 | TL.setAttrExprOperand(Reader->ReadExpr(*F)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6387 | else |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6388 | TL.setAttrExprOperand(nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6389 | } else if (TL.hasAttrEnumOperand()) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6390 | TL.setAttrEnumOperandLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6391 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6392 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6393 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6394 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6395 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6396 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6397 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 6398 | SubstTemplateTypeParmTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6399 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6400 | } |
| 6401 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 6402 | SubstTemplateTypeParmPackTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6403 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6404 | } |
| 6405 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 6406 | TemplateSpecializationTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6407 | TL.setTemplateKeywordLoc(ReadSourceLocation()); |
| 6408 | TL.setTemplateNameLoc(ReadSourceLocation()); |
| 6409 | TL.setLAngleLoc(ReadSourceLocation()); |
| 6410 | TL.setRAngleLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6411 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6412 | TL.setArgLocInfo( |
| 6413 | i, |
| 6414 | Reader->GetTemplateArgumentLocInfo( |
| 6415 | *F, TL.getTypePtr()->getArg(i).getKind(), Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6416 | } |
| 6417 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6418 | TL.setLParenLoc(ReadSourceLocation()); |
| 6419 | TL.setRParenLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6420 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6421 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6422 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6423 | TL.setElaboratedKeywordLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6424 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6425 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6426 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6427 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6428 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6429 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6430 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6431 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6432 | TL.setElaboratedKeywordLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6433 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6434 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6435 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6436 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6437 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 6438 | DependentTemplateSpecializationTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6439 | TL.setElaboratedKeywordLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6440 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6441 | TL.setTemplateKeywordLoc(ReadSourceLocation()); |
| 6442 | TL.setTemplateNameLoc(ReadSourceLocation()); |
| 6443 | TL.setLAngleLoc(ReadSourceLocation()); |
| 6444 | TL.setRAngleLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6445 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6446 | TL.setArgLocInfo( |
| 6447 | I, |
| 6448 | Reader->GetTemplateArgumentLocInfo( |
| 6449 | *F, TL.getTypePtr()->getArg(I).getKind(), Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6450 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6451 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6452 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6453 | TL.setEllipsisLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6454 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6455 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6456 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6457 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6458 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6459 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6460 | void TypeLocReader::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { |
| 6461 | if (TL.getNumProtocols()) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6462 | TL.setProtocolLAngleLoc(ReadSourceLocation()); |
| 6463 | TL.setProtocolRAngleLoc(ReadSourceLocation()); |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6464 | } |
| 6465 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6466 | TL.setProtocolLoc(i, ReadSourceLocation()); |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6467 | } |
| 6468 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6469 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6470 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6471 | TL.setTypeArgsLAngleLoc(ReadSourceLocation()); |
| 6472 | TL.setTypeArgsRAngleLoc(ReadSourceLocation()); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6473 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6474 | TL.setTypeArgTInfo(i, GetTypeSourceInfo()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6475 | TL.setProtocolLAngleLoc(ReadSourceLocation()); |
| 6476 | TL.setProtocolRAngleLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6477 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6478 | TL.setProtocolLoc(i, ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6479 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6480 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6481 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6482 | TL.setStarLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6483 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6484 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6485 | void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6486 | TL.setKWLoc(ReadSourceLocation()); |
| 6487 | TL.setLParenLoc(ReadSourceLocation()); |
| 6488 | TL.setRParenLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6489 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6490 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6491 | void TypeLocReader::VisitPipeTypeLoc(PipeTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6492 | TL.setKWLoc(ReadSourceLocation()); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6493 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6494 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6495 | TypeSourceInfo * |
| 6496 | ASTReader::GetTypeSourceInfo(ModuleFile &F, const ASTReader::RecordData &Record, |
| 6497 | unsigned &Idx) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6498 | QualType InfoTy = readType(F, Record, Idx); |
| 6499 | if (InfoTy.isNull()) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6500 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6501 | |
| 6502 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6503 | TypeLocReader TLR(F, *this, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6504 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
| 6505 | TLR.Visit(TL); |
| 6506 | return TInfo; |
| 6507 | } |
| 6508 | |
| 6509 | QualType ASTReader::GetType(TypeID ID) { |
| 6510 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 6511 | unsigned Index = ID >> Qualifiers::FastWidth; |
| 6512 | |
| 6513 | if (Index < NUM_PREDEF_TYPE_IDS) { |
| 6514 | QualType T; |
| 6515 | switch ((PredefinedTypeIDs)Index) { |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6516 | case PREDEF_TYPE_NULL_ID: |
| 6517 | return QualType(); |
| 6518 | case PREDEF_TYPE_VOID_ID: |
| 6519 | T = Context.VoidTy; |
| 6520 | break; |
| 6521 | case PREDEF_TYPE_BOOL_ID: |
| 6522 | T = Context.BoolTy; |
| 6523 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6524 | |
| 6525 | case PREDEF_TYPE_CHAR_U_ID: |
| 6526 | case PREDEF_TYPE_CHAR_S_ID: |
| 6527 | // FIXME: Check that the signedness of CharTy is correct! |
| 6528 | T = Context.CharTy; |
| 6529 | break; |
| 6530 | |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6531 | case PREDEF_TYPE_UCHAR_ID: |
| 6532 | T = Context.UnsignedCharTy; |
| 6533 | break; |
| 6534 | case PREDEF_TYPE_USHORT_ID: |
| 6535 | T = Context.UnsignedShortTy; |
| 6536 | break; |
| 6537 | case PREDEF_TYPE_UINT_ID: |
| 6538 | T = Context.UnsignedIntTy; |
| 6539 | break; |
| 6540 | case PREDEF_TYPE_ULONG_ID: |
| 6541 | T = Context.UnsignedLongTy; |
| 6542 | break; |
| 6543 | case PREDEF_TYPE_ULONGLONG_ID: |
| 6544 | T = Context.UnsignedLongLongTy; |
| 6545 | break; |
| 6546 | case PREDEF_TYPE_UINT128_ID: |
| 6547 | T = Context.UnsignedInt128Ty; |
| 6548 | break; |
| 6549 | case PREDEF_TYPE_SCHAR_ID: |
| 6550 | T = Context.SignedCharTy; |
| 6551 | break; |
| 6552 | case PREDEF_TYPE_WCHAR_ID: |
| 6553 | T = Context.WCharTy; |
| 6554 | break; |
| 6555 | case PREDEF_TYPE_SHORT_ID: |
| 6556 | T = Context.ShortTy; |
| 6557 | break; |
| 6558 | case PREDEF_TYPE_INT_ID: |
| 6559 | T = Context.IntTy; |
| 6560 | break; |
| 6561 | case PREDEF_TYPE_LONG_ID: |
| 6562 | T = Context.LongTy; |
| 6563 | break; |
| 6564 | case PREDEF_TYPE_LONGLONG_ID: |
| 6565 | T = Context.LongLongTy; |
| 6566 | break; |
| 6567 | case PREDEF_TYPE_INT128_ID: |
| 6568 | T = Context.Int128Ty; |
| 6569 | break; |
| 6570 | case PREDEF_TYPE_HALF_ID: |
| 6571 | T = Context.HalfTy; |
| 6572 | break; |
| 6573 | case PREDEF_TYPE_FLOAT_ID: |
| 6574 | T = Context.FloatTy; |
| 6575 | break; |
| 6576 | case PREDEF_TYPE_DOUBLE_ID: |
| 6577 | T = Context.DoubleTy; |
| 6578 | break; |
| 6579 | case PREDEF_TYPE_LONGDOUBLE_ID: |
| 6580 | T = Context.LongDoubleTy; |
| 6581 | break; |
Nemanja Ivanovic | bb1ea2d | 2016-05-09 08:52:33 +0000 | [diff] [blame] | 6582 | case PREDEF_TYPE_FLOAT128_ID: |
| 6583 | T = Context.Float128Ty; |
| 6584 | break; |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6585 | case PREDEF_TYPE_OVERLOAD_ID: |
| 6586 | T = Context.OverloadTy; |
| 6587 | break; |
| 6588 | case PREDEF_TYPE_BOUND_MEMBER: |
| 6589 | T = Context.BoundMemberTy; |
| 6590 | break; |
| 6591 | case PREDEF_TYPE_PSEUDO_OBJECT: |
| 6592 | T = Context.PseudoObjectTy; |
| 6593 | break; |
| 6594 | case PREDEF_TYPE_DEPENDENT_ID: |
| 6595 | T = Context.DependentTy; |
| 6596 | break; |
| 6597 | case PREDEF_TYPE_UNKNOWN_ANY: |
| 6598 | T = Context.UnknownAnyTy; |
| 6599 | break; |
| 6600 | case PREDEF_TYPE_NULLPTR_ID: |
| 6601 | T = Context.NullPtrTy; |
| 6602 | break; |
| 6603 | case PREDEF_TYPE_CHAR16_ID: |
| 6604 | T = Context.Char16Ty; |
| 6605 | break; |
| 6606 | case PREDEF_TYPE_CHAR32_ID: |
| 6607 | T = Context.Char32Ty; |
| 6608 | break; |
| 6609 | case PREDEF_TYPE_OBJC_ID: |
| 6610 | T = Context.ObjCBuiltinIdTy; |
| 6611 | break; |
| 6612 | case PREDEF_TYPE_OBJC_CLASS: |
| 6613 | T = Context.ObjCBuiltinClassTy; |
| 6614 | break; |
| 6615 | case PREDEF_TYPE_OBJC_SEL: |
| 6616 | T = Context.ObjCBuiltinSelTy; |
| 6617 | break; |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 6618 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 6619 | case PREDEF_TYPE_##Id##_ID: \ |
| 6620 | T = Context.SingletonId; \ |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6621 | break; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 6622 | #include "clang/Basic/OpenCLImageTypes.def" |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6623 | case PREDEF_TYPE_SAMPLER_ID: |
| 6624 | T = Context.OCLSamplerTy; |
| 6625 | break; |
| 6626 | case PREDEF_TYPE_EVENT_ID: |
| 6627 | T = Context.OCLEventTy; |
| 6628 | break; |
Alexey Bader | 9c8453f | 2015-09-15 11:18:52 +0000 | [diff] [blame] | 6629 | case PREDEF_TYPE_CLK_EVENT_ID: |
| 6630 | T = Context.OCLClkEventTy; |
| 6631 | break; |
| 6632 | case PREDEF_TYPE_QUEUE_ID: |
| 6633 | T = Context.OCLQueueTy; |
| 6634 | break; |
Alexey Bader | 9c8453f | 2015-09-15 11:18:52 +0000 | [diff] [blame] | 6635 | case PREDEF_TYPE_RESERVE_ID_ID: |
| 6636 | T = Context.OCLReserveIDTy; |
| 6637 | break; |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6638 | case PREDEF_TYPE_AUTO_DEDUCT: |
| 6639 | T = Context.getAutoDeductType(); |
| 6640 | break; |
| 6641 | |
| 6642 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
| 6643 | T = Context.getAutoRRefDeductType(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6644 | break; |
| 6645 | |
| 6646 | case PREDEF_TYPE_ARC_UNBRIDGED_CAST: |
| 6647 | T = Context.ARCUnbridgedCastTy; |
| 6648 | break; |
| 6649 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6650 | case PREDEF_TYPE_BUILTIN_FN: |
| 6651 | T = Context.BuiltinFnTy; |
| 6652 | break; |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 6653 | |
| 6654 | case PREDEF_TYPE_OMP_ARRAY_SECTION: |
| 6655 | T = Context.OMPArraySectionTy; |
| 6656 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6657 | } |
| 6658 | |
| 6659 | assert(!T.isNull() && "Unknown predefined type"); |
| 6660 | return T.withFastQualifiers(FastQuals); |
| 6661 | } |
| 6662 | |
| 6663 | Index -= NUM_PREDEF_TYPE_IDS; |
| 6664 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
| 6665 | if (TypesLoaded[Index].isNull()) { |
| 6666 | TypesLoaded[Index] = readTypeRecord(Index); |
| 6667 | if (TypesLoaded[Index].isNull()) |
| 6668 | return QualType(); |
| 6669 | |
| 6670 | TypesLoaded[Index]->setFromAST(); |
| 6671 | if (DeserializationListener) |
| 6672 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
| 6673 | TypesLoaded[Index]); |
| 6674 | } |
| 6675 | |
| 6676 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
| 6677 | } |
| 6678 | |
| 6679 | QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) { |
| 6680 | return GetType(getGlobalTypeID(F, LocalID)); |
| 6681 | } |
| 6682 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6683 | serialization::TypeID |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6684 | ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const { |
| 6685 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 6686 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6687 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6688 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 6689 | return LocalID; |
| 6690 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 6691 | if (!F.ModuleOffsetMap.empty()) |
| 6692 | ReadModuleOffsetMap(F); |
| 6693 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6694 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6695 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 6696 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6697 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6698 | unsigned GlobalIndex = LocalIndex + I->second; |
| 6699 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 6700 | } |
| 6701 | |
| 6702 | TemplateArgumentLocInfo |
| 6703 | ASTReader::GetTemplateArgumentLocInfo(ModuleFile &F, |
| 6704 | TemplateArgument::ArgKind Kind, |
| 6705 | const RecordData &Record, |
| 6706 | unsigned &Index) { |
| 6707 | switch (Kind) { |
| 6708 | case TemplateArgument::Expression: |
| 6709 | return ReadExpr(F); |
| 6710 | case TemplateArgument::Type: |
| 6711 | return GetTypeSourceInfo(F, Record, Index); |
| 6712 | case TemplateArgument::Template: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6713 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6714 | Index); |
| 6715 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
| 6716 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
| 6717 | SourceLocation()); |
| 6718 | } |
| 6719 | case TemplateArgument::TemplateExpansion: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6720 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6721 | Index); |
| 6722 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
| 6723 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6724 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6725 | EllipsisLoc); |
| 6726 | } |
| 6727 | case TemplateArgument::Null: |
| 6728 | case TemplateArgument::Integral: |
| 6729 | case TemplateArgument::Declaration: |
| 6730 | case TemplateArgument::NullPtr: |
| 6731 | case TemplateArgument::Pack: |
| 6732 | // FIXME: Is this right? |
| 6733 | return TemplateArgumentLocInfo(); |
| 6734 | } |
| 6735 | llvm_unreachable("unexpected template argument loc"); |
| 6736 | } |
| 6737 | |
| 6738 | TemplateArgumentLoc |
| 6739 | ASTReader::ReadTemplateArgumentLoc(ModuleFile &F, |
| 6740 | const RecordData &Record, unsigned &Index) { |
| 6741 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
| 6742 | |
| 6743 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 6744 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 6745 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 6746 | } |
| 6747 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
| 6748 | Record, Index)); |
| 6749 | } |
| 6750 | |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 6751 | const ASTTemplateArgumentListInfo* |
| 6752 | ASTReader::ReadASTTemplateArgumentListInfo(ModuleFile &F, |
| 6753 | const RecordData &Record, |
| 6754 | unsigned &Index) { |
| 6755 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Index); |
| 6756 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Index); |
| 6757 | unsigned NumArgsAsWritten = Record[Index++]; |
| 6758 | TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); |
| 6759 | for (unsigned i = 0; i != NumArgsAsWritten; ++i) |
| 6760 | TemplArgsInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Index)); |
| 6761 | return ASTTemplateArgumentListInfo::Create(getContext(), TemplArgsInfo); |
| 6762 | } |
| 6763 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6764 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
| 6765 | return GetDecl(ID); |
| 6766 | } |
| 6767 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6768 | void ASTReader::CompleteRedeclChain(const Decl *D) { |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 6769 | if (NumCurrentElementsDeserializing) { |
| 6770 | // We arrange to not care about the complete redeclaration chain while we're |
| 6771 | // deserializing. Just remember that the AST has marked this one as complete |
| 6772 | // but that it's not actually complete yet, so we know we still need to |
| 6773 | // complete it later. |
| 6774 | PendingIncompleteDeclChains.push_back(const_cast<Decl*>(D)); |
| 6775 | return; |
| 6776 | } |
| 6777 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6778 | const DeclContext *DC = D->getDeclContext()->getRedeclContext(); |
| 6779 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6780 | // If this is a named declaration, complete it by looking it up |
| 6781 | // within its context. |
| 6782 | // |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 6783 | // FIXME: Merging a function definition should merge |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6784 | // all mergeable entities within it. |
| 6785 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC) || |
| 6786 | isa<CXXRecordDecl>(DC) || isa<EnumDecl>(DC)) { |
| 6787 | if (DeclarationName Name = cast<NamedDecl>(D)->getDeclName()) { |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 6788 | if (!getContext().getLangOpts().CPlusPlus && |
| 6789 | isa<TranslationUnitDecl>(DC)) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6790 | // 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] | 6791 | // the identifier instead. (For C++ modules, we don't store decls |
| 6792 | // in the serialized identifier table, so we do the lookup in the TU.) |
| 6793 | auto *II = Name.getAsIdentifierInfo(); |
| 6794 | assert(II && "non-identifier name in C?"); |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6795 | if (II->isOutOfDate()) |
| 6796 | updateOutOfDateIdentifier(*II); |
| 6797 | } else |
| 6798 | DC->lookup(Name); |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 6799 | } else if (needsAnonymousDeclarationNumber(cast<NamedDecl>(D))) { |
Richard Smith | 3cb1572 | 2015-08-05 22:41:45 +0000 | [diff] [blame] | 6800 | // Find all declarations of this kind from the relevant context. |
| 6801 | for (auto *DCDecl : cast<Decl>(D->getLexicalDeclContext())->redecls()) { |
| 6802 | auto *DC = cast<DeclContext>(DCDecl); |
| 6803 | SmallVector<Decl*, 8> Decls; |
| 6804 | FindExternalLexicalDecls( |
| 6805 | DC, [&](Decl::Kind K) { return K == D->getKind(); }, Decls); |
| 6806 | } |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6807 | } |
| 6808 | } |
Richard Smith | 5089542 | 2015-01-31 03:04:55 +0000 | [diff] [blame] | 6809 | |
| 6810 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D)) |
| 6811 | CTSD->getSpecializedTemplate()->LoadLazySpecializations(); |
| 6812 | if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) |
| 6813 | VTSD->getSpecializedTemplate()->LoadLazySpecializations(); |
| 6814 | if (auto *FD = dyn_cast<FunctionDecl>(D)) { |
| 6815 | if (auto *Template = FD->getPrimaryTemplate()) |
| 6816 | Template->LoadLazySpecializations(); |
| 6817 | } |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6818 | } |
| 6819 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 6820 | CXXCtorInitializer ** |
| 6821 | ASTReader::GetExternalCXXCtorInitializers(uint64_t Offset) { |
| 6822 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 6823 | BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
| 6824 | SavedStreamPosition SavedPosition(Cursor); |
| 6825 | Cursor.JumpToBit(Loc.Offset); |
| 6826 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 6827 | |
| 6828 | RecordData Record; |
| 6829 | unsigned Code = Cursor.ReadCode(); |
| 6830 | unsigned RecCode = Cursor.readRecord(Code, Record); |
| 6831 | if (RecCode != DECL_CXX_CTOR_INITIALIZERS) { |
| 6832 | Error("malformed AST file: missing C++ ctor initializers"); |
| 6833 | return nullptr; |
| 6834 | } |
| 6835 | |
| 6836 | unsigned Idx = 0; |
| 6837 | return ReadCXXCtorInitializers(*Loc.F, Record, Idx); |
| 6838 | } |
| 6839 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6840 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| 6841 | RecordLocation Loc = getLocalBitOffset(Offset); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 6842 | BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6843 | SavedStreamPosition SavedPosition(Cursor); |
| 6844 | Cursor.JumpToBit(Loc.Offset); |
| 6845 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 6846 | RecordData Record; |
| 6847 | unsigned Code = Cursor.ReadCode(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 6848 | unsigned RecCode = Cursor.readRecord(Code, Record); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6849 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6850 | Error("malformed AST file: missing C++ base specifiers"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6851 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6852 | } |
| 6853 | |
| 6854 | unsigned Idx = 0; |
| 6855 | unsigned NumBases = Record[Idx++]; |
| 6856 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 6857 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 6858 | for (unsigned I = 0; I != NumBases; ++I) |
| 6859 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
| 6860 | return Bases; |
| 6861 | } |
| 6862 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6863 | serialization::DeclID |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6864 | ASTReader::getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const { |
| 6865 | if (LocalID < NUM_PREDEF_DECL_IDS) |
| 6866 | return LocalID; |
| 6867 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 6868 | if (!F.ModuleOffsetMap.empty()) |
| 6869 | ReadModuleOffsetMap(F); |
| 6870 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6871 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6872 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
| 6873 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6874 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6875 | return LocalID + I->second; |
| 6876 | } |
| 6877 | |
| 6878 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
| 6879 | ModuleFile &M) const { |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 6880 | // Predefined decls aren't from any module. |
| 6881 | if (ID < NUM_PREDEF_DECL_IDS) |
| 6882 | return false; |
| 6883 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6884 | return ID - NUM_PREDEF_DECL_IDS >= M.BaseDeclID && |
Richard Smith | bcda1a9 | 2015-07-12 23:51:20 +0000 | [diff] [blame] | 6885 | ID - NUM_PREDEF_DECL_IDS < M.BaseDeclID + M.LocalNumDecls; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6886 | } |
| 6887 | |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 6888 | ModuleFile *ASTReader::getOwningModuleFile(const Decl *D) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6889 | if (!D->isFromASTFile()) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6890 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6891 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID()); |
| 6892 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 6893 | return I->second; |
| 6894 | } |
| 6895 | |
| 6896 | SourceLocation ASTReader::getSourceLocationForDeclID(GlobalDeclID ID) { |
| 6897 | if (ID < NUM_PREDEF_DECL_IDS) |
| 6898 | return SourceLocation(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6899 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6900 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 6901 | |
| 6902 | if (Index > DeclsLoaded.size()) { |
| 6903 | Error("declaration ID out-of-range for AST file"); |
| 6904 | return SourceLocation(); |
| 6905 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6906 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6907 | if (Decl *D = DeclsLoaded[Index]) |
| 6908 | return D->getLocation(); |
| 6909 | |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 6910 | SourceLocation Loc; |
| 6911 | DeclCursorForID(ID, Loc); |
| 6912 | return Loc; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6913 | } |
| 6914 | |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 6915 | static Decl *getPredefinedDecl(ASTContext &Context, PredefinedDeclIDs ID) { |
| 6916 | switch (ID) { |
| 6917 | case PREDEF_DECL_NULL_ID: |
| 6918 | return nullptr; |
| 6919 | |
| 6920 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
| 6921 | return Context.getTranslationUnitDecl(); |
| 6922 | |
| 6923 | case PREDEF_DECL_OBJC_ID_ID: |
| 6924 | return Context.getObjCIdDecl(); |
| 6925 | |
| 6926 | case PREDEF_DECL_OBJC_SEL_ID: |
| 6927 | return Context.getObjCSelDecl(); |
| 6928 | |
| 6929 | case PREDEF_DECL_OBJC_CLASS_ID: |
| 6930 | return Context.getObjCClassDecl(); |
| 6931 | |
| 6932 | case PREDEF_DECL_OBJC_PROTOCOL_ID: |
| 6933 | return Context.getObjCProtocolDecl(); |
| 6934 | |
| 6935 | case PREDEF_DECL_INT_128_ID: |
| 6936 | return Context.getInt128Decl(); |
| 6937 | |
| 6938 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
| 6939 | return Context.getUInt128Decl(); |
| 6940 | |
| 6941 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
| 6942 | return Context.getObjCInstanceTypeDecl(); |
| 6943 | |
| 6944 | case PREDEF_DECL_BUILTIN_VA_LIST_ID: |
| 6945 | return Context.getBuiltinVaListDecl(); |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 6946 | |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 6947 | case PREDEF_DECL_VA_LIST_TAG: |
| 6948 | return Context.getVaListTagDecl(); |
| 6949 | |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 6950 | case PREDEF_DECL_BUILTIN_MS_VA_LIST_ID: |
| 6951 | return Context.getBuiltinMSVaListDecl(); |
| 6952 | |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 6953 | case PREDEF_DECL_EXTERN_C_CONTEXT_ID: |
| 6954 | return Context.getExternCContextDecl(); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 6955 | |
| 6956 | case PREDEF_DECL_MAKE_INTEGER_SEQ_ID: |
| 6957 | return Context.getMakeIntegerSeqDecl(); |
Quentin Colombet | 043406b | 2016-02-03 22:41:00 +0000 | [diff] [blame] | 6958 | |
| 6959 | case PREDEF_DECL_CF_CONSTANT_STRING_ID: |
| 6960 | return Context.getCFConstantStringDecl(); |
Ben Langmuir | f541674 | 2016-02-04 00:55:24 +0000 | [diff] [blame] | 6961 | |
| 6962 | case PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID: |
| 6963 | return Context.getCFConstantStringTagDecl(); |
Eric Fiselier | 6ad6855 | 2016-07-01 01:24:09 +0000 | [diff] [blame] | 6964 | |
| 6965 | case PREDEF_DECL_TYPE_PACK_ELEMENT_ID: |
| 6966 | return Context.getTypePackElementDecl(); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 6967 | } |
Yaron Keren | 322bdad | 2015-03-06 07:49:14 +0000 | [diff] [blame] | 6968 | llvm_unreachable("PredefinedDeclIDs unknown enum value"); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 6969 | } |
| 6970 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6971 | Decl *ASTReader::GetExistingDecl(DeclID ID) { |
| 6972 | if (ID < NUM_PREDEF_DECL_IDS) { |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 6973 | Decl *D = getPredefinedDecl(Context, (PredefinedDeclIDs)ID); |
| 6974 | if (D) { |
| 6975 | // Track that we have merged the declaration with ID \p ID into the |
| 6976 | // pre-existing predefined declaration \p D. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 6977 | auto &Merged = KeyDecls[D->getCanonicalDecl()]; |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 6978 | if (Merged.empty()) |
| 6979 | Merged.push_back(ID); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6980 | } |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 6981 | return D; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6982 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6983 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6984 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 6985 | |
| 6986 | if (Index >= DeclsLoaded.size()) { |
| 6987 | assert(0 && "declaration ID out-of-range for AST file"); |
| 6988 | Error("declaration ID out-of-range for AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6989 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6990 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6991 | |
| 6992 | return DeclsLoaded[Index]; |
| 6993 | } |
| 6994 | |
| 6995 | Decl *ASTReader::GetDecl(DeclID ID) { |
| 6996 | if (ID < NUM_PREDEF_DECL_IDS) |
| 6997 | return GetExistingDecl(ID); |
| 6998 | |
| 6999 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 7000 | |
| 7001 | if (Index >= DeclsLoaded.size()) { |
| 7002 | assert(0 && "declaration ID out-of-range for AST file"); |
| 7003 | Error("declaration ID out-of-range for AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7004 | return nullptr; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7005 | } |
| 7006 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7007 | if (!DeclsLoaded[Index]) { |
| 7008 | ReadDeclRecord(ID); |
| 7009 | if (DeserializationListener) |
| 7010 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 7011 | } |
| 7012 | |
| 7013 | return DeclsLoaded[Index]; |
| 7014 | } |
| 7015 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7016 | DeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile &M, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7017 | DeclID GlobalID) { |
| 7018 | if (GlobalID < NUM_PREDEF_DECL_IDS) |
| 7019 | return GlobalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7020 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7021 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID); |
| 7022 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 7023 | ModuleFile *Owner = I->second; |
| 7024 | |
| 7025 | llvm::DenseMap<ModuleFile *, serialization::DeclID>::iterator Pos |
| 7026 | = M.GlobalToLocalDeclIDs.find(Owner); |
| 7027 | if (Pos == M.GlobalToLocalDeclIDs.end()) |
| 7028 | return 0; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7029 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7030 | return GlobalID - Owner->BaseDeclID + Pos->second; |
| 7031 | } |
| 7032 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7033 | serialization::DeclID ASTReader::ReadDeclID(ModuleFile &F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7034 | const RecordData &Record, |
| 7035 | unsigned &Idx) { |
| 7036 | if (Idx >= Record.size()) { |
| 7037 | Error("Corrupted AST file"); |
| 7038 | return 0; |
| 7039 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7040 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7041 | return getGlobalDeclID(F, Record[Idx++]); |
| 7042 | } |
| 7043 | |
| 7044 | /// \brief Resolve the offset of a statement into a statement. |
| 7045 | /// |
| 7046 | /// This operation will read a new statement from the external |
| 7047 | /// source each time it is called, and is meant to be used via a |
| 7048 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
| 7049 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
| 7050 | // Switch case IDs are per Decl. |
| 7051 | ClearSwitchCaseIDs(); |
| 7052 | |
| 7053 | // Offset here is a global offset across the entire chain. |
| 7054 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 7055 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
David Blaikie | 9fd16f8 | 2017-03-08 23:57:08 +0000 | [diff] [blame] | 7056 | assert(NumCurrentElementsDeserializing == 0 && |
| 7057 | "should not be called while already deserializing"); |
| 7058 | Deserializing D(this); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7059 | return ReadStmtFromStream(*Loc.F); |
| 7060 | } |
| 7061 | |
Richard Smith | 3cb1572 | 2015-08-05 22:41:45 +0000 | [diff] [blame] | 7062 | void ASTReader::FindExternalLexicalDecls( |
| 7063 | const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, |
| 7064 | SmallVectorImpl<Decl *> &Decls) { |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7065 | bool PredefsVisited[NUM_PREDEF_DECL_IDS] = {}; |
| 7066 | |
Richard Smith | 9ccdd93 | 2015-08-06 22:14:12 +0000 | [diff] [blame] | 7067 | auto Visit = [&] (ModuleFile *M, LexicalContents LexicalDecls) { |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7068 | assert(LexicalDecls.size() % 2 == 0 && "expected an even number of entries"); |
| 7069 | for (int I = 0, N = LexicalDecls.size(); I != N; I += 2) { |
| 7070 | auto K = (Decl::Kind)+LexicalDecls[I]; |
| 7071 | if (!IsKindWeWant(K)) |
| 7072 | continue; |
| 7073 | |
| 7074 | auto ID = (serialization::DeclID)+LexicalDecls[I + 1]; |
| 7075 | |
| 7076 | // Don't add predefined declarations to the lexical context more |
| 7077 | // than once. |
| 7078 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 7079 | if (PredefsVisited[ID]) |
| 7080 | continue; |
| 7081 | |
| 7082 | PredefsVisited[ID] = true; |
| 7083 | } |
| 7084 | |
| 7085 | if (Decl *D = GetLocalDecl(*M, ID)) { |
Richard Smith | 2317a3e | 2015-08-11 21:21:20 +0000 | [diff] [blame] | 7086 | assert(D->getKind() == K && "wrong kind for lexical decl"); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7087 | if (!DC->isDeclInLexicalTraversal(D)) |
| 7088 | Decls.push_back(D); |
| 7089 | } |
| 7090 | } |
| 7091 | }; |
| 7092 | |
| 7093 | if (isa<TranslationUnitDecl>(DC)) { |
| 7094 | for (auto Lexical : TULexicalDecls) |
| 7095 | Visit(Lexical.first, Lexical.second); |
| 7096 | } else { |
| 7097 | auto I = LexicalDecls.find(DC); |
| 7098 | if (I != LexicalDecls.end()) |
Richard Smith | 9c9173d | 2015-08-11 22:00:24 +0000 | [diff] [blame] | 7099 | Visit(I->second.first, I->second.second); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7100 | } |
| 7101 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7102 | ++NumLexicalDeclContextsRead; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7103 | } |
| 7104 | |
| 7105 | namespace { |
| 7106 | |
| 7107 | class DeclIDComp { |
| 7108 | ASTReader &Reader; |
| 7109 | ModuleFile &Mod; |
| 7110 | |
| 7111 | public: |
| 7112 | DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {} |
| 7113 | |
| 7114 | bool operator()(LocalDeclID L, LocalDeclID R) const { |
| 7115 | SourceLocation LHS = getLocation(L); |
| 7116 | SourceLocation RHS = getLocation(R); |
| 7117 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7118 | } |
| 7119 | |
| 7120 | bool operator()(SourceLocation LHS, LocalDeclID R) const { |
| 7121 | SourceLocation RHS = getLocation(R); |
| 7122 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7123 | } |
| 7124 | |
| 7125 | bool operator()(LocalDeclID L, SourceLocation RHS) const { |
| 7126 | SourceLocation LHS = getLocation(L); |
| 7127 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7128 | } |
| 7129 | |
| 7130 | SourceLocation getLocation(LocalDeclID ID) const { |
| 7131 | return Reader.getSourceManager().getFileLoc( |
| 7132 | Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID))); |
| 7133 | } |
| 7134 | }; |
| 7135 | |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7136 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7137 | |
| 7138 | void ASTReader::FindFileRegionDecls(FileID File, |
| 7139 | unsigned Offset, unsigned Length, |
| 7140 | SmallVectorImpl<Decl *> &Decls) { |
| 7141 | SourceManager &SM = getSourceManager(); |
| 7142 | |
| 7143 | llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File); |
| 7144 | if (I == FileDeclIDs.end()) |
| 7145 | return; |
| 7146 | |
| 7147 | FileDeclsInfo &DInfo = I->second; |
| 7148 | if (DInfo.Decls.empty()) |
| 7149 | return; |
| 7150 | |
| 7151 | SourceLocation |
| 7152 | BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset); |
| 7153 | SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length); |
| 7154 | |
| 7155 | DeclIDComp DIDComp(*this, *DInfo.Mod); |
| 7156 | ArrayRef<serialization::LocalDeclID>::iterator |
| 7157 | BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 7158 | BeginLoc, DIDComp); |
| 7159 | if (BeginIt != DInfo.Decls.begin()) |
| 7160 | --BeginIt; |
| 7161 | |
| 7162 | // If we are pointing at a top-level decl inside an objc container, we need |
| 7163 | // to backtrack until we find it otherwise we will fail to report that the |
| 7164 | // region overlaps with an objc container. |
| 7165 | while (BeginIt != DInfo.Decls.begin() && |
| 7166 | GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt)) |
| 7167 | ->isTopLevelDeclInObjCContainer()) |
| 7168 | --BeginIt; |
| 7169 | |
| 7170 | ArrayRef<serialization::LocalDeclID>::iterator |
| 7171 | EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 7172 | EndLoc, DIDComp); |
| 7173 | if (EndIt != DInfo.Decls.end()) |
| 7174 | ++EndIt; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7175 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7176 | for (ArrayRef<serialization::LocalDeclID>::iterator |
| 7177 | DIt = BeginIt; DIt != EndIt; ++DIt) |
| 7178 | Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt))); |
| 7179 | } |
| 7180 | |
Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 7181 | bool |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7182 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
| 7183 | DeclarationName Name) { |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7184 | assert(DC->hasExternalVisibleStorage() && DC == DC->getPrimaryContext() && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7185 | "DeclContext has no visible decls in storage"); |
| 7186 | if (!Name) |
Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 7187 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7188 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7189 | auto It = Lookups.find(DC); |
| 7190 | if (It == Lookups.end()) |
| 7191 | return false; |
| 7192 | |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 7193 | Deserializing LookupResults(this); |
| 7194 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7195 | // Load the list of declarations. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7196 | SmallVector<NamedDecl *, 64> Decls; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7197 | for (DeclID ID : It->second.Table.find(Name)) { |
| 7198 | NamedDecl *ND = cast<NamedDecl>(GetDecl(ID)); |
| 7199 | if (ND->getDeclName() == Name) |
| 7200 | Decls.push_back(ND); |
| 7201 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7202 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7203 | ++NumVisibleDeclContextsRead; |
| 7204 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 7205 | return !Decls.empty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7206 | } |
| 7207 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7208 | void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) { |
| 7209 | if (!DC->hasExternalVisibleStorage()) |
| 7210 | return; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7211 | |
| 7212 | auto It = Lookups.find(DC); |
| 7213 | assert(It != Lookups.end() && |
| 7214 | "have external visible storage but no lookup tables"); |
| 7215 | |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 7216 | DeclsMap Decls; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7217 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7218 | for (DeclID ID : It->second.Table.findAll()) { |
| 7219 | NamedDecl *ND = cast<NamedDecl>(GetDecl(ID)); |
| 7220 | Decls[ND->getDeclName()].push_back(ND); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7221 | } |
| 7222 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7223 | ++NumVisibleDeclContextsRead; |
| 7224 | |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 7225 | for (DeclsMap::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7226 | SetExternalVisibleDeclsForName(DC, I->first, I->second); |
| 7227 | } |
| 7228 | const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false); |
| 7229 | } |
| 7230 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7231 | const serialization::reader::DeclContextLookupTable * |
| 7232 | ASTReader::getLoadedLookupTables(DeclContext *Primary) const { |
| 7233 | auto I = Lookups.find(Primary); |
| 7234 | return I == Lookups.end() ? nullptr : &I->second; |
| 7235 | } |
| 7236 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7237 | /// \brief Under non-PCH compilation the consumer receives the objc methods |
| 7238 | /// before receiving the implementation, and codegen depends on this. |
| 7239 | /// We simulate this by deserializing and passing to consumer the methods of the |
| 7240 | /// implementation before passing the deserialized implementation decl. |
| 7241 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 7242 | ASTConsumer *Consumer) { |
| 7243 | assert(ImplD && Consumer); |
| 7244 | |
Aaron Ballman | aff18c0 | 2014-03-13 19:03:34 +0000 | [diff] [blame] | 7245 | for (auto *I : ImplD->methods()) |
| 7246 | Consumer->HandleInterestingDecl(DeclGroupRef(I)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7247 | |
| 7248 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 7249 | } |
| 7250 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7251 | void ASTReader::PassInterestingDeclToConsumer(Decl *D) { |
| 7252 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 7253 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 7254 | else |
| 7255 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
| 7256 | } |
| 7257 | |
| 7258 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
| 7259 | this->Consumer = Consumer; |
| 7260 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 7261 | if (Consumer) |
| 7262 | PassInterestingDeclsToConsumer(); |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 7263 | |
| 7264 | if (DeserializationListener) |
| 7265 | DeserializationListener->ReaderInitialized(this); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7266 | } |
| 7267 | |
| 7268 | void ASTReader::PrintStats() { |
| 7269 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
| 7270 | |
| 7271 | unsigned NumTypesLoaded |
| 7272 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
| 7273 | QualType()); |
| 7274 | unsigned NumDeclsLoaded |
| 7275 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7276 | (Decl *)nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7277 | unsigned NumIdentifiersLoaded |
| 7278 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 7279 | IdentifiersLoaded.end(), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7280 | (IdentifierInfo *)nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7281 | unsigned NumMacrosLoaded |
| 7282 | = MacrosLoaded.size() - std::count(MacrosLoaded.begin(), |
| 7283 | MacrosLoaded.end(), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7284 | (MacroInfo *)nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7285 | unsigned NumSelectorsLoaded |
| 7286 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 7287 | SelectorsLoaded.end(), |
| 7288 | Selector()); |
| 7289 | |
| 7290 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
| 7291 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 7292 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 7293 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
| 7294 | if (!TypesLoaded.empty()) |
| 7295 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
| 7296 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 7297 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 7298 | if (!DeclsLoaded.empty()) |
| 7299 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
| 7300 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 7301 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
| 7302 | if (!IdentifiersLoaded.empty()) |
| 7303 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
| 7304 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 7305 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
| 7306 | if (!MacrosLoaded.empty()) |
| 7307 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 7308 | NumMacrosLoaded, (unsigned)MacrosLoaded.size(), |
| 7309 | ((float)NumMacrosLoaded/MacrosLoaded.size() * 100)); |
| 7310 | if (!SelectorsLoaded.empty()) |
| 7311 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
| 7312 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 7313 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
| 7314 | if (TotalNumStatements) |
| 7315 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 7316 | NumStatementsRead, TotalNumStatements, |
| 7317 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 7318 | if (TotalNumMacros) |
| 7319 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 7320 | NumMacrosRead, TotalNumMacros, |
| 7321 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 7322 | if (TotalLexicalDeclContexts) |
| 7323 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 7324 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 7325 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 7326 | * 100)); |
| 7327 | if (TotalVisibleDeclContexts) |
| 7328 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 7329 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 7330 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 7331 | * 100)); |
| 7332 | if (TotalNumMethodPoolEntries) { |
| 7333 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
| 7334 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 7335 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
| 7336 | * 100)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7337 | } |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7338 | if (NumMethodPoolLookups) { |
| 7339 | std::fprintf(stderr, " %u/%u method pool lookups succeeded (%f%%)\n", |
| 7340 | NumMethodPoolHits, NumMethodPoolLookups, |
| 7341 | ((float)NumMethodPoolHits/NumMethodPoolLookups * 100.0)); |
| 7342 | } |
| 7343 | if (NumMethodPoolTableLookups) { |
| 7344 | std::fprintf(stderr, " %u/%u method pool table lookups succeeded (%f%%)\n", |
| 7345 | NumMethodPoolTableHits, NumMethodPoolTableLookups, |
| 7346 | ((float)NumMethodPoolTableHits/NumMethodPoolTableLookups |
| 7347 | * 100.0)); |
| 7348 | } |
| 7349 | |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 7350 | if (NumIdentifierLookupHits) { |
| 7351 | std::fprintf(stderr, |
| 7352 | " %u / %u identifier table lookups succeeded (%f%%)\n", |
| 7353 | NumIdentifierLookupHits, NumIdentifierLookups, |
| 7354 | (double)NumIdentifierLookupHits*100.0/NumIdentifierLookups); |
| 7355 | } |
| 7356 | |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 7357 | if (GlobalIndex) { |
| 7358 | std::fprintf(stderr, "\n"); |
| 7359 | GlobalIndex->printStats(); |
| 7360 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7361 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7362 | std::fprintf(stderr, "\n"); |
| 7363 | dump(); |
| 7364 | std::fprintf(stderr, "\n"); |
| 7365 | } |
| 7366 | |
| 7367 | template<typename Key, typename ModuleFile, unsigned InitialCapacity> |
Vassil Vassilev | b271068 | 2017-03-02 18:13:19 +0000 | [diff] [blame] | 7368 | LLVM_DUMP_METHOD static void |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7369 | dumpModuleIDMap(StringRef Name, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7370 | const ContinuousRangeMap<Key, ModuleFile *, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7371 | InitialCapacity> &Map) { |
| 7372 | if (Map.begin() == Map.end()) |
| 7373 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7374 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7375 | typedef ContinuousRangeMap<Key, ModuleFile *, InitialCapacity> MapType; |
| 7376 | llvm::errs() << Name << ":\n"; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7377 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7378 | I != IEnd; ++I) { |
| 7379 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 7380 | << "\n"; |
| 7381 | } |
| 7382 | } |
| 7383 | |
Yaron Keren | cdae941 | 2016-01-29 19:38:18 +0000 | [diff] [blame] | 7384 | LLVM_DUMP_METHOD void ASTReader::dump() { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7385 | llvm::errs() << "*** PCH/ModuleFile Remappings:\n"; |
| 7386 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
| 7387 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
| 7388 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
| 7389 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
| 7390 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
| 7391 | dumpModuleIDMap("Global macro map", GlobalMacroMap); |
| 7392 | dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap); |
| 7393 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7394 | dumpModuleIDMap("Global preprocessed entity map", |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7395 | GlobalPreprocessedEntityMap); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7396 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7397 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 7398 | for (ModuleFile &M : ModuleMgr) |
| 7399 | M.dump(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7400 | } |
| 7401 | |
| 7402 | /// Return the amount of memory used by memory buffers, breaking down |
| 7403 | /// by heap-backed versus mmap'ed memory. |
| 7404 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 7405 | for (ModuleFile &I : ModuleMgr) { |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 7406 | if (llvm::MemoryBuffer *buf = I.Buffer) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7407 | size_t bytes = buf->getBufferSize(); |
| 7408 | switch (buf->getBufferKind()) { |
| 7409 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 7410 | sizes.malloc_bytes += bytes; |
| 7411 | break; |
| 7412 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 7413 | sizes.mmap_bytes += bytes; |
| 7414 | break; |
| 7415 | } |
| 7416 | } |
| 7417 | } |
| 7418 | } |
| 7419 | |
| 7420 | void ASTReader::InitializeSema(Sema &S) { |
| 7421 | SemaObj = &S; |
| 7422 | S.addExternalSource(this); |
| 7423 | |
| 7424 | // Makes sure any declarations that were deserialized "too early" |
| 7425 | // still get added to the identifier's declaration chains. |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7426 | for (uint64_t ID : PreloadedDeclIDs) { |
| 7427 | NamedDecl *D = cast<NamedDecl>(GetDecl(ID)); |
| 7428 | pushExternalDeclIntoScope(D, D->getDeclName()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7429 | } |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7430 | PreloadedDeclIDs.clear(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7431 | |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7432 | // FIXME: What happens if these are changed by a module import? |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7433 | if (!FPPragmaOptions.empty()) { |
| 7434 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 7435 | SemaObj->FPFeatures = FPOptions(FPPragmaOptions[0]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7436 | } |
| 7437 | |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 7438 | SemaObj->OpenCLFeatures.copy(OpenCLExtensions); |
| 7439 | SemaObj->OpenCLTypeExtMap = OpenCLTypeExtMap; |
| 7440 | SemaObj->OpenCLDeclExtMap = OpenCLDeclExtMap; |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7441 | |
| 7442 | UpdateSema(); |
| 7443 | } |
| 7444 | |
| 7445 | void ASTReader::UpdateSema() { |
| 7446 | assert(SemaObj && "no Sema to update"); |
| 7447 | |
| 7448 | // Load the offsets of the declarations that Sema references. |
| 7449 | // They will be lazily deserialized when needed. |
| 7450 | if (!SemaDeclRefs.empty()) { |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 7451 | assert(SemaDeclRefs.size() % 3 == 0); |
| 7452 | for (unsigned I = 0; I != SemaDeclRefs.size(); I += 3) { |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7453 | if (!SemaObj->StdNamespace) |
| 7454 | SemaObj->StdNamespace = SemaDeclRefs[I]; |
| 7455 | if (!SemaObj->StdBadAlloc) |
| 7456 | SemaObj->StdBadAlloc = SemaDeclRefs[I+1]; |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 7457 | if (!SemaObj->StdAlignValT) |
| 7458 | SemaObj->StdAlignValT = SemaDeclRefs[I+2]; |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7459 | } |
| 7460 | SemaDeclRefs.clear(); |
| 7461 | } |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 7462 | |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 7463 | // Update the state of pragmas. Use the same API as if we had encountered the |
| 7464 | // pragma in the source. |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 7465 | if(OptimizeOffPragmaLocation.isValid()) |
| 7466 | SemaObj->ActOnPragmaOptimize(/* IsOn = */ false, OptimizeOffPragmaLocation); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 7467 | if (PragmaMSStructState != -1) |
| 7468 | SemaObj->ActOnPragmaMSStruct((PragmaMSStructKind)PragmaMSStructState); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 7469 | if (PointersToMembersPragmaLocation.isValid()) { |
| 7470 | SemaObj->ActOnPragmaMSPointersToMembers( |
| 7471 | (LangOptions::PragmaMSPointersToMembersKind) |
| 7472 | PragmaMSPointersToMembersState, |
| 7473 | PointersToMembersPragmaLocation); |
| 7474 | } |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 7475 | SemaObj->ForceCUDAHostDeviceDepth = ForceCUDAHostDeviceDepth; |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 7476 | |
| 7477 | if (PragmaPackCurrentValue) { |
| 7478 | // The bottom of the stack might have a default value. It must be adjusted |
| 7479 | // to the current value to ensure that the packing state is preserved after |
| 7480 | // popping entries that were included/imported from a PCH/module. |
| 7481 | bool DropFirst = false; |
| 7482 | if (!PragmaPackStack.empty() && |
| 7483 | PragmaPackStack.front().Location.isInvalid()) { |
| 7484 | assert(PragmaPackStack.front().Value == SemaObj->PackStack.DefaultValue && |
| 7485 | "Expected a default alignment value"); |
| 7486 | SemaObj->PackStack.Stack.emplace_back( |
| 7487 | PragmaPackStack.front().SlotLabel, SemaObj->PackStack.CurrentValue, |
| 7488 | SemaObj->PackStack.CurrentPragmaLocation); |
| 7489 | DropFirst = true; |
| 7490 | } |
| 7491 | for (const auto &Entry : |
| 7492 | llvm::makeArrayRef(PragmaPackStack).drop_front(DropFirst ? 1 : 0)) |
| 7493 | SemaObj->PackStack.Stack.emplace_back(Entry.SlotLabel, Entry.Value, |
| 7494 | Entry.Location); |
| 7495 | if (PragmaPackCurrentLocation.isInvalid()) { |
| 7496 | assert(*PragmaPackCurrentValue == SemaObj->PackStack.DefaultValue && |
| 7497 | "Expected a default alignment value"); |
| 7498 | // Keep the current values. |
| 7499 | } else { |
| 7500 | SemaObj->PackStack.CurrentValue = *PragmaPackCurrentValue; |
| 7501 | SemaObj->PackStack.CurrentPragmaLocation = PragmaPackCurrentLocation; |
| 7502 | } |
| 7503 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7504 | } |
| 7505 | |
Richard Smith | a8d5b6a | 2015-07-17 19:51:03 +0000 | [diff] [blame] | 7506 | IdentifierInfo *ASTReader::get(StringRef Name) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7507 | // Note that we are loading an identifier. |
| 7508 | Deserializing AnIdentifier(this); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 7509 | |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 7510 | IdentifierLookupVisitor Visitor(Name, /*PriorGeneration=*/0, |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 7511 | NumIdentifierLookups, |
| 7512 | NumIdentifierLookupHits); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7513 | |
| 7514 | // We don't need to do identifier table lookups in C++ modules (we preload |
| 7515 | // all interesting declarations, and don't need to use the scope for name |
| 7516 | // lookups). Perform the lookup in PCH files, though, since we don't build |
| 7517 | // a complete initial identifier table if we're carrying on from a PCH. |
| 7518 | if (Context.getLangOpts().CPlusPlus) { |
| 7519 | for (auto F : ModuleMgr.pch_modules()) |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7520 | if (Visitor(*F)) |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7521 | break; |
| 7522 | } else { |
| 7523 | // If there is a global index, look there first to determine which modules |
| 7524 | // provably do not have any results for this identifier. |
| 7525 | GlobalModuleIndex::HitSet Hits; |
| 7526 | GlobalModuleIndex::HitSet *HitsPtr = nullptr; |
| 7527 | if (!loadGlobalIndex()) { |
| 7528 | if (GlobalIndex->lookupIdentifier(Name, Hits)) { |
| 7529 | HitsPtr = &Hits; |
| 7530 | } |
| 7531 | } |
| 7532 | |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7533 | ModuleMgr.visit(Visitor, HitsPtr); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7534 | } |
| 7535 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7536 | IdentifierInfo *II = Visitor.getIdentifierInfo(); |
| 7537 | markIdentifierUpToDate(II); |
| 7538 | return II; |
| 7539 | } |
| 7540 | |
| 7541 | namespace clang { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7542 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7543 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 7544 | /// identifiers stored within a set of AST files. |
| 7545 | class ASTIdentifierIterator : public IdentifierIterator { |
| 7546 | /// \brief The AST reader whose identifiers are being enumerated. |
| 7547 | const ASTReader &Reader; |
| 7548 | |
| 7549 | /// \brief The current index into the chain of AST files stored in |
| 7550 | /// the AST reader. |
| 7551 | unsigned Index; |
| 7552 | |
| 7553 | /// \brief The current position within the identifier lookup table |
| 7554 | /// of the current AST file. |
| 7555 | ASTIdentifierLookupTable::key_iterator Current; |
| 7556 | |
| 7557 | /// \brief The end position within the identifier lookup table of |
| 7558 | /// the current AST file. |
| 7559 | ASTIdentifierLookupTable::key_iterator End; |
| 7560 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7561 | /// \brief Whether to skip any modules in the ASTReader. |
| 7562 | bool SkipModules; |
| 7563 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7564 | public: |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7565 | explicit ASTIdentifierIterator(const ASTReader &Reader, |
| 7566 | bool SkipModules = false); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7567 | |
Craig Topper | 3e89dfe | 2014-03-13 02:13:41 +0000 | [diff] [blame] | 7568 | StringRef Next() override; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7569 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7570 | |
| 7571 | } // end namespace clang |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7572 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7573 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader, |
| 7574 | bool SkipModules) |
| 7575 | : Reader(Reader), Index(Reader.ModuleMgr.size()), SkipModules(SkipModules) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7576 | } |
| 7577 | |
| 7578 | StringRef ASTIdentifierIterator::Next() { |
| 7579 | while (Current == End) { |
| 7580 | // If we have exhausted all of our AST files, we're done. |
| 7581 | if (Index == 0) |
| 7582 | return StringRef(); |
| 7583 | |
| 7584 | --Index; |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7585 | ModuleFile &F = Reader.ModuleMgr[Index]; |
| 7586 | if (SkipModules && F.isModule()) |
| 7587 | continue; |
| 7588 | |
| 7589 | ASTIdentifierLookupTable *IdTable = |
| 7590 | (ASTIdentifierLookupTable *)F.IdentifierLookupTable; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7591 | Current = IdTable->key_begin(); |
| 7592 | End = IdTable->key_end(); |
| 7593 | } |
| 7594 | |
| 7595 | // We have any identifiers remaining in the current AST file; return |
| 7596 | // the next one. |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 7597 | StringRef Result = *Current; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7598 | ++Current; |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 7599 | return Result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7600 | } |
| 7601 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7602 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7603 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7604 | /// A utility for appending two IdentifierIterators. |
| 7605 | class ChainedIdentifierIterator : public IdentifierIterator { |
| 7606 | std::unique_ptr<IdentifierIterator> Current; |
| 7607 | std::unique_ptr<IdentifierIterator> Queued; |
| 7608 | |
| 7609 | public: |
| 7610 | ChainedIdentifierIterator(std::unique_ptr<IdentifierIterator> First, |
| 7611 | std::unique_ptr<IdentifierIterator> Second) |
| 7612 | : Current(std::move(First)), Queued(std::move(Second)) {} |
| 7613 | |
| 7614 | StringRef Next() override { |
| 7615 | if (!Current) |
| 7616 | return StringRef(); |
| 7617 | |
| 7618 | StringRef result = Current->Next(); |
| 7619 | if (!result.empty()) |
| 7620 | return result; |
| 7621 | |
| 7622 | // Try the queued iterator, which may itself be empty. |
| 7623 | Current.reset(); |
| 7624 | std::swap(Current, Queued); |
| 7625 | return Next(); |
| 7626 | } |
| 7627 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7628 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7629 | } // end anonymous namespace. |
| 7630 | |
Argyrios Kyrtzidis | 9aca3c6 | 2013-04-17 22:10:55 +0000 | [diff] [blame] | 7631 | IdentifierIterator *ASTReader::getIdentifiers() { |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7632 | if (!loadGlobalIndex()) { |
| 7633 | std::unique_ptr<IdentifierIterator> ReaderIter( |
| 7634 | new ASTIdentifierIterator(*this, /*SkipModules=*/true)); |
| 7635 | std::unique_ptr<IdentifierIterator> ModulesIter( |
| 7636 | GlobalIndex->createIdentifierIterator()); |
| 7637 | return new ChainedIdentifierIterator(std::move(ReaderIter), |
| 7638 | std::move(ModulesIter)); |
| 7639 | } |
Argyrios Kyrtzidis | 9aca3c6 | 2013-04-17 22:10:55 +0000 | [diff] [blame] | 7640 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7641 | return new ASTIdentifierIterator(*this); |
| 7642 | } |
| 7643 | |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7644 | namespace clang { |
| 7645 | namespace serialization { |
| 7646 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7647 | class ReadMethodPoolVisitor { |
| 7648 | ASTReader &Reader; |
| 7649 | Selector Sel; |
| 7650 | unsigned PriorGeneration; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7651 | unsigned InstanceBits; |
| 7652 | unsigned FactoryBits; |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7653 | bool InstanceHasMoreThanOneDecl; |
| 7654 | bool FactoryHasMoreThanOneDecl; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 7655 | SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 7656 | SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7657 | |
| 7658 | public: |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 7659 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7660 | unsigned PriorGeneration) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 7661 | : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration), |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7662 | InstanceBits(0), FactoryBits(0), InstanceHasMoreThanOneDecl(false), |
| 7663 | FactoryHasMoreThanOneDecl(false) {} |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 7664 | |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7665 | bool operator()(ModuleFile &M) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7666 | if (!M.SelectorLookupTable) |
| 7667 | return false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7668 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7669 | // If we've already searched this module file, skip it now. |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7670 | if (M.Generation <= PriorGeneration) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7671 | return true; |
| 7672 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7673 | ++Reader.NumMethodPoolTableLookups; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7674 | ASTSelectorLookupTable *PoolTable |
| 7675 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7676 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7677 | if (Pos == PoolTable->end()) |
| 7678 | return false; |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7679 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7680 | ++Reader.NumMethodPoolTableHits; |
| 7681 | ++Reader.NumSelectorsRead; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7682 | // FIXME: Not quite happy with the statistics here. We probably should |
| 7683 | // disable this tracking when called via LoadSelector. |
| 7684 | // Also, should entries without methods count as misses? |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7685 | ++Reader.NumMethodPoolEntriesRead; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7686 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7687 | if (Reader.DeserializationListener) |
| 7688 | Reader.DeserializationListener->SelectorRead(Data.ID, Sel); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7689 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7690 | InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 7691 | FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 7692 | InstanceBits = Data.InstanceBits; |
| 7693 | FactoryBits = Data.FactoryBits; |
| 7694 | InstanceHasMoreThanOneDecl = Data.InstanceHasMoreThanOneDecl; |
| 7695 | FactoryHasMoreThanOneDecl = Data.FactoryHasMoreThanOneDecl; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7696 | return true; |
| 7697 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7698 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7699 | /// \brief Retrieve the instance methods found by this visitor. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7700 | ArrayRef<ObjCMethodDecl *> getInstanceMethods() const { |
| 7701 | return InstanceMethods; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7702 | } |
| 7703 | |
| 7704 | /// \brief Retrieve the instance methods found by this visitor. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7705 | ArrayRef<ObjCMethodDecl *> getFactoryMethods() const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7706 | return FactoryMethods; |
| 7707 | } |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7708 | |
| 7709 | unsigned getInstanceBits() const { return InstanceBits; } |
| 7710 | unsigned getFactoryBits() const { return FactoryBits; } |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7711 | bool instanceHasMoreThanOneDecl() const { |
| 7712 | return InstanceHasMoreThanOneDecl; |
| 7713 | } |
| 7714 | bool factoryHasMoreThanOneDecl() const { return FactoryHasMoreThanOneDecl; } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7715 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7716 | |
| 7717 | } // end namespace serialization |
| 7718 | } // end namespace clang |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7719 | |
| 7720 | /// \brief Add the given set of methods to the method list. |
| 7721 | static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods, |
| 7722 | ObjCMethodList &List) { |
| 7723 | for (unsigned I = 0, N = Methods.size(); I != N; ++I) { |
| 7724 | S.addMethodToGlobalList(&List, Methods[I]); |
| 7725 | } |
| 7726 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7727 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7728 | void ASTReader::ReadMethodPool(Selector Sel) { |
| 7729 | // Get the selector generation and update it to the current generation. |
| 7730 | unsigned &Generation = SelectorGeneration[Sel]; |
| 7731 | unsigned PriorGeneration = Generation; |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 7732 | Generation = getGeneration(); |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 7733 | SelectorOutOfDate[Sel] = false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7734 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7735 | // Search for methods defined with this selector. |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7736 | ++NumMethodPoolLookups; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7737 | ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7738 | ModuleMgr.visit(Visitor); |
| 7739 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7740 | if (Visitor.getInstanceMethods().empty() && |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7741 | Visitor.getFactoryMethods().empty()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7742 | return; |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7743 | |
| 7744 | ++NumMethodPoolHits; |
| 7745 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7746 | if (!getSema()) |
| 7747 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7748 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7749 | Sema &S = *getSema(); |
| 7750 | Sema::GlobalMethodPool::iterator Pos |
| 7751 | = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first; |
Ben Langmuir | a0c32e9 | 2015-01-12 19:27:00 +0000 | [diff] [blame] | 7752 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7753 | Pos->second.first.setBits(Visitor.getInstanceBits()); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7754 | Pos->second.first.setHasMoreThanOneDecl(Visitor.instanceHasMoreThanOneDecl()); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7755 | Pos->second.second.setBits(Visitor.getFactoryBits()); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7756 | Pos->second.second.setHasMoreThanOneDecl(Visitor.factoryHasMoreThanOneDecl()); |
Ben Langmuir | a0c32e9 | 2015-01-12 19:27:00 +0000 | [diff] [blame] | 7757 | |
| 7758 | // Add methods to the global pool *after* setting hasMoreThanOneDecl, since |
| 7759 | // when building a module we keep every method individually and may need to |
| 7760 | // update hasMoreThanOneDecl as we add the methods. |
| 7761 | addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first); |
| 7762 | addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7763 | } |
| 7764 | |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 7765 | void ASTReader::updateOutOfDateSelector(Selector Sel) { |
| 7766 | if (SelectorOutOfDate[Sel]) |
| 7767 | ReadMethodPool(Sel); |
| 7768 | } |
| 7769 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7770 | void ASTReader::ReadKnownNamespaces( |
| 7771 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
| 7772 | Namespaces.clear(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7773 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7774 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7775 | if (NamespaceDecl *Namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7776 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 7777 | Namespaces.push_back(Namespace); |
| 7778 | } |
| 7779 | } |
| 7780 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 7781 | void ASTReader::ReadUndefinedButUsed( |
Richard Smith | d6a04d7 | 2016-03-25 21:49:43 +0000 | [diff] [blame] | 7782 | llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 7783 | for (unsigned Idx = 0, N = UndefinedButUsed.size(); Idx != N;) { |
| 7784 | NamedDecl *D = cast<NamedDecl>(GetDecl(UndefinedButUsed[Idx++])); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 7785 | SourceLocation Loc = |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 7786 | SourceLocation::getFromRawEncoding(UndefinedButUsed[Idx++]); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 7787 | Undefined.insert(std::make_pair(D, Loc)); |
| 7788 | } |
| 7789 | } |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 7790 | |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 7791 | void ASTReader::ReadMismatchingDeleteExpressions(llvm::MapVector< |
| 7792 | FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> & |
| 7793 | Exprs) { |
| 7794 | for (unsigned Idx = 0, N = DelayedDeleteExprs.size(); Idx != N;) { |
| 7795 | FieldDecl *FD = cast<FieldDecl>(GetDecl(DelayedDeleteExprs[Idx++])); |
| 7796 | uint64_t Count = DelayedDeleteExprs[Idx++]; |
| 7797 | for (uint64_t C = 0; C < Count; ++C) { |
| 7798 | SourceLocation DeleteLoc = |
| 7799 | SourceLocation::getFromRawEncoding(DelayedDeleteExprs[Idx++]); |
| 7800 | const bool IsArrayForm = DelayedDeleteExprs[Idx++]; |
| 7801 | Exprs[FD].push_back(std::make_pair(DeleteLoc, IsArrayForm)); |
| 7802 | } |
| 7803 | } |
| 7804 | } |
| 7805 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7806 | void ASTReader::ReadTentativeDefinitions( |
| 7807 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 7808 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 7809 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 7810 | if (Var) |
| 7811 | TentativeDefs.push_back(Var); |
| 7812 | } |
| 7813 | TentativeDefinitions.clear(); |
| 7814 | } |
| 7815 | |
| 7816 | void ASTReader::ReadUnusedFileScopedDecls( |
| 7817 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 7818 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 7819 | DeclaratorDecl *D |
| 7820 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 7821 | if (D) |
| 7822 | Decls.push_back(D); |
| 7823 | } |
| 7824 | UnusedFileScopedDecls.clear(); |
| 7825 | } |
| 7826 | |
| 7827 | void ASTReader::ReadDelegatingConstructors( |
| 7828 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 7829 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 7830 | CXXConstructorDecl *D |
| 7831 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 7832 | if (D) |
| 7833 | Decls.push_back(D); |
| 7834 | } |
| 7835 | DelegatingCtorDecls.clear(); |
| 7836 | } |
| 7837 | |
| 7838 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 7839 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 7840 | TypedefNameDecl *D |
| 7841 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 7842 | if (D) |
| 7843 | Decls.push_back(D); |
| 7844 | } |
| 7845 | ExtVectorDecls.clear(); |
| 7846 | } |
| 7847 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 7848 | void ASTReader::ReadUnusedLocalTypedefNameCandidates( |
| 7849 | llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) { |
| 7850 | for (unsigned I = 0, N = UnusedLocalTypedefNameCandidates.size(); I != N; |
| 7851 | ++I) { |
| 7852 | TypedefNameDecl *D = dyn_cast_or_null<TypedefNameDecl>( |
| 7853 | GetDecl(UnusedLocalTypedefNameCandidates[I])); |
| 7854 | if (D) |
| 7855 | Decls.insert(D); |
| 7856 | } |
| 7857 | UnusedLocalTypedefNameCandidates.clear(); |
| 7858 | } |
| 7859 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7860 | void ASTReader::ReadReferencedSelectors( |
| 7861 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 7862 | if (ReferencedSelectorsData.empty()) |
| 7863 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7864 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7865 | // If there are @selector references added them to its pool. This is for |
| 7866 | // implementation of -Wselector. |
| 7867 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 7868 | unsigned I = 0; |
| 7869 | while (I < DataSize) { |
| 7870 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 7871 | SourceLocation SelLoc |
| 7872 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 7873 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 7874 | } |
| 7875 | ReferencedSelectorsData.clear(); |
| 7876 | } |
| 7877 | |
| 7878 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 7879 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 7880 | if (WeakUndeclaredIdentifiers.empty()) |
| 7881 | return; |
| 7882 | |
| 7883 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7884 | IdentifierInfo *WeakId |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7885 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7886 | IdentifierInfo *AliasId |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7887 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 7888 | SourceLocation Loc |
| 7889 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 7890 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 7891 | WeakInfo WI(AliasId, Loc); |
| 7892 | WI.setUsed(Used); |
| 7893 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 7894 | } |
| 7895 | WeakUndeclaredIdentifiers.clear(); |
| 7896 | } |
| 7897 | |
| 7898 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 7899 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 7900 | ExternalVTableUse VT; |
| 7901 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 7902 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 7903 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 7904 | VTables.push_back(VT); |
| 7905 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7906 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7907 | VTableUses.clear(); |
| 7908 | } |
| 7909 | |
| 7910 | void ASTReader::ReadPendingInstantiations( |
| 7911 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 7912 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 7913 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 7914 | SourceLocation Loc |
| 7915 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 7916 | |
| 7917 | Pending.push_back(std::make_pair(D, Loc)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7918 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7919 | PendingInstantiations.clear(); |
| 7920 | } |
| 7921 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 7922 | void ASTReader::ReadLateParsedTemplates( |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 7923 | llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> |
| 7924 | &LPTMap) { |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 7925 | for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N; |
| 7926 | /* In loop */) { |
| 7927 | FunctionDecl *FD = cast<FunctionDecl>(GetDecl(LateParsedTemplates[Idx++])); |
| 7928 | |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 7929 | auto LT = llvm::make_unique<LateParsedTemplate>(); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 7930 | LT->D = GetDecl(LateParsedTemplates[Idx++]); |
| 7931 | |
| 7932 | ModuleFile *F = getOwningModuleFile(LT->D); |
| 7933 | assert(F && "No module"); |
| 7934 | |
| 7935 | unsigned TokN = LateParsedTemplates[Idx++]; |
| 7936 | LT->Toks.reserve(TokN); |
| 7937 | for (unsigned T = 0; T < TokN; ++T) |
| 7938 | LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx)); |
| 7939 | |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 7940 | LPTMap.insert(std::make_pair(FD, std::move(LT))); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 7941 | } |
| 7942 | |
| 7943 | LateParsedTemplates.clear(); |
| 7944 | } |
| 7945 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7946 | void ASTReader::LoadSelector(Selector Sel) { |
| 7947 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 7948 | ReadMethodPool(Sel); |
| 7949 | } |
| 7950 | |
| 7951 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
| 7952 | assert(ID && "Non-zero identifier ID required"); |
| 7953 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
| 7954 | IdentifiersLoaded[ID - 1] = II; |
| 7955 | if (DeserializationListener) |
| 7956 | DeserializationListener->IdentifierRead(ID, II); |
| 7957 | } |
| 7958 | |
| 7959 | /// \brief Set the globally-visible declarations associated with the given |
| 7960 | /// identifier. |
| 7961 | /// |
| 7962 | /// If the AST reader is currently in a state where the given declaration IDs |
| 7963 | /// cannot safely be resolved, they are queued until it is safe to resolve |
| 7964 | /// them. |
| 7965 | /// |
| 7966 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 7967 | /// declarations. |
| 7968 | /// |
| 7969 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 7970 | /// visible at global scope. |
| 7971 | /// |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 7972 | /// \param Decls if non-null, this vector will be populated with the set of |
| 7973 | /// deserialized declarations. These declarations will not be pushed into |
| 7974 | /// scope. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7975 | void |
| 7976 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
| 7977 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 7978 | SmallVectorImpl<Decl *> *Decls) { |
| 7979 | if (NumCurrentElementsDeserializing && !Decls) { |
| 7980 | PendingIdentifierInfos[II].append(DeclIDs.begin(), DeclIDs.end()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7981 | return; |
| 7982 | } |
| 7983 | |
| 7984 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7985 | if (!SemaObj) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7986 | // Queue this declaration so that it will be added to the |
| 7987 | // translation unit scope and identifier's declaration chain |
| 7988 | // once a Sema object is known. |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7989 | PreloadedDeclIDs.push_back(DeclIDs[I]); |
| 7990 | continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7991 | } |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7992 | |
| 7993 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 7994 | |
| 7995 | // If we're simply supposed to record the declarations, do so now. |
| 7996 | if (Decls) { |
| 7997 | Decls->push_back(D); |
| 7998 | continue; |
| 7999 | } |
| 8000 | |
| 8001 | // Introduce this declaration into the translation-unit scope |
| 8002 | // and add it to the declaration chain for this identifier, so |
| 8003 | // that (unqualified) name lookup will find it. |
| 8004 | pushExternalDeclIntoScope(D, II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8005 | } |
| 8006 | } |
| 8007 | |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 8008 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8009 | if (ID == 0) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8010 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8011 | |
| 8012 | if (IdentifiersLoaded.empty()) { |
| 8013 | Error("no identifier table in AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8014 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8015 | } |
| 8016 | |
| 8017 | ID -= 1; |
| 8018 | if (!IdentifiersLoaded[ID]) { |
| 8019 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 8020 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
| 8021 | ModuleFile *M = I->second; |
| 8022 | unsigned Index = ID - M->BaseIdentifierID; |
| 8023 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
| 8024 | |
| 8025 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 8026 | // Extract that 16-bit length to avoid having to execute strlen(). |
| 8027 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 8028 | // unsigned integers. This is important to avoid integer overflow when |
| 8029 | // we cast them to 'unsigned'. |
| 8030 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
| 8031 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 8032 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 8033 | auto &II = PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
| 8034 | IdentifiersLoaded[ID] = &II; |
| 8035 | markIdentifierFromAST(*this, II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8036 | if (DeserializationListener) |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 8037 | DeserializationListener->IdentifierRead(ID + 1, &II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8038 | } |
| 8039 | |
| 8040 | return IdentifiersLoaded[ID]; |
| 8041 | } |
| 8042 | |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 8043 | IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) { |
| 8044 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8045 | } |
| 8046 | |
| 8047 | IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) { |
| 8048 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 8049 | return LocalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8050 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8051 | if (!M.ModuleOffsetMap.empty()) |
| 8052 | ReadModuleOffsetMap(M); |
| 8053 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8054 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8055 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8056 | assert(I != M.IdentifierRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8057 | && "Invalid index into identifier index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8058 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8059 | return LocalID + I->second; |
| 8060 | } |
| 8061 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8062 | MacroInfo *ASTReader::getMacro(MacroID ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8063 | if (ID == 0) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8064 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8065 | |
| 8066 | if (MacrosLoaded.empty()) { |
| 8067 | Error("no macro table in AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8068 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8069 | } |
| 8070 | |
| 8071 | ID -= NUM_PREDEF_MACRO_IDS; |
| 8072 | if (!MacrosLoaded[ID]) { |
| 8073 | GlobalMacroMapType::iterator I |
| 8074 | = GlobalMacroMap.find(ID + NUM_PREDEF_MACRO_IDS); |
| 8075 | assert(I != GlobalMacroMap.end() && "Corrupted global macro map"); |
| 8076 | ModuleFile *M = I->second; |
| 8077 | unsigned Index = ID - M->BaseMacroID; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8078 | MacrosLoaded[ID] = ReadMacroRecord(*M, M->MacroOffsets[Index]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8079 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8080 | if (DeserializationListener) |
| 8081 | DeserializationListener->MacroRead(ID + NUM_PREDEF_MACRO_IDS, |
| 8082 | MacrosLoaded[ID]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8083 | } |
| 8084 | |
| 8085 | return MacrosLoaded[ID]; |
| 8086 | } |
| 8087 | |
| 8088 | MacroID ASTReader::getGlobalMacroID(ModuleFile &M, unsigned LocalID) { |
| 8089 | if (LocalID < NUM_PREDEF_MACRO_IDS) |
| 8090 | return LocalID; |
| 8091 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8092 | if (!M.ModuleOffsetMap.empty()) |
| 8093 | ReadModuleOffsetMap(M); |
| 8094 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8095 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8096 | = M.MacroRemap.find(LocalID - NUM_PREDEF_MACRO_IDS); |
| 8097 | assert(I != M.MacroRemap.end() && "Invalid index into macro index remap"); |
| 8098 | |
| 8099 | return LocalID + I->second; |
| 8100 | } |
| 8101 | |
| 8102 | serialization::SubmoduleID |
| 8103 | ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) { |
| 8104 | if (LocalID < NUM_PREDEF_SUBMODULE_IDS) |
| 8105 | return LocalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8106 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8107 | if (!M.ModuleOffsetMap.empty()) |
| 8108 | ReadModuleOffsetMap(M); |
| 8109 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8110 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8111 | = M.SubmoduleRemap.find(LocalID - NUM_PREDEF_SUBMODULE_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8112 | assert(I != M.SubmoduleRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8113 | && "Invalid index into submodule index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8114 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8115 | return LocalID + I->second; |
| 8116 | } |
| 8117 | |
| 8118 | Module *ASTReader::getSubmodule(SubmoduleID GlobalID) { |
| 8119 | if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) { |
| 8120 | assert(GlobalID == 0 && "Unhandled global submodule ID"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8121 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8122 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8123 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8124 | if (GlobalID > SubmodulesLoaded.size()) { |
| 8125 | Error("submodule ID out of range in AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8126 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8127 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8128 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8129 | return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS]; |
| 8130 | } |
Douglas Gregor | c147b0b | 2013-01-12 01:29:50 +0000 | [diff] [blame] | 8131 | |
| 8132 | Module *ASTReader::getModule(unsigned ID) { |
| 8133 | return getSubmodule(ID); |
| 8134 | } |
| 8135 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 8136 | ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &F, unsigned ID) { |
| 8137 | if (ID & 1) { |
| 8138 | // It's a module, look it up by submodule ID. |
| 8139 | auto I = GlobalSubmoduleMap.find(getGlobalSubmoduleID(F, ID >> 1)); |
| 8140 | return I == GlobalSubmoduleMap.end() ? nullptr : I->second; |
| 8141 | } else { |
| 8142 | // It's a prefix (preamble, PCH, ...). Look it up by index. |
| 8143 | unsigned IndexFromEnd = ID >> 1; |
| 8144 | assert(IndexFromEnd && "got reference to unknown module file"); |
| 8145 | return getModuleManager().pch_modules().end()[-IndexFromEnd]; |
| 8146 | } |
| 8147 | } |
| 8148 | |
| 8149 | unsigned ASTReader::getModuleFileID(ModuleFile *F) { |
| 8150 | if (!F) |
| 8151 | return 1; |
| 8152 | |
| 8153 | // For a file representing a module, use the submodule ID of the top-level |
| 8154 | // module as the file ID. For any other kind of file, the number of such |
| 8155 | // files loaded beforehand will be the same on reload. |
| 8156 | // FIXME: Is this true even if we have an explicit module file and a PCH? |
| 8157 | if (F->isModule()) |
| 8158 | return ((F->BaseSubmoduleID + NUM_PREDEF_SUBMODULE_IDS) << 1) | 1; |
| 8159 | |
| 8160 | auto PCHModules = getModuleManager().pch_modules(); |
| 8161 | auto I = std::find(PCHModules.begin(), PCHModules.end(), F); |
| 8162 | assert(I != PCHModules.end() && "emitting reference to unknown file"); |
| 8163 | return (I - PCHModules.end()) << 1; |
| 8164 | } |
| 8165 | |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8166 | llvm::Optional<ExternalASTSource::ASTSourceDescriptor> |
| 8167 | ASTReader::getSourceDescriptor(unsigned ID) { |
| 8168 | if (const Module *M = getSubmodule(ID)) |
Adrian Prantl | c6458d6 | 2015-09-19 00:10:32 +0000 | [diff] [blame] | 8169 | return ExternalASTSource::ASTSourceDescriptor(*M); |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8170 | |
| 8171 | // If there is only a single PCH, return it instead. |
| 8172 | // Chained PCH are not suported. |
Saleem Abdulrasool | 97d2555 | 2017-03-02 17:37:11 +0000 | [diff] [blame] | 8173 | const auto &PCHChain = ModuleMgr.pch_modules(); |
| 8174 | if (std::distance(std::begin(PCHChain), std::end(PCHChain))) { |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8175 | ModuleFile &MF = ModuleMgr.getPrimaryModule(); |
Adrian Prantl | 3a2d494 | 2016-01-22 23:30:56 +0000 | [diff] [blame] | 8176 | StringRef ModuleName = llvm::sys::path::filename(MF.OriginalSourceFileName); |
Adrian Prantl | 9bc3c4f | 2016-04-27 17:06:22 +0000 | [diff] [blame] | 8177 | StringRef FileName = llvm::sys::path::filename(MF.FileName); |
| 8178 | return ASTReader::ASTSourceDescriptor(ModuleName, MF.OriginalDir, FileName, |
| 8179 | MF.Signature); |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8180 | } |
| 8181 | return None; |
| 8182 | } |
| 8183 | |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 8184 | ExternalASTSource::ExtKind ASTReader::hasExternalDefinitions(const Decl *FD) { |
David Blaikie | e6b7c28 | 2017-04-11 20:46:34 +0000 | [diff] [blame] | 8185 | auto I = BodySource.find(FD); |
| 8186 | if (I == BodySource.end()) |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 8187 | return EK_ReplyHazy; |
David Blaikie | e6b7c28 | 2017-04-11 20:46:34 +0000 | [diff] [blame] | 8188 | return I->second ? EK_Never : EK_Always; |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 8189 | } |
| 8190 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8191 | Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) { |
| 8192 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 8193 | } |
| 8194 | |
| 8195 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
| 8196 | if (ID == 0) |
| 8197 | return Selector(); |
| 8198 | |
| 8199 | if (ID > SelectorsLoaded.size()) { |
| 8200 | Error("selector ID out of range in AST file"); |
| 8201 | return Selector(); |
| 8202 | } |
| 8203 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8204 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == nullptr) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8205 | // Load this selector from the selector table. |
| 8206 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 8207 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
| 8208 | ModuleFile &M = *I->second; |
| 8209 | ASTSelectorLookupTrait Trait(*this, M); |
| 8210 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
| 8211 | SelectorsLoaded[ID - 1] = |
| 8212 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
| 8213 | if (DeserializationListener) |
| 8214 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 8215 | } |
| 8216 | |
| 8217 | return SelectorsLoaded[ID - 1]; |
| 8218 | } |
| 8219 | |
| 8220 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
| 8221 | return DecodeSelector(ID); |
| 8222 | } |
| 8223 | |
| 8224 | uint32_t ASTReader::GetNumExternalSelectors() { |
| 8225 | // ID 0 (the null selector) is considered an external selector. |
| 8226 | return getTotalNumSelectors() + 1; |
| 8227 | } |
| 8228 | |
| 8229 | serialization::SelectorID |
| 8230 | ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const { |
| 8231 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 8232 | return LocalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8233 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8234 | if (!M.ModuleOffsetMap.empty()) |
| 8235 | ReadModuleOffsetMap(M); |
| 8236 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8237 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8238 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8239 | assert(I != M.SelectorRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8240 | && "Invalid index into selector index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8241 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8242 | return LocalID + I->second; |
| 8243 | } |
| 8244 | |
| 8245 | DeclarationName |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8246 | ASTReader::ReadDeclarationName(ModuleFile &F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8247 | const RecordData &Record, unsigned &Idx) { |
| 8248 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 8249 | switch (Kind) { |
| 8250 | case DeclarationName::Identifier: |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 8251 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8252 | |
| 8253 | case DeclarationName::ObjCZeroArgSelector: |
| 8254 | case DeclarationName::ObjCOneArgSelector: |
| 8255 | case DeclarationName::ObjCMultiArgSelector: |
| 8256 | return DeclarationName(ReadSelector(F, Record, Idx)); |
| 8257 | |
| 8258 | case DeclarationName::CXXConstructorName: |
| 8259 | return Context.DeclarationNames.getCXXConstructorName( |
| 8260 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 8261 | |
| 8262 | case DeclarationName::CXXDestructorName: |
| 8263 | return Context.DeclarationNames.getCXXDestructorName( |
| 8264 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 8265 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8266 | case DeclarationName::CXXDeductionGuideName: |
| 8267 | return Context.DeclarationNames.getCXXDeductionGuideName( |
| 8268 | ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
| 8269 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8270 | case DeclarationName::CXXConversionFunctionName: |
| 8271 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 8272 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 8273 | |
| 8274 | case DeclarationName::CXXOperatorName: |
| 8275 | return Context.DeclarationNames.getCXXOperatorName( |
| 8276 | (OverloadedOperatorKind)Record[Idx++]); |
| 8277 | |
| 8278 | case DeclarationName::CXXLiteralOperatorName: |
| 8279 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
| 8280 | GetIdentifierInfo(F, Record, Idx)); |
| 8281 | |
| 8282 | case DeclarationName::CXXUsingDirective: |
| 8283 | return DeclarationName::getUsingDirectiveName(); |
| 8284 | } |
| 8285 | |
| 8286 | llvm_unreachable("Invalid NameKind!"); |
| 8287 | } |
| 8288 | |
| 8289 | void ASTReader::ReadDeclarationNameLoc(ModuleFile &F, |
| 8290 | DeclarationNameLoc &DNLoc, |
| 8291 | DeclarationName Name, |
| 8292 | const RecordData &Record, unsigned &Idx) { |
| 8293 | switch (Name.getNameKind()) { |
| 8294 | case DeclarationName::CXXConstructorName: |
| 8295 | case DeclarationName::CXXDestructorName: |
| 8296 | case DeclarationName::CXXConversionFunctionName: |
| 8297 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8298 | break; |
| 8299 | |
| 8300 | case DeclarationName::CXXOperatorName: |
| 8301 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 8302 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 8303 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 8304 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 8305 | break; |
| 8306 | |
| 8307 | case DeclarationName::CXXLiteralOperatorName: |
| 8308 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 8309 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 8310 | break; |
| 8311 | |
| 8312 | case DeclarationName::Identifier: |
| 8313 | case DeclarationName::ObjCZeroArgSelector: |
| 8314 | case DeclarationName::ObjCOneArgSelector: |
| 8315 | case DeclarationName::ObjCMultiArgSelector: |
| 8316 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8317 | case DeclarationName::CXXDeductionGuideName: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8318 | break; |
| 8319 | } |
| 8320 | } |
| 8321 | |
| 8322 | void ASTReader::ReadDeclarationNameInfo(ModuleFile &F, |
| 8323 | DeclarationNameInfo &NameInfo, |
| 8324 | const RecordData &Record, unsigned &Idx) { |
| 8325 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
| 8326 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 8327 | DeclarationNameLoc DNLoc; |
| 8328 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 8329 | NameInfo.setInfo(DNLoc); |
| 8330 | } |
| 8331 | |
| 8332 | void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, |
| 8333 | const RecordData &Record, unsigned &Idx) { |
| 8334 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
| 8335 | unsigned NumTPLists = Record[Idx++]; |
| 8336 | Info.NumTemplParamLists = NumTPLists; |
| 8337 | if (NumTPLists) { |
| 8338 | Info.TemplParamLists = new (Context) TemplateParameterList*[NumTPLists]; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 8339 | for (unsigned i = 0; i != NumTPLists; ++i) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8340 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 8341 | } |
| 8342 | } |
| 8343 | |
| 8344 | TemplateName |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8345 | ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8346 | unsigned &Idx) { |
| 8347 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
| 8348 | switch (Kind) { |
| 8349 | case TemplateName::Template: |
| 8350 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
| 8351 | |
| 8352 | case TemplateName::OverloadedTemplate: { |
| 8353 | unsigned size = Record[Idx++]; |
| 8354 | UnresolvedSet<8> Decls; |
| 8355 | while (size--) |
| 8356 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
| 8357 | |
| 8358 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 8359 | } |
| 8360 | |
| 8361 | case TemplateName::QualifiedTemplate: { |
| 8362 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
| 8363 | bool hasTemplKeyword = Record[Idx++]; |
| 8364 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
| 8365 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 8366 | } |
| 8367 | |
| 8368 | case TemplateName::DependentTemplate: { |
| 8369 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
| 8370 | if (Record[Idx++]) // isIdentifier |
| 8371 | return Context.getDependentTemplateName(NNS, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8372 | GetIdentifierInfo(F, Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8373 | Idx)); |
| 8374 | return Context.getDependentTemplateName(NNS, |
| 8375 | (OverloadedOperatorKind)Record[Idx++]); |
| 8376 | } |
| 8377 | |
| 8378 | case TemplateName::SubstTemplateTemplateParm: { |
| 8379 | TemplateTemplateParmDecl *param |
| 8380 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
| 8381 | if (!param) return TemplateName(); |
| 8382 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
| 8383 | return Context.getSubstTemplateTemplateParm(param, replacement); |
| 8384 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8385 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8386 | case TemplateName::SubstTemplateTemplateParmPack: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8387 | TemplateTemplateParmDecl *Param |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8388 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
| 8389 | if (!Param) |
| 8390 | return TemplateName(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8391 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8392 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 8393 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 8394 | return TemplateName(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8395 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8396 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 8397 | } |
| 8398 | } |
| 8399 | |
| 8400 | llvm_unreachable("Unhandled template name kind!"); |
| 8401 | } |
| 8402 | |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8403 | TemplateArgument ASTReader::ReadTemplateArgument(ModuleFile &F, |
| 8404 | const RecordData &Record, |
| 8405 | unsigned &Idx, |
| 8406 | bool Canonicalize) { |
| 8407 | if (Canonicalize) { |
| 8408 | // The caller wants a canonical template argument. Sometimes the AST only |
| 8409 | // wants template arguments in canonical form (particularly as the template |
| 8410 | // argument lists of template specializations) so ensure we preserve that |
| 8411 | // canonical form across serialization. |
| 8412 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Idx, false); |
| 8413 | return Context.getCanonicalTemplateArgument(Arg); |
| 8414 | } |
| 8415 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8416 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 8417 | switch (Kind) { |
| 8418 | case TemplateArgument::Null: |
| 8419 | return TemplateArgument(); |
| 8420 | case TemplateArgument::Type: |
| 8421 | return TemplateArgument(readType(F, Record, Idx)); |
| 8422 | case TemplateArgument::Declaration: { |
| 8423 | ValueDecl *D = ReadDeclAs<ValueDecl>(F, Record, Idx); |
David Blaikie | 0f62c8d | 2014-10-16 04:21:25 +0000 | [diff] [blame] | 8424 | return TemplateArgument(D, readType(F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8425 | } |
| 8426 | case TemplateArgument::NullPtr: |
| 8427 | return TemplateArgument(readType(F, Record, Idx), /*isNullPtr*/true); |
| 8428 | case TemplateArgument::Integral: { |
| 8429 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 8430 | QualType T = readType(F, Record, Idx); |
| 8431 | return TemplateArgument(Context, Value, T); |
| 8432 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8433 | case TemplateArgument::Template: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8434 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
| 8435 | case TemplateArgument::TemplateExpansion: { |
| 8436 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8437 | Optional<unsigned> NumTemplateExpansions; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8438 | if (unsigned NumExpansions = Record[Idx++]) |
| 8439 | NumTemplateExpansions = NumExpansions - 1; |
| 8440 | return TemplateArgument(Name, NumTemplateExpansions); |
| 8441 | } |
| 8442 | case TemplateArgument::Expression: |
| 8443 | return TemplateArgument(ReadExpr(F)); |
| 8444 | case TemplateArgument::Pack: { |
| 8445 | unsigned NumArgs = Record[Idx++]; |
| 8446 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
| 8447 | for (unsigned I = 0; I != NumArgs; ++I) |
| 8448 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 8449 | return TemplateArgument(llvm::makeArrayRef(Args, NumArgs)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8450 | } |
| 8451 | } |
| 8452 | |
| 8453 | llvm_unreachable("Unhandled template argument kind!"); |
| 8454 | } |
| 8455 | |
| 8456 | TemplateParameterList * |
| 8457 | ASTReader::ReadTemplateParameterList(ModuleFile &F, |
| 8458 | const RecordData &Record, unsigned &Idx) { |
| 8459 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 8460 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 8461 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 8462 | |
| 8463 | unsigned NumParams = Record[Idx++]; |
| 8464 | SmallVector<NamedDecl *, 16> Params; |
| 8465 | Params.reserve(NumParams); |
| 8466 | while (NumParams--) |
| 8467 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
| 8468 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 8469 | // TODO: Concepts |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8470 | TemplateParameterList* TemplateParams = |
| 8471 | TemplateParameterList::Create(Context, TemplateLoc, LAngleLoc, |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 8472 | Params, RAngleLoc, nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8473 | return TemplateParams; |
| 8474 | } |
| 8475 | |
| 8476 | void |
| 8477 | ASTReader:: |
Craig Topper | 5603df4 | 2013-07-05 19:34:19 +0000 | [diff] [blame] | 8478 | ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8479 | ModuleFile &F, const RecordData &Record, |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8480 | unsigned &Idx, bool Canonicalize) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8481 | unsigned NumTemplateArgs = Record[Idx++]; |
| 8482 | TemplArgs.reserve(NumTemplateArgs); |
| 8483 | while (NumTemplateArgs--) |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8484 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx, Canonicalize)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8485 | } |
| 8486 | |
| 8487 | /// \brief Read a UnresolvedSet structure. |
Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 8488 | void ASTReader::ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8489 | const RecordData &Record, unsigned &Idx) { |
| 8490 | unsigned NumDecls = Record[Idx++]; |
| 8491 | Set.reserve(Context, NumDecls); |
| 8492 | while (NumDecls--) { |
Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 8493 | DeclID ID = ReadDeclID(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8494 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 8495 | Set.addLazyDecl(Context, ID, AS); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8496 | } |
| 8497 | } |
| 8498 | |
| 8499 | CXXBaseSpecifier |
| 8500 | ASTReader::ReadCXXBaseSpecifier(ModuleFile &F, |
| 8501 | const RecordData &Record, unsigned &Idx) { |
| 8502 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 8503 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 8504 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
| 8505 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
| 8506 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8507 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8508 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8509 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8510 | EllipsisLoc); |
| 8511 | Result.setInheritConstructors(inheritConstructors); |
| 8512 | return Result; |
| 8513 | } |
| 8514 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8515 | CXXCtorInitializer ** |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8516 | ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, |
| 8517 | unsigned &Idx) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8518 | unsigned NumInitializers = Record[Idx++]; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8519 | assert(NumInitializers && "wrote ctor initializers but have no inits"); |
| 8520 | auto **CtorInitializers = new (Context) CXXCtorInitializer*[NumInitializers]; |
| 8521 | for (unsigned i = 0; i != NumInitializers; ++i) { |
| 8522 | TypeSourceInfo *TInfo = nullptr; |
| 8523 | bool IsBaseVirtual = false; |
| 8524 | FieldDecl *Member = nullptr; |
| 8525 | IndirectFieldDecl *IndirectMember = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8526 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8527 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 8528 | switch (Type) { |
| 8529 | case CTOR_INITIALIZER_BASE: |
| 8530 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8531 | IsBaseVirtual = Record[Idx++]; |
| 8532 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8533 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8534 | case CTOR_INITIALIZER_DELEGATING: |
| 8535 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8536 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8537 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8538 | case CTOR_INITIALIZER_MEMBER: |
| 8539 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
| 8540 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8541 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8542 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
| 8543 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
| 8544 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8545 | } |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8546 | |
| 8547 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
| 8548 | Expr *Init = ReadExpr(F); |
| 8549 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 8550 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8551 | |
| 8552 | CXXCtorInitializer *BOMInit; |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8553 | if (Type == CTOR_INITIALIZER_BASE) |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8554 | BOMInit = new (Context) |
| 8555 | CXXCtorInitializer(Context, TInfo, IsBaseVirtual, LParenLoc, Init, |
| 8556 | RParenLoc, MemberOrEllipsisLoc); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8557 | else if (Type == CTOR_INITIALIZER_DELEGATING) |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8558 | BOMInit = new (Context) |
| 8559 | CXXCtorInitializer(Context, TInfo, LParenLoc, Init, RParenLoc); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8560 | else if (Member) |
| 8561 | BOMInit = new (Context) |
| 8562 | CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, LParenLoc, |
| 8563 | Init, RParenLoc); |
| 8564 | else |
| 8565 | BOMInit = new (Context) |
| 8566 | CXXCtorInitializer(Context, IndirectMember, MemberOrEllipsisLoc, |
| 8567 | LParenLoc, Init, RParenLoc); |
| 8568 | |
Richard Smith | 418ed82 | 2016-12-14 19:45:03 +0000 | [diff] [blame] | 8569 | if (/*IsWritten*/Record[Idx++]) { |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8570 | unsigned SourceOrder = Record[Idx++]; |
| 8571 | BOMInit->setSourceOrder(SourceOrder); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8572 | } |
| 8573 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8574 | CtorInitializers[i] = BOMInit; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8575 | } |
| 8576 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8577 | return CtorInitializers; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8578 | } |
| 8579 | |
| 8580 | NestedNameSpecifier * |
| 8581 | ASTReader::ReadNestedNameSpecifier(ModuleFile &F, |
| 8582 | const RecordData &Record, unsigned &Idx) { |
| 8583 | unsigned N = Record[Idx++]; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8584 | NestedNameSpecifier *NNS = nullptr, *Prev = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8585 | for (unsigned I = 0; I != N; ++I) { |
| 8586 | NestedNameSpecifier::SpecifierKind Kind |
| 8587 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 8588 | switch (Kind) { |
| 8589 | case NestedNameSpecifier::Identifier: { |
| 8590 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
| 8591 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
| 8592 | break; |
| 8593 | } |
| 8594 | |
| 8595 | case NestedNameSpecifier::Namespace: { |
| 8596 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
| 8597 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
| 8598 | break; |
| 8599 | } |
| 8600 | |
| 8601 | case NestedNameSpecifier::NamespaceAlias: { |
| 8602 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
| 8603 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
| 8604 | break; |
| 8605 | } |
| 8606 | |
| 8607 | case NestedNameSpecifier::TypeSpec: |
| 8608 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 8609 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
| 8610 | if (!T) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8611 | return nullptr; |
| 8612 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8613 | bool Template = Record[Idx++]; |
| 8614 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
| 8615 | break; |
| 8616 | } |
| 8617 | |
| 8618 | case NestedNameSpecifier::Global: { |
| 8619 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
| 8620 | // No associated value, and there can't be a prefix. |
| 8621 | break; |
| 8622 | } |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8623 | |
| 8624 | case NestedNameSpecifier::Super: { |
| 8625 | CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx); |
| 8626 | NNS = NestedNameSpecifier::SuperSpecifier(Context, RD); |
| 8627 | break; |
| 8628 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8629 | } |
| 8630 | Prev = NNS; |
| 8631 | } |
| 8632 | return NNS; |
| 8633 | } |
| 8634 | |
| 8635 | NestedNameSpecifierLoc |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8636 | ASTReader::ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8637 | unsigned &Idx) { |
| 8638 | unsigned N = Record[Idx++]; |
| 8639 | NestedNameSpecifierLocBuilder Builder; |
| 8640 | for (unsigned I = 0; I != N; ++I) { |
| 8641 | NestedNameSpecifier::SpecifierKind Kind |
| 8642 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 8643 | switch (Kind) { |
| 8644 | case NestedNameSpecifier::Identifier: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8645 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8646 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8647 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
| 8648 | break; |
| 8649 | } |
| 8650 | |
| 8651 | case NestedNameSpecifier::Namespace: { |
| 8652 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
| 8653 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8654 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
| 8655 | break; |
| 8656 | } |
| 8657 | |
| 8658 | case NestedNameSpecifier::NamespaceAlias: { |
| 8659 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
| 8660 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8661 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
| 8662 | break; |
| 8663 | } |
| 8664 | |
| 8665 | case NestedNameSpecifier::TypeSpec: |
| 8666 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 8667 | bool Template = Record[Idx++]; |
| 8668 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 8669 | if (!T) |
| 8670 | return NestedNameSpecifierLoc(); |
| 8671 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
| 8672 | |
| 8673 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8674 | Builder.Extend(Context, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8675 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 8676 | T->getTypeLoc(), ColonColonLoc); |
| 8677 | break; |
| 8678 | } |
| 8679 | |
| 8680 | case NestedNameSpecifier::Global: { |
| 8681 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
| 8682 | Builder.MakeGlobal(Context, ColonColonLoc); |
| 8683 | break; |
| 8684 | } |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8685 | |
| 8686 | case NestedNameSpecifier::Super: { |
| 8687 | CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx); |
| 8688 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8689 | Builder.MakeSuper(Context, RD, Range.getBegin(), Range.getEnd()); |
| 8690 | break; |
| 8691 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8692 | } |
| 8693 | } |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8694 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8695 | return Builder.getWithLocInContext(Context); |
| 8696 | } |
| 8697 | |
| 8698 | SourceRange |
| 8699 | ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record, |
| 8700 | unsigned &Idx) { |
| 8701 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 8702 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
| 8703 | return SourceRange(beg, end); |
| 8704 | } |
| 8705 | |
| 8706 | /// \brief Read an integral value |
| 8707 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
| 8708 | unsigned BitWidth = Record[Idx++]; |
| 8709 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 8710 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 8711 | Idx += NumWords; |
| 8712 | return Result; |
| 8713 | } |
| 8714 | |
| 8715 | /// \brief Read a signed integral value |
| 8716 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
| 8717 | bool isUnsigned = Record[Idx++]; |
| 8718 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 8719 | } |
| 8720 | |
| 8721 | /// \brief Read a floating-point value |
Tim Northover | 178723a | 2013-01-22 09:46:51 +0000 | [diff] [blame] | 8722 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, |
| 8723 | const llvm::fltSemantics &Sem, |
| 8724 | unsigned &Idx) { |
| 8725 | return llvm::APFloat(Sem, ReadAPInt(Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8726 | } |
| 8727 | |
| 8728 | // \brief Read a string |
| 8729 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
| 8730 | unsigned Len = Record[Idx++]; |
| 8731 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
| 8732 | Idx += Len; |
| 8733 | return Result; |
| 8734 | } |
| 8735 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 8736 | std::string ASTReader::ReadPath(ModuleFile &F, const RecordData &Record, |
| 8737 | unsigned &Idx) { |
| 8738 | std::string Filename = ReadString(Record, Idx); |
| 8739 | ResolveImportedPath(F, Filename); |
| 8740 | return Filename; |
| 8741 | } |
| 8742 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8743 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8744 | unsigned &Idx) { |
| 8745 | unsigned Major = Record[Idx++]; |
| 8746 | unsigned Minor = Record[Idx++]; |
| 8747 | unsigned Subminor = Record[Idx++]; |
| 8748 | if (Minor == 0) |
| 8749 | return VersionTuple(Major); |
| 8750 | if (Subminor == 0) |
| 8751 | return VersionTuple(Major, Minor - 1); |
| 8752 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 8753 | } |
| 8754 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8755 | CXXTemporary *ASTReader::ReadCXXTemporary(ModuleFile &F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8756 | const RecordData &Record, |
| 8757 | unsigned &Idx) { |
| 8758 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
| 8759 | return CXXTemporary::Create(Context, Decl); |
| 8760 | } |
| 8761 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8762 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) const { |
Argyrios Kyrtzidis | dc9fdaf | 2013-05-24 05:44:08 +0000 | [diff] [blame] | 8763 | return Diag(CurrentImportLoc, DiagID); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8764 | } |
| 8765 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8766 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8767 | return Diags.Report(Loc, DiagID); |
| 8768 | } |
| 8769 | |
| 8770 | /// \brief Retrieve the identifier table associated with the |
| 8771 | /// preprocessor. |
| 8772 | IdentifierTable &ASTReader::getIdentifierTable() { |
| 8773 | return PP.getIdentifierTable(); |
| 8774 | } |
| 8775 | |
| 8776 | /// \brief Record that the given ID maps to the given switch-case |
| 8777 | /// statement. |
| 8778 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8779 | assert((*CurrSwitchCaseStmts)[ID] == nullptr && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8780 | "Already have a SwitchCase with this ID"); |
| 8781 | (*CurrSwitchCaseStmts)[ID] = SC; |
| 8782 | } |
| 8783 | |
| 8784 | /// \brief Retrieve the switch-case statement with the given ID. |
| 8785 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8786 | assert((*CurrSwitchCaseStmts)[ID] != nullptr && "No SwitchCase with this ID"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8787 | return (*CurrSwitchCaseStmts)[ID]; |
| 8788 | } |
| 8789 | |
| 8790 | void ASTReader::ClearSwitchCaseIDs() { |
| 8791 | CurrSwitchCaseStmts->clear(); |
| 8792 | } |
| 8793 | |
| 8794 | void ASTReader::ReadComments() { |
| 8795 | std::vector<RawComment *> Comments; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 8796 | for (SmallVectorImpl<std::pair<BitstreamCursor, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8797 | serialization::ModuleFile *> >::iterator |
| 8798 | I = CommentsCursors.begin(), |
| 8799 | E = CommentsCursors.end(); |
| 8800 | I != E; ++I) { |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 8801 | Comments.clear(); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 8802 | BitstreamCursor &Cursor = I->first; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8803 | serialization::ModuleFile &F = *I->second; |
| 8804 | SavedStreamPosition SavedPosition(Cursor); |
| 8805 | |
| 8806 | RecordData Record; |
| 8807 | while (true) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 8808 | llvm::BitstreamEntry Entry = |
| 8809 | Cursor.advanceSkippingSubblocks(BitstreamCursor::AF_DontPopBlockAtEnd); |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 8810 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 8811 | switch (Entry.Kind) { |
| 8812 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 8813 | case llvm::BitstreamEntry::Error: |
| 8814 | Error("malformed block record in AST file"); |
| 8815 | return; |
| 8816 | case llvm::BitstreamEntry::EndBlock: |
| 8817 | goto NextCursor; |
| 8818 | case llvm::BitstreamEntry::Record: |
| 8819 | // The interesting case. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8820 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8821 | } |
| 8822 | |
| 8823 | // Read a record. |
| 8824 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 8825 | switch ((CommentRecordTypes)Cursor.readRecord(Entry.ID, Record)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8826 | case COMMENTS_RAW_COMMENT: { |
| 8827 | unsigned Idx = 0; |
| 8828 | SourceRange SR = ReadSourceRange(F, Record, Idx); |
| 8829 | RawComment::CommentKind Kind = |
| 8830 | (RawComment::CommentKind) Record[Idx++]; |
| 8831 | bool IsTrailingComment = Record[Idx++]; |
| 8832 | bool IsAlmostTrailingComment = Record[Idx++]; |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 8833 | Comments.push_back(new (Context) RawComment( |
| 8834 | SR, Kind, IsTrailingComment, IsAlmostTrailingComment, |
| 8835 | Context.getLangOpts().CommentOpts.ParseAllComments)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8836 | break; |
| 8837 | } |
| 8838 | } |
| 8839 | } |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 8840 | NextCursor: |
Bruno Cardoso Lopes | c23af57 | 2016-12-19 21:06:06 +0000 | [diff] [blame] | 8841 | // De-serialized SourceLocations get negative FileIDs for other modules, |
| 8842 | // potentially invalidating the original order. Sort it again. |
| 8843 | std::sort(Comments.begin(), Comments.end(), |
| 8844 | BeforeThanCompare<RawComment>(SourceMgr)); |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 8845 | Context.Comments.addDeserializedComments(Comments); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8846 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8847 | } |
| 8848 | |
Argyrios Kyrtzidis | a38cb20 | 2017-01-30 06:05:58 +0000 | [diff] [blame] | 8849 | void ASTReader::visitInputFiles(serialization::ModuleFile &MF, |
| 8850 | bool IncludeSystem, bool Complain, |
| 8851 | llvm::function_ref<void(const serialization::InputFile &IF, |
| 8852 | bool isSystem)> Visitor) { |
| 8853 | unsigned NumUserInputs = MF.NumUserInputFiles; |
| 8854 | unsigned NumInputs = MF.InputFilesLoaded.size(); |
| 8855 | assert(NumUserInputs <= NumInputs); |
| 8856 | unsigned N = IncludeSystem ? NumInputs : NumUserInputs; |
| 8857 | for (unsigned I = 0; I < N; ++I) { |
| 8858 | bool IsSystem = I >= NumUserInputs; |
| 8859 | InputFile IF = getInputFile(MF, I+1, Complain); |
| 8860 | Visitor(IF, IsSystem); |
| 8861 | } |
| 8862 | } |
| 8863 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 8864 | std::string ASTReader::getOwningModuleNameForDiagnostic(const Decl *D) { |
| 8865 | // If we know the owning module, use it. |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 8866 | if (Module *M = D->getImportedOwningModule()) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 8867 | return M->getFullModuleName(); |
| 8868 | |
| 8869 | // Otherwise, use the name of the top-level module the decl is within. |
| 8870 | if (ModuleFile *M = getOwningModuleFile(D)) |
| 8871 | return M->ModuleName; |
| 8872 | |
| 8873 | // Not from a module. |
| 8874 | return ""; |
| 8875 | } |
| 8876 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8877 | void ASTReader::finishPendingActions() { |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 8878 | while (!PendingIdentifierInfos.empty() || |
| 8879 | !PendingIncompleteDeclChains.empty() || !PendingDeclChains.empty() || |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 8880 | !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() || |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 8881 | !PendingUpdateRecords.empty()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8882 | // If any identifiers with corresponding top-level declarations have |
| 8883 | // been loaded, load those declarations now. |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 8884 | typedef llvm::DenseMap<IdentifierInfo *, SmallVector<Decl *, 2> > |
| 8885 | TopLevelDeclsMap; |
| 8886 | TopLevelDeclsMap TopLevelDecls; |
| 8887 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8888 | while (!PendingIdentifierInfos.empty()) { |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8889 | IdentifierInfo *II = PendingIdentifierInfos.back().first; |
Richard Smith | f0ae3c2d | 2014-03-28 17:31:23 +0000 | [diff] [blame] | 8890 | SmallVector<uint32_t, 4> DeclIDs = |
| 8891 | std::move(PendingIdentifierInfos.back().second); |
Douglas Gregor | cb15f08 | 2013-02-19 18:26:28 +0000 | [diff] [blame] | 8892 | PendingIdentifierInfos.pop_back(); |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8893 | |
| 8894 | SetGloballyVisibleDecls(II, DeclIDs, &TopLevelDecls[II]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8895 | } |
Richard Smith | f0ae3c2d | 2014-03-28 17:31:23 +0000 | [diff] [blame] | 8896 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 8897 | // For each decl chain that we wanted to complete while deserializing, mark |
| 8898 | // it as "still needs to be completed". |
| 8899 | for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) { |
| 8900 | markIncompleteDeclChain(PendingIncompleteDeclChains[I]); |
| 8901 | } |
| 8902 | PendingIncompleteDeclChains.clear(); |
| 8903 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8904 | // Load pending declaration chains. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 8905 | for (unsigned I = 0; I != PendingDeclChains.size(); ++I) |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 8906 | loadPendingDeclChain(PendingDeclChains[I].first, PendingDeclChains[I].second); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8907 | PendingDeclChains.clear(); |
| 8908 | |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8909 | // Make the most recent of the top-level declarations visible. |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 8910 | for (TopLevelDeclsMap::iterator TLD = TopLevelDecls.begin(), |
| 8911 | TLDEnd = TopLevelDecls.end(); TLD != TLDEnd; ++TLD) { |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8912 | IdentifierInfo *II = TLD->first; |
| 8913 | for (unsigned I = 0, N = TLD->second.size(); I != N; ++I) { |
Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 8914 | pushExternalDeclIntoScope(cast<NamedDecl>(TLD->second[I]), II); |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8915 | } |
| 8916 | } |
| 8917 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8918 | // Load any pending macro definitions. |
| 8919 | for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) { |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8920 | IdentifierInfo *II = PendingMacroIDs.begin()[I].first; |
| 8921 | SmallVector<PendingMacroInfo, 2> GlobalIDs; |
| 8922 | GlobalIDs.swap(PendingMacroIDs.begin()[I].second); |
| 8923 | // Initialize the macro history from chained-PCHs ahead of module imports. |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 8924 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
Argyrios Kyrtzidis | 719736c | 2013-01-19 03:14:56 +0000 | [diff] [blame] | 8925 | ++IDIdx) { |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8926 | const PendingMacroInfo &Info = GlobalIDs[IDIdx]; |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 8927 | if (!Info.M->isModule()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8928 | resolvePendingMacro(II, Info); |
| 8929 | } |
| 8930 | // Handle module imports. |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 8931 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8932 | ++IDIdx) { |
| 8933 | const PendingMacroInfo &Info = GlobalIDs[IDIdx]; |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 8934 | if (Info.M->isModule()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8935 | resolvePendingMacro(II, Info); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8936 | } |
| 8937 | } |
| 8938 | PendingMacroIDs.clear(); |
Argyrios Kyrtzidis | 83a6e3b | 2013-02-16 00:48:59 +0000 | [diff] [blame] | 8939 | |
| 8940 | // Wire up the DeclContexts for Decls that we delayed setting until |
| 8941 | // recursive loading is completed. |
| 8942 | while (!PendingDeclContextInfos.empty()) { |
| 8943 | PendingDeclContextInfo Info = PendingDeclContextInfos.front(); |
| 8944 | PendingDeclContextInfos.pop_front(); |
| 8945 | DeclContext *SemaDC = cast<DeclContext>(GetDecl(Info.SemaDC)); |
| 8946 | DeclContext *LexicalDC = cast<DeclContext>(GetDecl(Info.LexicalDC)); |
| 8947 | Info.D->setDeclContextsImpl(SemaDC, LexicalDC, getContext()); |
| 8948 | } |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 8949 | |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 8950 | // Perform any pending declaration updates. |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 8951 | while (!PendingUpdateRecords.empty()) { |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 8952 | auto Update = PendingUpdateRecords.pop_back_val(); |
| 8953 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 8954 | loadDeclUpdateRecords(Update.first, Update.second); |
| 8955 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8956 | } |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 8957 | |
| 8958 | // At this point, all update records for loaded decls are in place, so any |
| 8959 | // fake class definitions should have become real. |
| 8960 | assert(PendingFakeDefinitionData.empty() && |
| 8961 | "faked up a class definition but never saw the real one"); |
| 8962 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8963 | // If we deserialized any C++ or Objective-C class definitions, any |
| 8964 | // Objective-C protocol definitions, or any redeclarable templates, make sure |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8965 | // that all redeclarations point to the definitions. Note that this can only |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8966 | // happen now, after the redeclaration chains have been fully wired. |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 8967 | for (Decl *D : PendingDefinitions) { |
| 8968 | if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
Richard Smith | 5b21db8 | 2014-04-23 18:20:42 +0000 | [diff] [blame] | 8969 | if (const TagType *TagT = dyn_cast<TagType>(TD->getTypeForDecl())) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8970 | // Make sure that the TagType points at the definition. |
| 8971 | const_cast<TagType*>(TagT)->decl = TD; |
| 8972 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 8973 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 8974 | if (auto RD = dyn_cast<CXXRecordDecl>(D)) { |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 8975 | for (auto *R = getMostRecentExistingDecl(RD); R; |
| 8976 | R = R->getPreviousDecl()) { |
| 8977 | assert((R == D) == |
| 8978 | cast<CXXRecordDecl>(R)->isThisDeclarationADefinition() && |
Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 8979 | "declaration thinks it's the definition but it isn't"); |
Aaron Ballman | 86c9390 | 2014-03-06 23:45:36 +0000 | [diff] [blame] | 8980 | cast<CXXRecordDecl>(R)->DefinitionData = RD->DefinitionData; |
Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 8981 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8982 | } |
| 8983 | |
| 8984 | continue; |
| 8985 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 8986 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 8987 | if (auto ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8988 | // Make sure that the ObjCInterfaceType points at the definition. |
| 8989 | const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl)) |
| 8990 | ->Decl = ID; |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 8991 | |
| 8992 | for (auto *R = getMostRecentExistingDecl(ID); R; R = R->getPreviousDecl()) |
| 8993 | cast<ObjCInterfaceDecl>(R)->Data = ID->Data; |
| 8994 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8995 | continue; |
| 8996 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 8997 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 8998 | if (auto PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 8999 | for (auto *R = getMostRecentExistingDecl(PD); R; R = R->getPreviousDecl()) |
| 9000 | cast<ObjCProtocolDecl>(R)->Data = PD->Data; |
| 9001 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9002 | continue; |
| 9003 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9004 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9005 | auto RTD = cast<RedeclarableTemplateDecl>(D)->getCanonicalDecl(); |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9006 | for (auto *R = getMostRecentExistingDecl(RTD); R; R = R->getPreviousDecl()) |
| 9007 | cast<RedeclarableTemplateDecl>(R)->Common = RTD->Common; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9008 | } |
| 9009 | PendingDefinitions.clear(); |
| 9010 | |
| 9011 | // Load the bodies of any functions or methods we've encountered. We do |
| 9012 | // 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] | 9013 | // have been fully wired up (hasBody relies on this). |
| 9014 | // FIXME: We shouldn't require complete redeclaration chains here. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9015 | for (PendingBodiesMap::iterator PB = PendingBodies.begin(), |
| 9016 | PBEnd = PendingBodies.end(); |
| 9017 | PB != PBEnd; ++PB) { |
| 9018 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(PB->first)) { |
| 9019 | // FIXME: Check for =delete/=default? |
| 9020 | // FIXME: Complain about ODR violations here? |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 9021 | const FunctionDecl *Defn = nullptr; |
David Blaikie | e6b7c28 | 2017-04-11 20:46:34 +0000 | [diff] [blame] | 9022 | if (!getContext().getLangOpts().Modules || !FD->hasBody(Defn)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9023 | FD->setLazyBody(PB->second); |
David Blaikie | e6b7c28 | 2017-04-11 20:46:34 +0000 | [diff] [blame] | 9024 | } else |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 9025 | mergeDefinitionVisibility(const_cast<FunctionDecl*>(Defn), FD); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9026 | continue; |
| 9027 | } |
| 9028 | |
| 9029 | ObjCMethodDecl *MD = cast<ObjCMethodDecl>(PB->first); |
| 9030 | if (!getContext().getLangOpts().Modules || !MD->hasBody()) |
| 9031 | MD->setLazyBody(PB->second); |
| 9032 | } |
| 9033 | PendingBodies.clear(); |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 9034 | |
| 9035 | // Do some cleanup. |
| 9036 | for (auto *ND : PendingMergedDefinitionsToDeduplicate) |
| 9037 | getContext().deduplicateMergedDefinitonsFor(ND); |
| 9038 | PendingMergedDefinitionsToDeduplicate.clear(); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9039 | } |
| 9040 | |
| 9041 | void ASTReader::diagnoseOdrViolations() { |
Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 9042 | if (PendingOdrMergeFailures.empty() && PendingOdrMergeChecks.empty()) |
| 9043 | return; |
| 9044 | |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9045 | // Trigger the import of the full definition of each class that had any |
| 9046 | // odr-merging problems, so we can produce better diagnostics for them. |
Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 9047 | // These updates may in turn find and diagnose some ODR failures, so take |
| 9048 | // ownership of the set first. |
| 9049 | auto OdrMergeFailures = std::move(PendingOdrMergeFailures); |
| 9050 | PendingOdrMergeFailures.clear(); |
| 9051 | for (auto &Merge : OdrMergeFailures) { |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9052 | Merge.first->buildLookup(); |
| 9053 | Merge.first->decls_begin(); |
| 9054 | Merge.first->bases_begin(); |
| 9055 | Merge.first->vbases_begin(); |
| 9056 | for (auto *RD : Merge.second) { |
| 9057 | RD->decls_begin(); |
| 9058 | RD->bases_begin(); |
| 9059 | RD->vbases_begin(); |
| 9060 | } |
| 9061 | } |
| 9062 | |
| 9063 | // For each declaration from a merged context, check that the canonical |
| 9064 | // definition of that context also contains a declaration of the same |
| 9065 | // entity. |
| 9066 | // |
| 9067 | // Caution: this loop does things that might invalidate iterators into |
| 9068 | // PendingOdrMergeChecks. Don't turn this into a range-based for loop! |
| 9069 | while (!PendingOdrMergeChecks.empty()) { |
| 9070 | NamedDecl *D = PendingOdrMergeChecks.pop_back_val(); |
| 9071 | |
| 9072 | // FIXME: Skip over implicit declarations for now. This matters for things |
| 9073 | // like implicitly-declared special member functions. This isn't entirely |
| 9074 | // correct; we can end up with multiple unmerged declarations of the same |
| 9075 | // implicit entity. |
| 9076 | if (D->isImplicit()) |
| 9077 | continue; |
| 9078 | |
| 9079 | DeclContext *CanonDef = D->getDeclContext(); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9080 | |
| 9081 | bool Found = false; |
| 9082 | const Decl *DCanon = D->getCanonicalDecl(); |
| 9083 | |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 9084 | for (auto RI : D->redecls()) { |
| 9085 | if (RI->getLexicalDeclContext() == CanonDef) { |
| 9086 | Found = true; |
| 9087 | break; |
| 9088 | } |
| 9089 | } |
| 9090 | if (Found) |
| 9091 | continue; |
| 9092 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9093 | // Quick check failed, time to do the slow thing. Note, we can't just |
| 9094 | // look up the name of D in CanonDef here, because the member that is |
| 9095 | // in CanonDef might not be found by name lookup (it might have been |
| 9096 | // replaced by a more recent declaration in the lookup table), and we |
| 9097 | // can't necessarily find it in the redeclaration chain because it might |
| 9098 | // be merely mergeable, not redeclarable. |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9099 | llvm::SmallVector<const NamedDecl*, 4> Candidates; |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9100 | for (auto *CanonMember : CanonDef->decls()) { |
| 9101 | if (CanonMember->getCanonicalDecl() == DCanon) { |
| 9102 | // This can happen if the declaration is merely mergeable and not |
| 9103 | // actually redeclarable (we looked for redeclarations earlier). |
| 9104 | // |
| 9105 | // FIXME: We should be able to detect this more efficiently, without |
| 9106 | // pulling in all of the members of CanonDef. |
| 9107 | Found = true; |
| 9108 | break; |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9109 | } |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9110 | if (auto *ND = dyn_cast<NamedDecl>(CanonMember)) |
| 9111 | if (ND->getDeclName() == D->getDeclName()) |
| 9112 | Candidates.push_back(ND); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9113 | } |
| 9114 | |
| 9115 | if (!Found) { |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 9116 | // The AST doesn't like TagDecls becoming invalid after they've been |
| 9117 | // completed. We only really need to mark FieldDecls as invalid here. |
| 9118 | if (!isa<TagDecl>(D)) |
| 9119 | D->setInvalidDecl(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 9120 | |
Richard Smith | 4ab3dbd | 2015-02-13 22:43:51 +0000 | [diff] [blame] | 9121 | // Ensure we don't accidentally recursively enter deserialization while |
| 9122 | // we're producing our diagnostic. |
| 9123 | Deserializing RecursionGuard(this); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9124 | |
| 9125 | std::string CanonDefModule = |
| 9126 | getOwningModuleNameForDiagnostic(cast<Decl>(CanonDef)); |
| 9127 | Diag(D->getLocation(), diag::err_module_odr_violation_missing_decl) |
| 9128 | << D << getOwningModuleNameForDiagnostic(D) |
| 9129 | << CanonDef << CanonDefModule.empty() << CanonDefModule; |
| 9130 | |
| 9131 | if (Candidates.empty()) |
| 9132 | Diag(cast<Decl>(CanonDef)->getLocation(), |
| 9133 | diag::note_module_odr_violation_no_possible_decls) << D; |
| 9134 | else { |
| 9135 | for (unsigned I = 0, N = Candidates.size(); I != N; ++I) |
| 9136 | Diag(Candidates[I]->getLocation(), |
| 9137 | diag::note_module_odr_violation_possible_decl) |
| 9138 | << Candidates[I]; |
| 9139 | } |
| 9140 | |
| 9141 | DiagnosedOdrMergeFailures.insert(CanonDef); |
| 9142 | } |
| 9143 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9144 | |
Richard Smith | 4ab3dbd | 2015-02-13 22:43:51 +0000 | [diff] [blame] | 9145 | if (OdrMergeFailures.empty()) |
| 9146 | return; |
| 9147 | |
| 9148 | // Ensure we don't accidentally recursively enter deserialization while |
| 9149 | // we're producing our diagnostics. |
| 9150 | Deserializing RecursionGuard(this); |
| 9151 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9152 | // Issue any pending ODR-failure diagnostics. |
Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 9153 | for (auto &Merge : OdrMergeFailures) { |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9154 | // If we've already pointed out a specific problem with this class, don't |
| 9155 | // bother issuing a general "something's different" diagnostic. |
David Blaikie | 82e95a3 | 2014-11-19 07:49:47 +0000 | [diff] [blame] | 9156 | if (!DiagnosedOdrMergeFailures.insert(Merge.first).second) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9157 | continue; |
| 9158 | |
| 9159 | bool Diagnosed = false; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9160 | CXXRecordDecl *FirstRecord = Merge.first; |
| 9161 | std::string FirstModule = getOwningModuleNameForDiagnostic(FirstRecord); |
| 9162 | for (CXXRecordDecl *SecondRecord : Merge.second) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9163 | // Multiple different declarations got merged together; tell the user |
| 9164 | // where they came from. |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9165 | if (FirstRecord == SecondRecord) |
| 9166 | continue; |
| 9167 | |
| 9168 | std::string SecondModule = getOwningModuleNameForDiagnostic(SecondRecord); |
| 9169 | using DeclHashes = llvm::SmallVector<std::pair<Decl *, unsigned>, 4>; |
| 9170 | DeclHashes FirstHashes; |
| 9171 | DeclHashes SecondHashes; |
| 9172 | ODRHash Hash; |
| 9173 | |
| 9174 | auto PopulateHashes = [&Hash, FirstRecord](DeclHashes &Hashes, |
| 9175 | CXXRecordDecl *Record) { |
| 9176 | for (auto *D : Record->decls()) { |
| 9177 | // Due to decl merging, the first CXXRecordDecl is the parent of |
| 9178 | // Decls in both records. |
| 9179 | if (!ODRHash::isWhitelistedDecl(D, FirstRecord)) |
| 9180 | continue; |
| 9181 | Hash.clear(); |
| 9182 | Hash.AddSubDecl(D); |
| 9183 | Hashes.emplace_back(D, Hash.CalculateHash()); |
| 9184 | } |
| 9185 | }; |
| 9186 | PopulateHashes(FirstHashes, FirstRecord); |
| 9187 | PopulateHashes(SecondHashes, SecondRecord); |
| 9188 | |
| 9189 | // Used with err_module_odr_violation_mismatch_decl and |
| 9190 | // note_module_odr_violation_mismatch_decl |
| 9191 | enum { |
| 9192 | EndOfClass, |
| 9193 | PublicSpecifer, |
| 9194 | PrivateSpecifer, |
| 9195 | ProtectedSpecifer, |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9196 | StaticAssert, |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9197 | Field, |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9198 | CXXMethod, |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9199 | Other |
| 9200 | } FirstDiffType = Other, |
| 9201 | SecondDiffType = Other; |
| 9202 | |
| 9203 | auto DifferenceSelector = [](Decl *D) { |
| 9204 | assert(D && "valid Decl required"); |
| 9205 | switch (D->getKind()) { |
| 9206 | default: |
| 9207 | return Other; |
| 9208 | case Decl::AccessSpec: |
| 9209 | switch (D->getAccess()) { |
| 9210 | case AS_public: |
| 9211 | return PublicSpecifer; |
| 9212 | case AS_private: |
| 9213 | return PrivateSpecifer; |
| 9214 | case AS_protected: |
| 9215 | return ProtectedSpecifer; |
| 9216 | case AS_none: |
Simon Pilgrim | eeb1b30 | 2017-02-22 13:21:24 +0000 | [diff] [blame] | 9217 | break; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9218 | } |
Simon Pilgrim | eeb1b30 | 2017-02-22 13:21:24 +0000 | [diff] [blame] | 9219 | llvm_unreachable("Invalid access specifier"); |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9220 | case Decl::StaticAssert: |
| 9221 | return StaticAssert; |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9222 | case Decl::Field: |
| 9223 | return Field; |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9224 | case Decl::CXXMethod: |
| 9225 | return CXXMethod; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9226 | } |
| 9227 | }; |
| 9228 | |
| 9229 | Decl *FirstDecl = nullptr; |
| 9230 | Decl *SecondDecl = nullptr; |
| 9231 | auto FirstIt = FirstHashes.begin(); |
| 9232 | auto SecondIt = SecondHashes.begin(); |
| 9233 | |
| 9234 | // If there is a diagnoseable difference, FirstDiffType and |
| 9235 | // SecondDiffType will not be Other and FirstDecl and SecondDecl will be |
| 9236 | // filled in if not EndOfClass. |
| 9237 | while (FirstIt != FirstHashes.end() || SecondIt != SecondHashes.end()) { |
Benjamin Kramer | 6f224d2 | 2017-02-22 10:19:45 +0000 | [diff] [blame] | 9238 | if (FirstIt != FirstHashes.end() && SecondIt != SecondHashes.end() && |
| 9239 | FirstIt->second == SecondIt->second) { |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9240 | ++FirstIt; |
| 9241 | ++SecondIt; |
| 9242 | continue; |
Richard Trieu | dc4cb02 | 2017-02-17 07:19:24 +0000 | [diff] [blame] | 9243 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9244 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9245 | FirstDecl = FirstIt == FirstHashes.end() ? nullptr : FirstIt->first; |
| 9246 | SecondDecl = SecondIt == SecondHashes.end() ? nullptr : SecondIt->first; |
| 9247 | |
| 9248 | FirstDiffType = FirstDecl ? DifferenceSelector(FirstDecl) : EndOfClass; |
| 9249 | SecondDiffType = |
| 9250 | SecondDecl ? DifferenceSelector(SecondDecl) : EndOfClass; |
| 9251 | |
| 9252 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9253 | } |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9254 | |
| 9255 | if (FirstDiffType == Other || SecondDiffType == Other) { |
| 9256 | // Reaching this point means an unexpected Decl was encountered |
| 9257 | // or no difference was detected. This causes a generic error |
| 9258 | // message to be emitted. |
| 9259 | Diag(FirstRecord->getLocation(), |
| 9260 | diag::err_module_odr_violation_different_definitions) |
| 9261 | << FirstRecord << FirstModule.empty() << FirstModule; |
| 9262 | |
| 9263 | Diag(SecondRecord->getLocation(), |
| 9264 | diag::note_module_odr_violation_different_definitions) |
| 9265 | << SecondModule; |
| 9266 | Diagnosed = true; |
| 9267 | break; |
| 9268 | } |
| 9269 | |
| 9270 | if (FirstDiffType != SecondDiffType) { |
| 9271 | SourceLocation FirstLoc; |
| 9272 | SourceRange FirstRange; |
| 9273 | if (FirstDiffType == EndOfClass) { |
| 9274 | FirstLoc = FirstRecord->getBraceRange().getEnd(); |
| 9275 | } else { |
| 9276 | FirstLoc = FirstIt->first->getLocation(); |
| 9277 | FirstRange = FirstIt->first->getSourceRange(); |
| 9278 | } |
| 9279 | Diag(FirstLoc, diag::err_module_odr_violation_mismatch_decl) |
| 9280 | << FirstRecord << FirstModule.empty() << FirstModule << FirstRange |
| 9281 | << FirstDiffType; |
| 9282 | |
| 9283 | SourceLocation SecondLoc; |
| 9284 | SourceRange SecondRange; |
| 9285 | if (SecondDiffType == EndOfClass) { |
| 9286 | SecondLoc = SecondRecord->getBraceRange().getEnd(); |
| 9287 | } else { |
| 9288 | SecondLoc = SecondDecl->getLocation(); |
| 9289 | SecondRange = SecondDecl->getSourceRange(); |
| 9290 | } |
| 9291 | Diag(SecondLoc, diag::note_module_odr_violation_mismatch_decl) |
| 9292 | << SecondModule << SecondRange << SecondDiffType; |
| 9293 | Diagnosed = true; |
| 9294 | break; |
| 9295 | } |
| 9296 | |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9297 | assert(FirstDiffType == SecondDiffType); |
| 9298 | |
| 9299 | // Used with err_module_odr_violation_mismatch_decl_diff and |
| 9300 | // note_module_odr_violation_mismatch_decl_diff |
| 9301 | enum ODRDeclDifference{ |
| 9302 | StaticAssertCondition, |
| 9303 | StaticAssertMessage, |
| 9304 | StaticAssertOnlyMessage, |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9305 | FieldName, |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 9306 | FieldTypeName, |
Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 9307 | FieldSingleBitField, |
Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 9308 | FieldDifferentWidthBitField, |
| 9309 | FieldSingleMutable, |
| 9310 | FieldSingleInitializer, |
| 9311 | FieldDifferentInitializers, |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9312 | MethodName, |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9313 | MethodDeleted, |
| 9314 | MethodVirtual, |
| 9315 | MethodStatic, |
| 9316 | MethodVolatile, |
| 9317 | MethodConst, |
| 9318 | MethodInline, |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9319 | }; |
| 9320 | |
| 9321 | // These lambdas have the common portions of the ODR diagnostics. This |
| 9322 | // has the same return as Diag(), so addition parameters can be passed |
| 9323 | // in with operator<< |
| 9324 | auto ODRDiagError = [FirstRecord, &FirstModule, this]( |
| 9325 | SourceLocation Loc, SourceRange Range, ODRDeclDifference DiffType) { |
| 9326 | return Diag(Loc, diag::err_module_odr_violation_mismatch_decl_diff) |
| 9327 | << FirstRecord << FirstModule.empty() << FirstModule << Range |
| 9328 | << DiffType; |
| 9329 | }; |
| 9330 | auto ODRDiagNote = [&SecondModule, this]( |
| 9331 | SourceLocation Loc, SourceRange Range, ODRDeclDifference DiffType) { |
| 9332 | return Diag(Loc, diag::note_module_odr_violation_mismatch_decl_diff) |
| 9333 | << SecondModule << Range << DiffType; |
| 9334 | }; |
| 9335 | |
| 9336 | auto ComputeODRHash = [&Hash](const Stmt* S) { |
| 9337 | assert(S); |
| 9338 | Hash.clear(); |
| 9339 | Hash.AddStmt(S); |
| 9340 | return Hash.CalculateHash(); |
| 9341 | }; |
| 9342 | |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 9343 | auto ComputeDeclNameODRHash = [&Hash](const DeclarationName Name) { |
| 9344 | Hash.clear(); |
| 9345 | Hash.AddDeclarationName(Name); |
| 9346 | return Hash.CalculateHash(); |
| 9347 | }; |
| 9348 | |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9349 | switch (FirstDiffType) { |
| 9350 | case Other: |
| 9351 | case EndOfClass: |
| 9352 | case PublicSpecifer: |
| 9353 | case PrivateSpecifer: |
| 9354 | case ProtectedSpecifer: |
| 9355 | llvm_unreachable("Invalid diff type"); |
| 9356 | |
| 9357 | case StaticAssert: { |
| 9358 | StaticAssertDecl *FirstSA = cast<StaticAssertDecl>(FirstDecl); |
| 9359 | StaticAssertDecl *SecondSA = cast<StaticAssertDecl>(SecondDecl); |
| 9360 | |
| 9361 | Expr *FirstExpr = FirstSA->getAssertExpr(); |
| 9362 | Expr *SecondExpr = SecondSA->getAssertExpr(); |
| 9363 | unsigned FirstODRHash = ComputeODRHash(FirstExpr); |
| 9364 | unsigned SecondODRHash = ComputeODRHash(SecondExpr); |
| 9365 | if (FirstODRHash != SecondODRHash) { |
| 9366 | ODRDiagError(FirstExpr->getLocStart(), FirstExpr->getSourceRange(), |
| 9367 | StaticAssertCondition); |
| 9368 | ODRDiagNote(SecondExpr->getLocStart(), |
| 9369 | SecondExpr->getSourceRange(), StaticAssertCondition); |
| 9370 | Diagnosed = true; |
| 9371 | break; |
| 9372 | } |
| 9373 | |
| 9374 | StringLiteral *FirstStr = FirstSA->getMessage(); |
| 9375 | StringLiteral *SecondStr = SecondSA->getMessage(); |
| 9376 | assert((FirstStr || SecondStr) && "Both messages cannot be empty"); |
| 9377 | if ((FirstStr && !SecondStr) || (!FirstStr && SecondStr)) { |
| 9378 | SourceLocation FirstLoc, SecondLoc; |
| 9379 | SourceRange FirstRange, SecondRange; |
| 9380 | if (FirstStr) { |
| 9381 | FirstLoc = FirstStr->getLocStart(); |
| 9382 | FirstRange = FirstStr->getSourceRange(); |
| 9383 | } else { |
| 9384 | FirstLoc = FirstSA->getLocStart(); |
| 9385 | FirstRange = FirstSA->getSourceRange(); |
| 9386 | } |
| 9387 | if (SecondStr) { |
| 9388 | SecondLoc = SecondStr->getLocStart(); |
| 9389 | SecondRange = SecondStr->getSourceRange(); |
| 9390 | } else { |
| 9391 | SecondLoc = SecondSA->getLocStart(); |
| 9392 | SecondRange = SecondSA->getSourceRange(); |
| 9393 | } |
| 9394 | ODRDiagError(FirstLoc, FirstRange, StaticAssertOnlyMessage) |
| 9395 | << (FirstStr == nullptr); |
| 9396 | ODRDiagNote(SecondLoc, SecondRange, StaticAssertOnlyMessage) |
| 9397 | << (SecondStr == nullptr); |
| 9398 | Diagnosed = true; |
| 9399 | break; |
| 9400 | } |
| 9401 | |
| 9402 | if (FirstStr && SecondStr && |
| 9403 | FirstStr->getString() != SecondStr->getString()) { |
| 9404 | ODRDiagError(FirstStr->getLocStart(), FirstStr->getSourceRange(), |
| 9405 | StaticAssertMessage); |
| 9406 | ODRDiagNote(SecondStr->getLocStart(), SecondStr->getSourceRange(), |
| 9407 | StaticAssertMessage); |
| 9408 | Diagnosed = true; |
| 9409 | break; |
| 9410 | } |
| 9411 | break; |
| 9412 | } |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9413 | case Field: { |
| 9414 | FieldDecl *FirstField = cast<FieldDecl>(FirstDecl); |
| 9415 | FieldDecl *SecondField = cast<FieldDecl>(SecondDecl); |
| 9416 | IdentifierInfo *FirstII = FirstField->getIdentifier(); |
| 9417 | IdentifierInfo *SecondII = SecondField->getIdentifier(); |
| 9418 | if (FirstII->getName() != SecondII->getName()) { |
| 9419 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9420 | FieldName) |
| 9421 | << FirstII; |
| 9422 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9423 | FieldName) |
| 9424 | << SecondII; |
| 9425 | |
| 9426 | Diagnosed = true; |
| 9427 | break; |
| 9428 | } |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 9429 | |
| 9430 | assert( |
| 9431 | Context.hasSameType(FirstField->getType(), SecondField->getType())); |
| 9432 | |
| 9433 | QualType FirstType = FirstField->getType(); |
| 9434 | QualType SecondType = SecondField->getType(); |
| 9435 | const TypedefType *FirstTypedef = dyn_cast<TypedefType>(FirstType); |
| 9436 | const TypedefType *SecondTypedef = dyn_cast<TypedefType>(SecondType); |
| 9437 | |
| 9438 | if ((FirstTypedef && !SecondTypedef) || |
| 9439 | (!FirstTypedef && SecondTypedef)) { |
| 9440 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9441 | FieldTypeName) |
| 9442 | << FirstII << FirstType; |
| 9443 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9444 | FieldTypeName) |
| 9445 | << SecondII << SecondType; |
| 9446 | |
| 9447 | Diagnosed = true; |
| 9448 | break; |
| 9449 | } |
| 9450 | |
| 9451 | if (FirstTypedef && SecondTypedef) { |
| 9452 | unsigned FirstHash = ComputeDeclNameODRHash( |
| 9453 | FirstTypedef->getDecl()->getDeclName()); |
| 9454 | unsigned SecondHash = ComputeDeclNameODRHash( |
| 9455 | SecondTypedef->getDecl()->getDeclName()); |
| 9456 | if (FirstHash != SecondHash) { |
| 9457 | ODRDiagError(FirstField->getLocation(), |
| 9458 | FirstField->getSourceRange(), FieldTypeName) |
| 9459 | << FirstII << FirstType; |
| 9460 | ODRDiagNote(SecondField->getLocation(), |
| 9461 | SecondField->getSourceRange(), FieldTypeName) |
| 9462 | << SecondII << SecondType; |
| 9463 | |
| 9464 | Diagnosed = true; |
| 9465 | break; |
| 9466 | } |
| 9467 | } |
| 9468 | |
Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 9469 | const bool IsFirstBitField = FirstField->isBitField(); |
| 9470 | const bool IsSecondBitField = SecondField->isBitField(); |
| 9471 | if (IsFirstBitField != IsSecondBitField) { |
| 9472 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9473 | FieldSingleBitField) |
| 9474 | << FirstII << IsFirstBitField; |
| 9475 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9476 | FieldSingleBitField) |
| 9477 | << SecondII << IsSecondBitField; |
| 9478 | Diagnosed = true; |
| 9479 | break; |
| 9480 | } |
| 9481 | |
| 9482 | if (IsFirstBitField && IsSecondBitField) { |
| 9483 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9484 | FieldDifferentWidthBitField) |
| 9485 | << FirstII << FirstField->getBitWidth()->getSourceRange(); |
| 9486 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9487 | FieldDifferentWidthBitField) |
| 9488 | << SecondII << SecondField->getBitWidth()->getSourceRange(); |
| 9489 | Diagnosed = true; |
| 9490 | break; |
| 9491 | } |
| 9492 | |
Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 9493 | const bool IsFirstMutable = FirstField->isMutable(); |
| 9494 | const bool IsSecondMutable = SecondField->isMutable(); |
| 9495 | if (IsFirstMutable != IsSecondMutable) { |
| 9496 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9497 | FieldSingleMutable) |
| 9498 | << FirstII << IsFirstMutable; |
| 9499 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9500 | FieldSingleMutable) |
| 9501 | << SecondII << IsSecondMutable; |
| 9502 | Diagnosed = true; |
| 9503 | break; |
| 9504 | } |
| 9505 | |
| 9506 | const Expr *FirstInitializer = FirstField->getInClassInitializer(); |
| 9507 | const Expr *SecondInitializer = SecondField->getInClassInitializer(); |
| 9508 | if ((!FirstInitializer && SecondInitializer) || |
| 9509 | (FirstInitializer && !SecondInitializer)) { |
| 9510 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9511 | FieldSingleInitializer) |
| 9512 | << FirstII << (FirstInitializer != nullptr); |
| 9513 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9514 | FieldSingleInitializer) |
| 9515 | << SecondII << (SecondInitializer != nullptr); |
| 9516 | Diagnosed = true; |
| 9517 | break; |
| 9518 | } |
| 9519 | |
| 9520 | if (FirstInitializer && SecondInitializer) { |
| 9521 | unsigned FirstInitHash = ComputeODRHash(FirstInitializer); |
| 9522 | unsigned SecondInitHash = ComputeODRHash(SecondInitializer); |
| 9523 | if (FirstInitHash != SecondInitHash) { |
| 9524 | ODRDiagError(FirstField->getLocation(), |
| 9525 | FirstField->getSourceRange(), |
| 9526 | FieldDifferentInitializers) |
| 9527 | << FirstII << FirstInitializer->getSourceRange(); |
| 9528 | ODRDiagNote(SecondField->getLocation(), |
| 9529 | SecondField->getSourceRange(), |
| 9530 | FieldDifferentInitializers) |
| 9531 | << SecondII << SecondInitializer->getSourceRange(); |
| 9532 | Diagnosed = true; |
| 9533 | break; |
| 9534 | } |
| 9535 | } |
| 9536 | |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9537 | break; |
| 9538 | } |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9539 | case CXXMethod: { |
| 9540 | const CXXMethodDecl *FirstMethod = cast<CXXMethodDecl>(FirstDecl); |
| 9541 | const CXXMethodDecl *SecondMethod = cast<CXXMethodDecl>(SecondDecl); |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9542 | auto FirstName = FirstMethod->getDeclName(); |
| 9543 | auto SecondName = SecondMethod->getDeclName(); |
| 9544 | if (FirstName != SecondName) { |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9545 | ODRDiagError(FirstMethod->getLocation(), |
| 9546 | FirstMethod->getSourceRange(), MethodName) |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9547 | << FirstName; |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9548 | ODRDiagNote(SecondMethod->getLocation(), |
| 9549 | SecondMethod->getSourceRange(), MethodName) |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9550 | << SecondName; |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9551 | |
| 9552 | Diagnosed = true; |
| 9553 | break; |
| 9554 | } |
| 9555 | |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9556 | const bool FirstDeleted = FirstMethod->isDeleted(); |
| 9557 | const bool SecondDeleted = SecondMethod->isDeleted(); |
| 9558 | if (FirstDeleted != SecondDeleted) { |
| 9559 | ODRDiagError(FirstMethod->getLocation(), |
| 9560 | FirstMethod->getSourceRange(), MethodDeleted) |
| 9561 | << FirstName << FirstDeleted; |
| 9562 | |
| 9563 | ODRDiagNote(SecondMethod->getLocation(), |
| 9564 | SecondMethod->getSourceRange(), MethodDeleted) |
| 9565 | << SecondName << SecondDeleted; |
| 9566 | Diagnosed = true; |
| 9567 | break; |
| 9568 | } |
| 9569 | |
| 9570 | const bool FirstVirtual = FirstMethod->isVirtualAsWritten(); |
| 9571 | const bool SecondVirtual = SecondMethod->isVirtualAsWritten(); |
| 9572 | const bool FirstPure = FirstMethod->isPure(); |
| 9573 | const bool SecondPure = SecondMethod->isPure(); |
| 9574 | if ((FirstVirtual || SecondVirtual) && |
| 9575 | (FirstVirtual != SecondVirtual || FirstPure != SecondPure)) { |
| 9576 | ODRDiagError(FirstMethod->getLocation(), |
| 9577 | FirstMethod->getSourceRange(), MethodVirtual) |
| 9578 | << FirstName << FirstPure << FirstVirtual; |
| 9579 | ODRDiagNote(SecondMethod->getLocation(), |
| 9580 | SecondMethod->getSourceRange(), MethodVirtual) |
| 9581 | << SecondName << SecondPure << SecondVirtual; |
| 9582 | Diagnosed = true; |
| 9583 | break; |
| 9584 | } |
| 9585 | |
| 9586 | // CXXMethodDecl::isStatic uses the canonical Decl. With Decl merging, |
| 9587 | // FirstDecl is the canonical Decl of SecondDecl, so the storage |
| 9588 | // class needs to be checked instead. |
| 9589 | const auto FirstStorage = FirstMethod->getStorageClass(); |
| 9590 | const auto SecondStorage = SecondMethod->getStorageClass(); |
| 9591 | const bool FirstStatic = FirstStorage == SC_Static; |
| 9592 | const bool SecondStatic = SecondStorage == SC_Static; |
| 9593 | if (FirstStatic != SecondStatic) { |
| 9594 | ODRDiagError(FirstMethod->getLocation(), |
| 9595 | FirstMethod->getSourceRange(), MethodStatic) |
| 9596 | << FirstName << FirstStatic; |
| 9597 | ODRDiagNote(SecondMethod->getLocation(), |
| 9598 | SecondMethod->getSourceRange(), MethodStatic) |
| 9599 | << SecondName << SecondStatic; |
| 9600 | Diagnosed = true; |
| 9601 | break; |
| 9602 | } |
| 9603 | |
| 9604 | const bool FirstVolatile = FirstMethod->isVolatile(); |
| 9605 | const bool SecondVolatile = SecondMethod->isVolatile(); |
| 9606 | if (FirstVolatile != SecondVolatile) { |
| 9607 | ODRDiagError(FirstMethod->getLocation(), |
| 9608 | FirstMethod->getSourceRange(), MethodVolatile) |
| 9609 | << FirstName << FirstVolatile; |
| 9610 | ODRDiagNote(SecondMethod->getLocation(), |
| 9611 | SecondMethod->getSourceRange(), MethodVolatile) |
| 9612 | << SecondName << SecondVolatile; |
| 9613 | Diagnosed = true; |
| 9614 | break; |
| 9615 | } |
| 9616 | |
| 9617 | const bool FirstConst = FirstMethod->isConst(); |
| 9618 | const bool SecondConst = SecondMethod->isConst(); |
| 9619 | if (FirstConst != SecondConst) { |
| 9620 | ODRDiagError(FirstMethod->getLocation(), |
| 9621 | FirstMethod->getSourceRange(), MethodConst) |
| 9622 | << FirstName << FirstConst; |
| 9623 | ODRDiagNote(SecondMethod->getLocation(), |
| 9624 | SecondMethod->getSourceRange(), MethodConst) |
| 9625 | << SecondName << SecondConst; |
| 9626 | Diagnosed = true; |
| 9627 | break; |
| 9628 | } |
| 9629 | |
| 9630 | const bool FirstInline = FirstMethod->isInlineSpecified(); |
| 9631 | const bool SecondInline = SecondMethod->isInlineSpecified(); |
| 9632 | if (FirstInline != SecondInline) { |
| 9633 | ODRDiagError(FirstMethod->getLocation(), |
| 9634 | FirstMethod->getSourceRange(), MethodInline) |
| 9635 | << FirstName << FirstInline; |
| 9636 | ODRDiagNote(SecondMethod->getLocation(), |
| 9637 | SecondMethod->getSourceRange(), MethodInline) |
| 9638 | << SecondName << SecondInline; |
| 9639 | Diagnosed = true; |
| 9640 | break; |
| 9641 | } |
| 9642 | |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9643 | break; |
| 9644 | } |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9645 | } |
| 9646 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9647 | if (Diagnosed == true) |
| 9648 | continue; |
| 9649 | |
| 9650 | Diag(FirstRecord->getLocation(), |
| 9651 | diag::err_module_odr_violation_different_definitions) |
| 9652 | << FirstRecord << FirstModule.empty() << FirstModule; |
| 9653 | |
| 9654 | Diag(SecondRecord->getLocation(), |
| 9655 | diag::note_module_odr_violation_different_definitions) |
| 9656 | << SecondModule; |
| 9657 | Diagnosed = true; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9658 | } |
| 9659 | |
| 9660 | if (!Diagnosed) { |
| 9661 | // All definitions are updates to the same declaration. This happens if a |
| 9662 | // module instantiates the declaration of a class template specialization |
| 9663 | // and two or more other modules instantiate its definition. |
| 9664 | // |
| 9665 | // FIXME: Indicate which modules had instantiations of this definition. |
| 9666 | // FIXME: How can this even happen? |
| 9667 | Diag(Merge.first->getLocation(), |
| 9668 | diag::err_module_odr_violation_different_instantiations) |
| 9669 | << Merge.first; |
| 9670 | } |
| 9671 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9672 | } |
| 9673 | |
Richard Smith | ce18a18 | 2015-07-14 00:26:00 +0000 | [diff] [blame] | 9674 | void ASTReader::StartedDeserializing() { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 9675 | if (++NumCurrentElementsDeserializing == 1 && ReadTimer.get()) |
Richard Smith | ce18a18 | 2015-07-14 00:26:00 +0000 | [diff] [blame] | 9676 | ReadTimer->startTimer(); |
| 9677 | } |
| 9678 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9679 | void ASTReader::FinishedDeserializing() { |
| 9680 | assert(NumCurrentElementsDeserializing && |
| 9681 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 9682 | if (NumCurrentElementsDeserializing == 1) { |
| 9683 | // We decrease NumCurrentElementsDeserializing only after pending actions |
| 9684 | // are finished, to avoid recursively re-calling finishPendingActions(). |
| 9685 | finishPendingActions(); |
| 9686 | } |
| 9687 | --NumCurrentElementsDeserializing; |
| 9688 | |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9689 | if (NumCurrentElementsDeserializing == 0) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 9690 | // Propagate exception specification updates along redeclaration chains. |
Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 9691 | while (!PendingExceptionSpecUpdates.empty()) { |
| 9692 | auto Updates = std::move(PendingExceptionSpecUpdates); |
| 9693 | PendingExceptionSpecUpdates.clear(); |
| 9694 | for (auto Update : Updates) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 9695 | ProcessingUpdatesRAIIObj ProcessingUpdates(*this); |
Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 9696 | auto *FPT = Update.second->getType()->castAs<FunctionProtoType>(); |
Richard Smith | 1d0f199 | 2015-08-19 21:09:32 +0000 | [diff] [blame] | 9697 | auto ESI = FPT->getExtProtoInfo().ExceptionSpec; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 9698 | if (auto *Listener = Context.getASTMutationListener()) |
| 9699 | Listener->ResolvedExceptionSpec(cast<FunctionDecl>(Update.second)); |
Richard Smith | 1d0f199 | 2015-08-19 21:09:32 +0000 | [diff] [blame] | 9700 | for (auto *Redecl : Update.second->redecls()) |
| 9701 | Context.adjustExceptionSpec(cast<FunctionDecl>(Redecl), ESI); |
Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 9702 | } |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 9703 | } |
| 9704 | |
Richard Smith | ce18a18 | 2015-07-14 00:26:00 +0000 | [diff] [blame] | 9705 | if (ReadTimer) |
| 9706 | ReadTimer->stopTimer(); |
| 9707 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9708 | diagnoseOdrViolations(); |
| 9709 | |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 9710 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 9711 | // decls to the consumer. |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9712 | if (Consumer) |
| 9713 | PassInterestingDeclsToConsumer(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9714 | } |
| 9715 | } |
| 9716 | |
Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 9717 | void ASTReader::pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 9718 | if (IdentifierInfo *II = Name.getAsIdentifierInfo()) { |
| 9719 | // Remove any fake results before adding any real ones. |
| 9720 | auto It = PendingFakeLookupResults.find(II); |
| 9721 | if (It != PendingFakeLookupResults.end()) { |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 9722 | for (auto *ND : It->second) |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 9723 | SemaObj->IdResolver.RemoveDecl(ND); |
Ben Langmuir | eb8bd2d | 2015-04-10 22:25:42 +0000 | [diff] [blame] | 9724 | // FIXME: this works around module+PCH performance issue. |
| 9725 | // Rather than erase the result from the map, which is O(n), just clear |
| 9726 | // the vector of NamedDecls. |
| 9727 | It->second.clear(); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 9728 | } |
| 9729 | } |
Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 9730 | |
| 9731 | if (SemaObj->IdResolver.tryAddTopLevelDecl(D, Name) && SemaObj->TUScope) { |
| 9732 | SemaObj->TUScope->AddDecl(D); |
| 9733 | } else if (SemaObj->TUScope) { |
| 9734 | // Adding the decl to IdResolver may have failed because it was already in |
| 9735 | // (even though it was not added in scope). If it is already in, make sure |
| 9736 | // it gets in the scope as well. |
| 9737 | if (std::find(SemaObj->IdResolver.begin(Name), |
| 9738 | SemaObj->IdResolver.end(), D) != SemaObj->IdResolver.end()) |
| 9739 | SemaObj->TUScope->AddDecl(D); |
| 9740 | } |
| 9741 | } |
| 9742 | |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 9743 | ASTReader::ASTReader(Preprocessor &PP, ASTContext &Context, |
| 9744 | const PCHContainerReader &PCHContainerRdr, |
| 9745 | ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, |
| 9746 | StringRef isysroot, bool DisableValidation, |
| 9747 | bool AllowASTWithCompilerErrors, |
| 9748 | bool AllowConfigurationMismatch, bool ValidateSystemInputs, |
| 9749 | bool UseGlobalIndex, |
| 9750 | std::unique_ptr<llvm::Timer> ReadTimer) |
| 9751 | : Listener(DisableValidation |
| 9752 | ? cast<ASTReaderListener>(new SimpleASTReaderListener(PP)) |
| 9753 | : cast<ASTReaderListener>(new PCHValidator(PP, *this))), |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 9754 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
David Blaikie | 9d7c1ba | 2017-01-05 18:45:43 +0000 | [diff] [blame] | 9755 | PCHContainerRdr(PCHContainerRdr), Diags(PP.getDiagnostics()), PP(PP), |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 9756 | Context(Context), |
| 9757 | ModuleMgr(PP.getFileManager(), PP.getPCMCache(), PCHContainerRdr), |
| 9758 | PCMCache(PP.getPCMCache()), DummyIdResolver(PP), |
| 9759 | ReadTimer(std::move(ReadTimer)), isysroot(isysroot), |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 9760 | DisableValidation(DisableValidation), |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 9761 | AllowASTWithCompilerErrors(AllowASTWithCompilerErrors), |
| 9762 | AllowConfigurationMismatch(AllowConfigurationMismatch), |
| 9763 | ValidateSystemInputs(ValidateSystemInputs), |
David Blaikie | 9d7c1ba | 2017-01-05 18:45:43 +0000 | [diff] [blame] | 9764 | UseGlobalIndex(UseGlobalIndex), CurrSwitchCaseStmts(&SwitchCaseStmts) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9765 | SourceMgr.setExternalSLocEntrySource(this); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 9766 | |
| 9767 | for (const auto &Ext : Extensions) { |
| 9768 | auto BlockName = Ext->getExtensionMetadata().BlockName; |
| 9769 | auto Known = ModuleFileExtensions.find(BlockName); |
| 9770 | if (Known != ModuleFileExtensions.end()) { |
| 9771 | Diags.Report(diag::warn_duplicate_module_file_extension) |
| 9772 | << BlockName; |
| 9773 | continue; |
| 9774 | } |
| 9775 | |
| 9776 | ModuleFileExtensions.insert({BlockName, Ext}); |
| 9777 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9778 | } |
| 9779 | |
| 9780 | ASTReader::~ASTReader() { |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 9781 | if (OwnsDeserializationListener) |
| 9782 | delete DeserializationListener; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9783 | } |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 9784 | |
| 9785 | IdentifierResolver &ASTReader::getIdResolver() { |
| 9786 | return SemaObj ? SemaObj->IdResolver : DummyIdResolver; |
| 9787 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 9788 | |
| 9789 | unsigned ASTRecordReader::readRecord(llvm::BitstreamCursor &Cursor, |
| 9790 | unsigned AbbrevID) { |
| 9791 | Idx = 0; |
| 9792 | Record.clear(); |
| 9793 | return Cursor.readRecord(AbbrevID, Record); |
| 9794 | } |