Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1 | //===-- ASTReader.cpp - AST File Reader -----------------------------------===// |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the ASTReader class, which reads AST files. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Serialization/ASTReader.h" |
| 15 | #include "ASTCommon.h" |
| 16 | #include "ASTReaderInternals.h" |
| 17 | #include "clang/AST/ASTConsumer.h" |
| 18 | #include "clang/AST/ASTContext.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 19 | #include "clang/AST/ASTMutationListener.h" |
| 20 | #include "clang/AST/ASTUnresolvedSet.h" |
| 21 | #include "clang/AST/Decl.h" |
| 22 | #include "clang/AST/DeclCXX.h" |
| 23 | #include "clang/AST/DeclGroup.h" |
| 24 | #include "clang/AST/DeclObjC.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 25 | #include "clang/AST/DeclTemplate.h" |
| 26 | #include "clang/AST/Expr.h" |
| 27 | #include "clang/AST/ExprCXX.h" |
| 28 | #include "clang/AST/NestedNameSpecifier.h" |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 29 | #include "clang/AST/ODRHash.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 30 | #include "clang/AST/RawCommentList.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 31 | #include "clang/AST/Type.h" |
| 32 | #include "clang/AST/TypeLocVisitor.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 33 | #include "clang/AST/UnresolvedSet.h" |
| 34 | #include "clang/Basic/CommentOptions.h" |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 35 | #include "clang/Basic/DiagnosticOptions.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 36 | #include "clang/Basic/ExceptionSpecificationType.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 37 | #include "clang/Basic/FileManager.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 38 | #include "clang/Basic/FileSystemOptions.h" |
| 39 | #include "clang/Basic/LangOptions.h" |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 40 | #include "clang/Basic/MemoryBufferCache.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 41 | #include "clang/Basic/ObjCRuntime.h" |
| 42 | #include "clang/Basic/OperatorKinds.h" |
| 43 | #include "clang/Basic/Sanitizers.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 44 | #include "clang/Basic/SourceManager.h" |
| 45 | #include "clang/Basic/SourceManagerInternals.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 46 | #include "clang/Basic/Specifiers.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 47 | #include "clang/Basic/TargetInfo.h" |
| 48 | #include "clang/Basic/TargetOptions.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 49 | #include "clang/Basic/TokenKinds.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 50 | #include "clang/Basic/Version.h" |
| 51 | #include "clang/Basic/VersionTuple.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 52 | #include "clang/Frontend/PCHContainerOperations.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 53 | #include "clang/Lex/HeaderSearch.h" |
| 54 | #include "clang/Lex/HeaderSearchOptions.h" |
| 55 | #include "clang/Lex/MacroInfo.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 56 | #include "clang/Lex/ModuleMap.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 57 | #include "clang/Lex/PreprocessingRecord.h" |
| 58 | #include "clang/Lex/Preprocessor.h" |
| 59 | #include "clang/Lex/PreprocessorOptions.h" |
| 60 | #include "clang/Sema/Scope.h" |
| 61 | #include "clang/Sema/Sema.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 62 | #include "clang/Sema/Weak.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 63 | #include "clang/Serialization/ASTDeserializationListener.h" |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 64 | #include "clang/Serialization/GlobalModuleIndex.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 65 | #include "clang/Serialization/ModuleManager.h" |
| 66 | #include "clang/Serialization/SerializationDiagnostic.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 67 | #include "llvm/ADT/APFloat.h" |
| 68 | #include "llvm/ADT/APInt.h" |
| 69 | #include "llvm/ADT/APSInt.h" |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 70 | #include "llvm/ADT/Hashing.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 71 | #include "llvm/ADT/SmallString.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 72 | #include "llvm/ADT/StringExtras.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 73 | #include "llvm/ADT/Triple.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 74 | #include "llvm/Bitcode/BitstreamReader.h" |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 75 | #include "llvm/Support/Compression.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 76 | #include "llvm/Support/Compiler.h" |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 77 | #include "llvm/Support/Error.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 78 | #include "llvm/Support/ErrorHandling.h" |
| 79 | #include "llvm/Support/FileSystem.h" |
| 80 | #include "llvm/Support/MemoryBuffer.h" |
| 81 | #include "llvm/Support/Path.h" |
| 82 | #include "llvm/Support/SaveAndRestore.h" |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 83 | #include "llvm/Support/raw_ostream.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 84 | #include <algorithm> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 85 | #include <cassert> |
| 86 | #include <cstdint> |
Chris Lattner | 91f373e | 2013-01-20 00:57:52 +0000 | [diff] [blame] | 87 | #include <cstdio> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 88 | #include <cstring> |
| 89 | #include <ctime> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 90 | #include <iterator> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 91 | #include <limits> |
| 92 | #include <map> |
| 93 | #include <memory> |
| 94 | #include <new> |
| 95 | #include <string> |
Rafael Espindola | 8a8e554 | 2014-06-12 17:19:42 +0000 | [diff] [blame] | 96 | #include <system_error> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 97 | #include <tuple> |
| 98 | #include <utility> |
| 99 | #include <vector> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 100 | |
| 101 | using namespace clang; |
| 102 | using namespace clang::serialization; |
| 103 | using namespace clang::serialization::reader; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 104 | using llvm::BitstreamCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 105 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 106 | //===----------------------------------------------------------------------===// |
| 107 | // ChainedASTReaderListener implementation |
| 108 | //===----------------------------------------------------------------------===// |
| 109 | |
| 110 | bool |
| 111 | ChainedASTReaderListener::ReadFullVersionInformation(StringRef FullVersion) { |
| 112 | return First->ReadFullVersionInformation(FullVersion) || |
| 113 | Second->ReadFullVersionInformation(FullVersion); |
| 114 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 115 | |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 116 | void ChainedASTReaderListener::ReadModuleName(StringRef ModuleName) { |
| 117 | First->ReadModuleName(ModuleName); |
| 118 | Second->ReadModuleName(ModuleName); |
| 119 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 120 | |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 121 | void ChainedASTReaderListener::ReadModuleMapFile(StringRef ModuleMapPath) { |
| 122 | First->ReadModuleMapFile(ModuleMapPath); |
| 123 | Second->ReadModuleMapFile(ModuleMapPath); |
| 124 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 125 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 126 | bool |
| 127 | ChainedASTReaderListener::ReadLanguageOptions(const LangOptions &LangOpts, |
| 128 | bool Complain, |
| 129 | bool AllowCompatibleDifferences) { |
| 130 | return First->ReadLanguageOptions(LangOpts, Complain, |
| 131 | AllowCompatibleDifferences) || |
| 132 | Second->ReadLanguageOptions(LangOpts, Complain, |
| 133 | AllowCompatibleDifferences); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 134 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 135 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 136 | bool ChainedASTReaderListener::ReadTargetOptions( |
| 137 | const TargetOptions &TargetOpts, bool Complain, |
| 138 | bool AllowCompatibleDifferences) { |
| 139 | return First->ReadTargetOptions(TargetOpts, Complain, |
| 140 | AllowCompatibleDifferences) || |
| 141 | Second->ReadTargetOptions(TargetOpts, Complain, |
| 142 | AllowCompatibleDifferences); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 143 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 144 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 145 | bool ChainedASTReaderListener::ReadDiagnosticOptions( |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 146 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) { |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 147 | return First->ReadDiagnosticOptions(DiagOpts, Complain) || |
| 148 | Second->ReadDiagnosticOptions(DiagOpts, Complain); |
| 149 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 150 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 151 | bool |
| 152 | ChainedASTReaderListener::ReadFileSystemOptions(const FileSystemOptions &FSOpts, |
| 153 | bool Complain) { |
| 154 | return First->ReadFileSystemOptions(FSOpts, Complain) || |
| 155 | Second->ReadFileSystemOptions(FSOpts, Complain); |
| 156 | } |
| 157 | |
| 158 | bool ChainedASTReaderListener::ReadHeaderSearchOptions( |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 159 | const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, |
| 160 | bool Complain) { |
| 161 | return First->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 162 | Complain) || |
| 163 | Second->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 164 | Complain); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 165 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 166 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 167 | bool ChainedASTReaderListener::ReadPreprocessorOptions( |
| 168 | const PreprocessorOptions &PPOpts, bool Complain, |
| 169 | std::string &SuggestedPredefines) { |
| 170 | return First->ReadPreprocessorOptions(PPOpts, Complain, |
| 171 | SuggestedPredefines) || |
| 172 | Second->ReadPreprocessorOptions(PPOpts, Complain, SuggestedPredefines); |
| 173 | } |
| 174 | void ChainedASTReaderListener::ReadCounter(const serialization::ModuleFile &M, |
| 175 | unsigned Value) { |
| 176 | First->ReadCounter(M, Value); |
| 177 | Second->ReadCounter(M, Value); |
| 178 | } |
| 179 | bool ChainedASTReaderListener::needsInputFileVisitation() { |
| 180 | return First->needsInputFileVisitation() || |
| 181 | Second->needsInputFileVisitation(); |
| 182 | } |
| 183 | bool ChainedASTReaderListener::needsSystemInputFileVisitation() { |
| 184 | return First->needsSystemInputFileVisitation() || |
| 185 | Second->needsSystemInputFileVisitation(); |
| 186 | } |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 187 | void ChainedASTReaderListener::visitModuleFile(StringRef Filename, |
| 188 | ModuleKind Kind) { |
| 189 | First->visitModuleFile(Filename, Kind); |
| 190 | Second->visitModuleFile(Filename, Kind); |
Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 191 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 192 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 193 | bool ChainedASTReaderListener::visitInputFile(StringRef Filename, |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 194 | bool isSystem, |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 195 | bool isOverridden, |
| 196 | bool isExplicitModule) { |
Justin Bogner | c65a66d | 2014-05-22 06:04:59 +0000 | [diff] [blame] | 197 | bool Continue = false; |
| 198 | if (First->needsInputFileVisitation() && |
| 199 | (!isSystem || First->needsSystemInputFileVisitation())) |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 200 | Continue |= First->visitInputFile(Filename, isSystem, isOverridden, |
| 201 | isExplicitModule); |
Justin Bogner | c65a66d | 2014-05-22 06:04:59 +0000 | [diff] [blame] | 202 | if (Second->needsInputFileVisitation() && |
| 203 | (!isSystem || Second->needsSystemInputFileVisitation())) |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 204 | Continue |= Second->visitInputFile(Filename, isSystem, isOverridden, |
| 205 | isExplicitModule); |
Justin Bogner | c65a66d | 2014-05-22 06:04:59 +0000 | [diff] [blame] | 206 | return Continue; |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 209 | void ChainedASTReaderListener::readModuleFileExtension( |
| 210 | const ModuleFileExtensionMetadata &Metadata) { |
| 211 | First->readModuleFileExtension(Metadata); |
| 212 | Second->readModuleFileExtension(Metadata); |
| 213 | } |
| 214 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 215 | //===----------------------------------------------------------------------===// |
| 216 | // PCH validator implementation |
| 217 | //===----------------------------------------------------------------------===// |
| 218 | |
Angel Garcia Gomez | 637d1e6 | 2015-10-20 13:23:58 +0000 | [diff] [blame] | 219 | ASTReaderListener::~ASTReaderListener() {} |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 220 | |
| 221 | /// \brief Compare the given set of language options against an existing set of |
| 222 | /// language options. |
| 223 | /// |
| 224 | /// \param Diags If non-NULL, diagnostics will be emitted via this engine. |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 225 | /// \param AllowCompatibleDifferences If true, differences between compatible |
| 226 | /// language options will be permitted. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 227 | /// |
| 228 | /// \returns true if the languagae options mis-match, false otherwise. |
| 229 | static bool checkLanguageOptions(const LangOptions &LangOpts, |
| 230 | const LangOptions &ExistingLangOpts, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 231 | DiagnosticsEngine *Diags, |
| 232 | bool AllowCompatibleDifferences = true) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 233 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 234 | if (ExistingLangOpts.Name != LangOpts.Name) { \ |
| 235 | if (Diags) \ |
| 236 | Diags->Report(diag::err_pch_langopt_mismatch) \ |
| 237 | << Description << LangOpts.Name << ExistingLangOpts.Name; \ |
| 238 | return true; \ |
| 239 | } |
| 240 | |
| 241 | #define VALUE_LANGOPT(Name, Bits, Default, Description) \ |
| 242 | if (ExistingLangOpts.Name != LangOpts.Name) { \ |
| 243 | if (Diags) \ |
| 244 | Diags->Report(diag::err_pch_langopt_value_mismatch) \ |
| 245 | << Description; \ |
| 246 | return true; \ |
| 247 | } |
| 248 | |
| 249 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 250 | if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \ |
| 251 | if (Diags) \ |
| 252 | Diags->Report(diag::err_pch_langopt_value_mismatch) \ |
| 253 | << Description; \ |
| 254 | return true; \ |
| 255 | } |
| 256 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 257 | #define COMPATIBLE_LANGOPT(Name, Bits, Default, Description) \ |
| 258 | if (!AllowCompatibleDifferences) \ |
| 259 | LANGOPT(Name, Bits, Default, Description) |
| 260 | |
| 261 | #define COMPATIBLE_ENUM_LANGOPT(Name, Bits, Default, Description) \ |
| 262 | if (!AllowCompatibleDifferences) \ |
| 263 | ENUM_LANGOPT(Name, Bits, Default, Description) |
| 264 | |
Richard Smith | a1ddf5e | 2016-04-07 20:47:37 +0000 | [diff] [blame] | 265 | #define COMPATIBLE_VALUE_LANGOPT(Name, Bits, Default, Description) \ |
| 266 | if (!AllowCompatibleDifferences) \ |
| 267 | VALUE_LANGOPT(Name, Bits, Default, Description) |
| 268 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 269 | #define BENIGN_LANGOPT(Name, Bits, Default, Description) |
| 270 | #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) |
Richard Smith | a1ddf5e | 2016-04-07 20:47:37 +0000 | [diff] [blame] | 271 | #define BENIGN_VALUE_LANGOPT(Name, Type, Bits, Default, Description) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 272 | #include "clang/Basic/LangOptions.def" |
| 273 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 274 | if (ExistingLangOpts.ModuleFeatures != LangOpts.ModuleFeatures) { |
| 275 | if (Diags) |
| 276 | Diags->Report(diag::err_pch_langopt_value_mismatch) << "module features"; |
| 277 | return true; |
| 278 | } |
| 279 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 280 | if (ExistingLangOpts.ObjCRuntime != LangOpts.ObjCRuntime) { |
| 281 | if (Diags) |
| 282 | Diags->Report(diag::err_pch_langopt_value_mismatch) |
| 283 | << "target Objective-C runtime"; |
| 284 | return true; |
| 285 | } |
| 286 | |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 287 | if (ExistingLangOpts.CommentOpts.BlockCommandNames != |
| 288 | LangOpts.CommentOpts.BlockCommandNames) { |
| 289 | if (Diags) |
| 290 | Diags->Report(diag::err_pch_langopt_value_mismatch) |
| 291 | << "block command names"; |
| 292 | return true; |
| 293 | } |
| 294 | |
Vedant Kumar | 85a83c2 | 2017-06-01 20:01:01 +0000 | [diff] [blame] | 295 | // Sanitizer feature mismatches are treated as compatible differences. If |
| 296 | // compatible differences aren't allowed, we still only want to check for |
| 297 | // mismatches of non-modular sanitizers (the only ones which can affect AST |
| 298 | // generation). |
| 299 | if (!AllowCompatibleDifferences) { |
| 300 | SanitizerMask ModularSanitizers = getPPTransparentSanitizers(); |
| 301 | SanitizerSet ExistingSanitizers = ExistingLangOpts.Sanitize; |
| 302 | SanitizerSet ImportedSanitizers = LangOpts.Sanitize; |
| 303 | ExistingSanitizers.clear(ModularSanitizers); |
| 304 | ImportedSanitizers.clear(ModularSanitizers); |
| 305 | if (ExistingSanitizers.Mask != ImportedSanitizers.Mask) { |
| 306 | const std::string Flag = "-fsanitize="; |
| 307 | if (Diags) { |
| 308 | #define SANITIZER(NAME, ID) \ |
| 309 | { \ |
| 310 | bool InExistingModule = ExistingSanitizers.has(SanitizerKind::ID); \ |
| 311 | bool InImportedModule = ImportedSanitizers.has(SanitizerKind::ID); \ |
| 312 | if (InExistingModule != InImportedModule) \ |
| 313 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) \ |
| 314 | << InExistingModule << (Flag + NAME); \ |
| 315 | } |
| 316 | #include "clang/Basic/Sanitizers.def" |
| 317 | } |
| 318 | return true; |
| 319 | } |
| 320 | } |
| 321 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 322 | return false; |
| 323 | } |
| 324 | |
| 325 | /// \brief Compare the given set of target options against an existing set of |
| 326 | /// target options. |
| 327 | /// |
| 328 | /// \param Diags If non-NULL, diagnostics will be emitted via this engine. |
| 329 | /// |
| 330 | /// \returns true if the target options mis-match, false otherwise. |
| 331 | static bool checkTargetOptions(const TargetOptions &TargetOpts, |
| 332 | const TargetOptions &ExistingTargetOpts, |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 333 | DiagnosticsEngine *Diags, |
| 334 | bool AllowCompatibleDifferences = true) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 335 | #define CHECK_TARGET_OPT(Field, Name) \ |
| 336 | if (TargetOpts.Field != ExistingTargetOpts.Field) { \ |
| 337 | if (Diags) \ |
| 338 | Diags->Report(diag::err_pch_targetopt_mismatch) \ |
| 339 | << Name << TargetOpts.Field << ExistingTargetOpts.Field; \ |
| 340 | return true; \ |
| 341 | } |
| 342 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 343 | // The triple and ABI must match exactly. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 344 | CHECK_TARGET_OPT(Triple, "target"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 345 | CHECK_TARGET_OPT(ABI, "target ABI"); |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 346 | |
| 347 | // We can tolerate different CPUs in many cases, notably when one CPU |
| 348 | // supports a strict superset of another. When allowing compatible |
| 349 | // differences skip this check. |
| 350 | if (!AllowCompatibleDifferences) |
| 351 | CHECK_TARGET_OPT(CPU, "target CPU"); |
| 352 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 353 | #undef CHECK_TARGET_OPT |
| 354 | |
| 355 | // Compare feature sets. |
| 356 | SmallVector<StringRef, 4> ExistingFeatures( |
| 357 | ExistingTargetOpts.FeaturesAsWritten.begin(), |
| 358 | ExistingTargetOpts.FeaturesAsWritten.end()); |
| 359 | SmallVector<StringRef, 4> ReadFeatures(TargetOpts.FeaturesAsWritten.begin(), |
| 360 | TargetOpts.FeaturesAsWritten.end()); |
| 361 | std::sort(ExistingFeatures.begin(), ExistingFeatures.end()); |
| 362 | std::sort(ReadFeatures.begin(), ReadFeatures.end()); |
| 363 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 364 | // We compute the set difference in both directions explicitly so that we can |
| 365 | // diagnose the differences differently. |
| 366 | SmallVector<StringRef, 4> UnmatchedExistingFeatures, UnmatchedReadFeatures; |
| 367 | std::set_difference( |
| 368 | ExistingFeatures.begin(), ExistingFeatures.end(), ReadFeatures.begin(), |
| 369 | ReadFeatures.end(), std::back_inserter(UnmatchedExistingFeatures)); |
| 370 | std::set_difference(ReadFeatures.begin(), ReadFeatures.end(), |
| 371 | ExistingFeatures.begin(), ExistingFeatures.end(), |
| 372 | std::back_inserter(UnmatchedReadFeatures)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 373 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 374 | // If we are allowing compatible differences and the read feature set is |
| 375 | // a strict subset of the existing feature set, there is nothing to diagnose. |
| 376 | if (AllowCompatibleDifferences && UnmatchedReadFeatures.empty()) |
| 377 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 378 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 379 | if (Diags) { |
| 380 | for (StringRef Feature : UnmatchedReadFeatures) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 381 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 382 | << /* is-existing-feature */ false << Feature; |
| 383 | for (StringRef Feature : UnmatchedExistingFeatures) |
| 384 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
| 385 | << /* is-existing-feature */ true << Feature; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 386 | } |
| 387 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 388 | return !UnmatchedReadFeatures.empty() || !UnmatchedExistingFeatures.empty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | bool |
| 392 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 393 | bool Complain, |
| 394 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 395 | const LangOptions &ExistingLangOpts = PP.getLangOpts(); |
| 396 | return checkLanguageOptions(LangOpts, ExistingLangOpts, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 397 | Complain ? &Reader.Diags : nullptr, |
| 398 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | bool PCHValidator::ReadTargetOptions(const TargetOptions &TargetOpts, |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 402 | bool Complain, |
| 403 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 404 | const TargetOptions &ExistingTargetOpts = PP.getTargetInfo().getTargetOpts(); |
| 405 | return checkTargetOptions(TargetOpts, ExistingTargetOpts, |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 406 | Complain ? &Reader.Diags : nullptr, |
| 407 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 411 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 412 | typedef llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> > |
| 413 | MacroDefinitionsMap; |
Craig Topper | 3598eb7 | 2013-07-05 04:43:31 +0000 | [diff] [blame] | 414 | typedef llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8> > |
| 415 | DeclsMap; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 416 | |
| 417 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 418 | |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 419 | static bool checkDiagnosticGroupMappings(DiagnosticsEngine &StoredDiags, |
| 420 | DiagnosticsEngine &Diags, |
| 421 | bool Complain) { |
| 422 | typedef DiagnosticsEngine::Level Level; |
| 423 | |
| 424 | // Check current mappings for new -Werror mappings, and the stored mappings |
| 425 | // for cases that were explicitly mapped to *not* be errors that are now |
| 426 | // errors because of options like -Werror. |
| 427 | DiagnosticsEngine *MappingSources[] = { &Diags, &StoredDiags }; |
| 428 | |
| 429 | for (DiagnosticsEngine *MappingSource : MappingSources) { |
| 430 | for (auto DiagIDMappingPair : MappingSource->getDiagnosticMappings()) { |
| 431 | diag::kind DiagID = DiagIDMappingPair.first; |
| 432 | Level CurLevel = Diags.getDiagnosticLevel(DiagID, SourceLocation()); |
| 433 | if (CurLevel < DiagnosticsEngine::Error) |
| 434 | continue; // not significant |
| 435 | Level StoredLevel = |
| 436 | StoredDiags.getDiagnosticLevel(DiagID, SourceLocation()); |
| 437 | if (StoredLevel < DiagnosticsEngine::Error) { |
| 438 | if (Complain) |
| 439 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror=" + |
| 440 | Diags.getDiagnosticIDs()->getWarningOptionForDiag(DiagID).str(); |
| 441 | return true; |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | return false; |
| 447 | } |
| 448 | |
Alp Toker | ac4e8e5 | 2014-06-22 21:58:33 +0000 | [diff] [blame] | 449 | static bool isExtHandlingFromDiagsError(DiagnosticsEngine &Diags) { |
| 450 | diag::Severity Ext = Diags.getExtensionHandlingBehavior(); |
| 451 | if (Ext == diag::Severity::Warning && Diags.getWarningsAsErrors()) |
| 452 | return true; |
| 453 | return Ext >= diag::Severity::Error; |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | static bool checkDiagnosticMappings(DiagnosticsEngine &StoredDiags, |
| 457 | DiagnosticsEngine &Diags, |
| 458 | bool IsSystem, bool Complain) { |
| 459 | // Top-level options |
| 460 | if (IsSystem) { |
| 461 | if (Diags.getSuppressSystemWarnings()) |
| 462 | return false; |
| 463 | // If -Wsystem-headers was not enabled before, be conservative |
| 464 | if (StoredDiags.getSuppressSystemWarnings()) { |
| 465 | if (Complain) |
| 466 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Wsystem-headers"; |
| 467 | return true; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | if (Diags.getWarningsAsErrors() && !StoredDiags.getWarningsAsErrors()) { |
| 472 | if (Complain) |
| 473 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror"; |
| 474 | return true; |
| 475 | } |
| 476 | |
| 477 | if (Diags.getWarningsAsErrors() && Diags.getEnableAllWarnings() && |
| 478 | !StoredDiags.getEnableAllWarnings()) { |
| 479 | if (Complain) |
| 480 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Weverything -Werror"; |
| 481 | return true; |
| 482 | } |
| 483 | |
| 484 | if (isExtHandlingFromDiagsError(Diags) && |
| 485 | !isExtHandlingFromDiagsError(StoredDiags)) { |
| 486 | if (Complain) |
| 487 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-pedantic-errors"; |
| 488 | return true; |
| 489 | } |
| 490 | |
| 491 | return checkDiagnosticGroupMappings(StoredDiags, Diags, Complain); |
| 492 | } |
| 493 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 494 | /// Return the top import module if it is implicit, nullptr otherwise. |
| 495 | static Module *getTopImportImplicitModule(ModuleManager &ModuleMgr, |
| 496 | Preprocessor &PP) { |
| 497 | // If the original import came from a file explicitly generated by the user, |
| 498 | // don't check the diagnostic mappings. |
| 499 | // FIXME: currently this is approximated by checking whether this is not a |
| 500 | // module import of an implicitly-loaded module file. |
| 501 | // Note: ModuleMgr.rbegin() may not be the current module, but it must be in |
| 502 | // the transitive closure of its imports, since unrelated modules cannot be |
| 503 | // imported until after this module finishes validation. |
| 504 | ModuleFile *TopImport = &*ModuleMgr.rbegin(); |
| 505 | while (!TopImport->ImportedBy.empty()) |
| 506 | TopImport = TopImport->ImportedBy[0]; |
| 507 | if (TopImport->Kind != MK_ImplicitModule) |
| 508 | return nullptr; |
| 509 | |
| 510 | StringRef ModuleName = TopImport->ModuleName; |
| 511 | assert(!ModuleName.empty() && "diagnostic options read before module name"); |
| 512 | |
| 513 | Module *M = PP.getHeaderSearchInfo().lookupModule(ModuleName); |
| 514 | assert(M && "missing module"); |
| 515 | return M; |
| 516 | } |
| 517 | |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 518 | bool PCHValidator::ReadDiagnosticOptions( |
| 519 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) { |
| 520 | DiagnosticsEngine &ExistingDiags = PP.getDiagnostics(); |
| 521 | IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(ExistingDiags.getDiagnosticIDs()); |
| 522 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags( |
Alp Toker | f994cef | 2014-07-05 03:08:06 +0000 | [diff] [blame] | 523 | new DiagnosticsEngine(DiagIDs, DiagOpts.get())); |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 524 | // This should never fail, because we would have processed these options |
| 525 | // before writing them to an ASTFile. |
| 526 | ProcessWarningOptions(*Diags, *DiagOpts, /*Report*/false); |
| 527 | |
| 528 | ModuleManager &ModuleMgr = Reader.getModuleManager(); |
| 529 | assert(ModuleMgr.size() >= 1 && "what ASTFile is this then"); |
| 530 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 531 | Module *TopM = getTopImportImplicitModule(ModuleMgr, PP); |
| 532 | if (!TopM) |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 533 | return false; |
| 534 | |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 535 | // FIXME: if the diagnostics are incompatible, save a DiagnosticOptions that |
| 536 | // contains the union of their flags. |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 537 | return checkDiagnosticMappings(*Diags, ExistingDiags, TopM->IsSystem, |
| 538 | Complain); |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 539 | } |
| 540 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 541 | /// \brief Collect the macro definitions provided by the given preprocessor |
| 542 | /// options. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 543 | static void |
| 544 | collectMacroDefinitions(const PreprocessorOptions &PPOpts, |
| 545 | MacroDefinitionsMap &Macros, |
| 546 | SmallVectorImpl<StringRef> *MacroNames = nullptr) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 547 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 548 | StringRef Macro = PPOpts.Macros[I].first; |
| 549 | bool IsUndef = PPOpts.Macros[I].second; |
| 550 | |
| 551 | std::pair<StringRef, StringRef> MacroPair = Macro.split('='); |
| 552 | StringRef MacroName = MacroPair.first; |
| 553 | StringRef MacroBody = MacroPair.second; |
| 554 | |
| 555 | // For an #undef'd macro, we only care about the name. |
| 556 | if (IsUndef) { |
| 557 | if (MacroNames && !Macros.count(MacroName)) |
| 558 | MacroNames->push_back(MacroName); |
| 559 | |
| 560 | Macros[MacroName] = std::make_pair("", true); |
| 561 | continue; |
| 562 | } |
| 563 | |
| 564 | // For a #define'd macro, figure out the actual definition. |
| 565 | if (MacroName.size() == Macro.size()) |
| 566 | MacroBody = "1"; |
| 567 | else { |
| 568 | // Note: GCC drops anything following an end-of-line character. |
| 569 | StringRef::size_type End = MacroBody.find_first_of("\n\r"); |
| 570 | MacroBody = MacroBody.substr(0, End); |
| 571 | } |
| 572 | |
| 573 | if (MacroNames && !Macros.count(MacroName)) |
| 574 | MacroNames->push_back(MacroName); |
| 575 | Macros[MacroName] = std::make_pair(MacroBody, false); |
| 576 | } |
| 577 | } |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 578 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 579 | /// \brief Check the preprocessor options deserialized from the control block |
| 580 | /// against the preprocessor options in an existing preprocessor. |
| 581 | /// |
| 582 | /// \param Diags If non-null, produce diagnostics for any mismatches incurred. |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 583 | /// \param Validate If true, validate preprocessor options. If false, allow |
| 584 | /// macros defined by \p ExistingPPOpts to override those defined by |
| 585 | /// \p PPOpts in SuggestedPredefines. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 586 | static bool checkPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 587 | const PreprocessorOptions &ExistingPPOpts, |
| 588 | DiagnosticsEngine *Diags, |
| 589 | FileManager &FileMgr, |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 590 | std::string &SuggestedPredefines, |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 591 | const LangOptions &LangOpts, |
| 592 | bool Validate = true) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 593 | // Check macro definitions. |
| 594 | MacroDefinitionsMap ASTFileMacros; |
| 595 | collectMacroDefinitions(PPOpts, ASTFileMacros); |
| 596 | MacroDefinitionsMap ExistingMacros; |
| 597 | SmallVector<StringRef, 4> ExistingMacroNames; |
| 598 | collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames); |
| 599 | |
| 600 | for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) { |
| 601 | // Dig out the macro definition in the existing preprocessor options. |
| 602 | StringRef MacroName = ExistingMacroNames[I]; |
| 603 | std::pair<StringRef, bool> Existing = ExistingMacros[MacroName]; |
| 604 | |
| 605 | // Check whether we know anything about this macro name or not. |
| 606 | llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/> >::iterator Known |
| 607 | = ASTFileMacros.find(MacroName); |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 608 | if (!Validate || Known == ASTFileMacros.end()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 609 | // FIXME: Check whether this identifier was referenced anywhere in the |
| 610 | // AST file. If so, we should reject the AST file. Unfortunately, this |
| 611 | // information isn't in the control block. What shall we do about it? |
| 612 | |
| 613 | if (Existing.second) { |
| 614 | SuggestedPredefines += "#undef "; |
| 615 | SuggestedPredefines += MacroName.str(); |
| 616 | SuggestedPredefines += '\n'; |
| 617 | } else { |
| 618 | SuggestedPredefines += "#define "; |
| 619 | SuggestedPredefines += MacroName.str(); |
| 620 | SuggestedPredefines += ' '; |
| 621 | SuggestedPredefines += Existing.first.str(); |
| 622 | SuggestedPredefines += '\n'; |
| 623 | } |
| 624 | continue; |
| 625 | } |
| 626 | |
| 627 | // If the macro was defined in one but undef'd in the other, we have a |
| 628 | // conflict. |
| 629 | if (Existing.second != Known->second.second) { |
| 630 | if (Diags) { |
| 631 | Diags->Report(diag::err_pch_macro_def_undef) |
| 632 | << MacroName << Known->second.second; |
| 633 | } |
| 634 | return true; |
| 635 | } |
| 636 | |
| 637 | // If the macro was #undef'd in both, or if the macro bodies are identical, |
| 638 | // it's fine. |
| 639 | if (Existing.second || Existing.first == Known->second.first) |
| 640 | continue; |
| 641 | |
| 642 | // The macro bodies differ; complain. |
| 643 | if (Diags) { |
| 644 | Diags->Report(diag::err_pch_macro_def_conflict) |
| 645 | << MacroName << Known->second.first << Existing.first; |
| 646 | } |
| 647 | return true; |
| 648 | } |
| 649 | |
| 650 | // Check whether we're using predefines. |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 651 | if (PPOpts.UsePredefines != ExistingPPOpts.UsePredefines && Validate) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 652 | if (Diags) { |
| 653 | Diags->Report(diag::err_pch_undef) << ExistingPPOpts.UsePredefines; |
| 654 | } |
| 655 | return true; |
| 656 | } |
| 657 | |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 658 | // Detailed record is important since it is used for the module cache hash. |
| 659 | if (LangOpts.Modules && |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 660 | PPOpts.DetailedRecord != ExistingPPOpts.DetailedRecord && Validate) { |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 661 | if (Diags) { |
| 662 | Diags->Report(diag::err_pch_pp_detailed_record) << PPOpts.DetailedRecord; |
| 663 | } |
| 664 | return true; |
| 665 | } |
| 666 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 667 | // Compute the #include and #include_macros lines we need. |
| 668 | for (unsigned I = 0, N = ExistingPPOpts.Includes.size(); I != N; ++I) { |
| 669 | StringRef File = ExistingPPOpts.Includes[I]; |
| 670 | if (File == ExistingPPOpts.ImplicitPCHInclude) |
| 671 | continue; |
| 672 | |
| 673 | if (std::find(PPOpts.Includes.begin(), PPOpts.Includes.end(), File) |
| 674 | != PPOpts.Includes.end()) |
| 675 | continue; |
| 676 | |
| 677 | SuggestedPredefines += "#include \""; |
Manuel Klimek | 9af34ae | 2014-08-12 08:25:57 +0000 | [diff] [blame] | 678 | SuggestedPredefines += File; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 679 | SuggestedPredefines += "\"\n"; |
| 680 | } |
| 681 | |
| 682 | for (unsigned I = 0, N = ExistingPPOpts.MacroIncludes.size(); I != N; ++I) { |
| 683 | StringRef File = ExistingPPOpts.MacroIncludes[I]; |
| 684 | if (std::find(PPOpts.MacroIncludes.begin(), PPOpts.MacroIncludes.end(), |
| 685 | File) |
| 686 | != PPOpts.MacroIncludes.end()) |
| 687 | continue; |
| 688 | |
| 689 | SuggestedPredefines += "#__include_macros \""; |
Manuel Klimek | 9af34ae | 2014-08-12 08:25:57 +0000 | [diff] [blame] | 690 | SuggestedPredefines += File; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 691 | SuggestedPredefines += "\"\n##\n"; |
| 692 | } |
| 693 | |
| 694 | return false; |
| 695 | } |
| 696 | |
| 697 | bool PCHValidator::ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 698 | bool Complain, |
| 699 | std::string &SuggestedPredefines) { |
| 700 | const PreprocessorOptions &ExistingPPOpts = PP.getPreprocessorOpts(); |
| 701 | |
| 702 | return checkPreprocessorOptions(PPOpts, ExistingPPOpts, |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 703 | Complain? &Reader.Diags : nullptr, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 704 | PP.getFileManager(), |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 705 | SuggestedPredefines, |
| 706 | PP.getLangOpts()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 707 | } |
| 708 | |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 709 | bool SimpleASTReaderListener::ReadPreprocessorOptions( |
| 710 | const PreprocessorOptions &PPOpts, |
| 711 | bool Complain, |
| 712 | std::string &SuggestedPredefines) { |
| 713 | return checkPreprocessorOptions(PPOpts, |
| 714 | PP.getPreprocessorOpts(), |
| 715 | nullptr, |
| 716 | PP.getFileManager(), |
| 717 | SuggestedPredefines, |
| 718 | PP.getLangOpts(), |
| 719 | false); |
| 720 | } |
| 721 | |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 722 | /// Check the header search options deserialized from the control block |
| 723 | /// against the header search options in an existing preprocessor. |
| 724 | /// |
| 725 | /// \param Diags If non-null, produce diagnostics for any mismatches incurred. |
| 726 | static bool checkHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 727 | StringRef SpecificModuleCachePath, |
| 728 | StringRef ExistingModuleCachePath, |
| 729 | DiagnosticsEngine *Diags, |
| 730 | const LangOptions &LangOpts) { |
| 731 | if (LangOpts.Modules) { |
| 732 | if (SpecificModuleCachePath != ExistingModuleCachePath) { |
| 733 | if (Diags) |
| 734 | Diags->Report(diag::err_pch_modulecache_mismatch) |
| 735 | << SpecificModuleCachePath << ExistingModuleCachePath; |
| 736 | return true; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | return false; |
| 741 | } |
| 742 | |
| 743 | bool PCHValidator::ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 744 | StringRef SpecificModuleCachePath, |
| 745 | bool Complain) { |
| 746 | return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 747 | PP.getHeaderSearchInfo().getModuleCachePath(), |
| 748 | Complain ? &Reader.Diags : nullptr, |
| 749 | PP.getLangOpts()); |
| 750 | } |
| 751 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 752 | void PCHValidator::ReadCounter(const ModuleFile &M, unsigned Value) { |
| 753 | PP.setCounterValue(Value); |
| 754 | } |
| 755 | |
| 756 | //===----------------------------------------------------------------------===// |
| 757 | // AST reader implementation |
| 758 | //===----------------------------------------------------------------------===// |
| 759 | |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 760 | void ASTReader::setDeserializationListener(ASTDeserializationListener *Listener, |
| 761 | bool TakeOwnership) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 762 | DeserializationListener = Listener; |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 763 | OwnsDeserializationListener = TakeOwnership; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 764 | } |
| 765 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 766 | unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { |
| 767 | return serialization::ComputeHash(Sel); |
| 768 | } |
| 769 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 770 | std::pair<unsigned, unsigned> |
| 771 | ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 772 | using namespace llvm::support; |
| 773 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 774 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 775 | return std::make_pair(KeyLen, DataLen); |
| 776 | } |
| 777 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 778 | ASTSelectorLookupTrait::internal_key_type |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 779 | ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 780 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 781 | SelectorTable &SelTable = Reader.getContext().Selectors; |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 782 | unsigned N = endian::readNext<uint16_t, little, unaligned>(d); |
| 783 | IdentifierInfo *FirstII = Reader.getLocalIdentifier( |
| 784 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 785 | if (N == 0) |
| 786 | return SelTable.getNullarySelector(FirstII); |
| 787 | else if (N == 1) |
| 788 | return SelTable.getUnarySelector(FirstII); |
| 789 | |
| 790 | SmallVector<IdentifierInfo *, 16> Args; |
| 791 | Args.push_back(FirstII); |
| 792 | for (unsigned I = 1; I != N; ++I) |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 793 | Args.push_back(Reader.getLocalIdentifier( |
| 794 | F, endian::readNext<uint32_t, little, unaligned>(d))); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 795 | |
| 796 | return SelTable.getSelector(N, Args.data()); |
| 797 | } |
| 798 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 799 | ASTSelectorLookupTrait::data_type |
| 800 | ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 801 | unsigned DataLen) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 802 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 803 | |
| 804 | data_type Result; |
| 805 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 806 | Result.ID = Reader.getGlobalSelectorID( |
| 807 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 808 | unsigned FullInstanceBits = endian::readNext<uint16_t, little, unaligned>(d); |
| 809 | unsigned FullFactoryBits = endian::readNext<uint16_t, little, unaligned>(d); |
| 810 | Result.InstanceBits = FullInstanceBits & 0x3; |
| 811 | Result.InstanceHasMoreThanOneDecl = (FullInstanceBits >> 2) & 0x1; |
| 812 | Result.FactoryBits = FullFactoryBits & 0x3; |
| 813 | Result.FactoryHasMoreThanOneDecl = (FullFactoryBits >> 2) & 0x1; |
| 814 | unsigned NumInstanceMethods = FullInstanceBits >> 3; |
| 815 | unsigned NumFactoryMethods = FullFactoryBits >> 3; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 816 | |
| 817 | // Load instance methods |
| 818 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 819 | if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>( |
| 820 | F, endian::readNext<uint32_t, little, unaligned>(d))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 821 | Result.Instance.push_back(Method); |
| 822 | } |
| 823 | |
| 824 | // Load factory methods |
| 825 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 826 | if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>( |
| 827 | F, endian::readNext<uint32_t, little, unaligned>(d))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 828 | Result.Factory.push_back(Method); |
| 829 | } |
| 830 | |
| 831 | return Result; |
| 832 | } |
| 833 | |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 834 | unsigned ASTIdentifierLookupTraitBase::ComputeHash(const internal_key_type& a) { |
| 835 | return llvm::HashString(a); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | std::pair<unsigned, unsigned> |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 839 | ASTIdentifierLookupTraitBase::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 840 | using namespace llvm::support; |
| 841 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 842 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 843 | return std::make_pair(KeyLen, DataLen); |
| 844 | } |
| 845 | |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 846 | ASTIdentifierLookupTraitBase::internal_key_type |
| 847 | ASTIdentifierLookupTraitBase::ReadKey(const unsigned char* d, unsigned n) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 848 | assert(n >= 2 && d[n-1] == '\0'); |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 849 | return StringRef((const char*) d, n-1); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 850 | } |
| 851 | |
Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 852 | /// \brief Whether the given identifier is "interesting". |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 853 | static bool isInterestingIdentifier(ASTReader &Reader, IdentifierInfo &II, |
| 854 | bool IsModule) { |
Richard Smith | cab8980 | 2015-07-17 20:19:56 +0000 | [diff] [blame] | 855 | return II.hadMacroDefinition() || |
| 856 | II.isPoisoned() || |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 857 | (IsModule ? II.hasRevertedBuiltin() : II.getObjCOrBuiltinID()) || |
Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 858 | II.hasRevertedTokenIDToIdentifier() || |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 859 | (!(IsModule && Reader.getPreprocessor().getLangOpts().CPlusPlus) && |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 860 | II.getFETokenInfo<void>()); |
Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 861 | } |
| 862 | |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 863 | static bool readBit(unsigned &Bits) { |
| 864 | bool Value = Bits & 0x1; |
| 865 | Bits >>= 1; |
| 866 | return Value; |
| 867 | } |
| 868 | |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 869 | IdentID ASTIdentifierLookupTrait::ReadIdentifierID(const unsigned char *d) { |
| 870 | using namespace llvm::support; |
| 871 | unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d); |
| 872 | return Reader.getGlobalIdentifierID(F, RawID >> 1); |
| 873 | } |
| 874 | |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 875 | static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II) { |
| 876 | if (!II.isFromAST()) { |
| 877 | II.setIsFromAST(); |
| 878 | bool IsModule = Reader.getPreprocessor().getCurrentModule() != nullptr; |
| 879 | if (isInterestingIdentifier(Reader, II, IsModule)) |
| 880 | II.setChangedSinceDeserialization(); |
| 881 | } |
| 882 | } |
| 883 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 884 | IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, |
| 885 | const unsigned char* d, |
| 886 | unsigned DataLen) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 887 | using namespace llvm::support; |
| 888 | unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 889 | bool IsInteresting = RawID & 0x01; |
| 890 | |
| 891 | // Wipe out the "is interesting" bit. |
| 892 | RawID = RawID >> 1; |
| 893 | |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 894 | // Build the IdentifierInfo and link the identifier ID with it. |
| 895 | IdentifierInfo *II = KnownII; |
| 896 | if (!II) { |
| 897 | II = &Reader.getIdentifierTable().getOwn(k); |
| 898 | KnownII = II; |
| 899 | } |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 900 | markIdentifierFromAST(Reader, *II); |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 901 | Reader.markIdentifierUpToDate(II); |
| 902 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 903 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
| 904 | if (!IsInteresting) { |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 905 | // For uninteresting identifiers, there's nothing else to do. Just notify |
| 906 | // the reader that we've finished loading this identifier. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 907 | Reader.SetIdentifierInfo(ID, II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 908 | return II; |
| 909 | } |
| 910 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 911 | unsigned ObjCOrBuiltinID = endian::readNext<uint16_t, little, unaligned>(d); |
| 912 | unsigned Bits = endian::readNext<uint16_t, little, unaligned>(d); |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 913 | bool CPlusPlusOperatorKeyword = readBit(Bits); |
| 914 | bool HasRevertedTokenIDToIdentifier = readBit(Bits); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 915 | bool HasRevertedBuiltin = readBit(Bits); |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 916 | bool Poisoned = readBit(Bits); |
| 917 | bool ExtensionToken = readBit(Bits); |
| 918 | bool HadMacroDefinition = readBit(Bits); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 919 | |
| 920 | assert(Bits == 0 && "Extra bits in the identifier?"); |
| 921 | DataLen -= 8; |
| 922 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 923 | // Set or check the various bits in the IdentifierInfo structure. |
| 924 | // Token IDs are read-only. |
Argyrios Kyrtzidis | ddee8c9 | 2013-02-27 01:13:51 +0000 | [diff] [blame] | 925 | if (HasRevertedTokenIDToIdentifier && II->getTokenID() != tok::identifier) |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 926 | II->revertTokenIDToIdentifier(); |
| 927 | if (!F.isModule()) |
| 928 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 929 | else if (HasRevertedBuiltin && II->getBuiltinID()) { |
| 930 | II->revertBuiltin(); |
| 931 | assert((II->hasRevertedBuiltin() || |
| 932 | II->getObjCOrBuiltinID() == ObjCOrBuiltinID) && |
| 933 | "Incorrect ObjC keyword or builtin ID"); |
| 934 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 935 | assert(II->isExtensionToken() == ExtensionToken && |
| 936 | "Incorrect extension token flag"); |
| 937 | (void)ExtensionToken; |
| 938 | if (Poisoned) |
| 939 | II->setIsPoisoned(true); |
| 940 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 941 | "Incorrect C++ operator keyword flag"); |
| 942 | (void)CPlusPlusOperatorKeyword; |
| 943 | |
| 944 | // If this identifier is a macro, deserialize the macro |
| 945 | // definition. |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 946 | if (HadMacroDefinition) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 947 | uint32_t MacroDirectivesOffset = |
| 948 | endian::readNext<uint32_t, little, unaligned>(d); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 949 | DataLen -= 4; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 950 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 951 | Reader.addPendingMacro(II, &F, MacroDirectivesOffset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | Reader.SetIdentifierInfo(ID, II); |
| 955 | |
| 956 | // Read all of the declarations visible at global scope with this |
| 957 | // name. |
| 958 | if (DataLen > 0) { |
| 959 | SmallVector<uint32_t, 4> DeclIDs; |
| 960 | for (; DataLen > 0; DataLen -= 4) |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 961 | DeclIDs.push_back(Reader.getGlobalDeclID( |
| 962 | F, endian::readNext<uint32_t, little, unaligned>(d))); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 963 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
| 964 | } |
| 965 | |
| 966 | return II; |
| 967 | } |
| 968 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 969 | DeclarationNameKey::DeclarationNameKey(DeclarationName Name) |
| 970 | : Kind(Name.getNameKind()) { |
| 971 | switch (Kind) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 972 | case DeclarationName::Identifier: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 973 | Data = (uint64_t)Name.getAsIdentifierInfo(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 974 | break; |
| 975 | case DeclarationName::ObjCZeroArgSelector: |
| 976 | case DeclarationName::ObjCOneArgSelector: |
| 977 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 978 | Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 979 | break; |
| 980 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 981 | Data = Name.getCXXOverloadedOperator(); |
| 982 | break; |
| 983 | case DeclarationName::CXXLiteralOperatorName: |
| 984 | Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 985 | break; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 986 | case DeclarationName::CXXDeductionGuideName: |
| 987 | Data = (uint64_t)Name.getCXXDeductionGuideTemplate() |
| 988 | ->getDeclName().getAsIdentifierInfo(); |
| 989 | break; |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 990 | case DeclarationName::CXXConstructorName: |
| 991 | case DeclarationName::CXXDestructorName: |
| 992 | case DeclarationName::CXXConversionFunctionName: |
| 993 | case DeclarationName::CXXUsingDirective: |
| 994 | Data = 0; |
| 995 | break; |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | unsigned DeclarationNameKey::getHash() const { |
| 1000 | llvm::FoldingSetNodeID ID; |
| 1001 | ID.AddInteger(Kind); |
| 1002 | |
| 1003 | switch (Kind) { |
| 1004 | case DeclarationName::Identifier: |
| 1005 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1006 | case DeclarationName::CXXDeductionGuideName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1007 | ID.AddString(((IdentifierInfo*)Data)->getName()); |
| 1008 | break; |
| 1009 | case DeclarationName::ObjCZeroArgSelector: |
| 1010 | case DeclarationName::ObjCOneArgSelector: |
| 1011 | case DeclarationName::ObjCMultiArgSelector: |
| 1012 | ID.AddInteger(serialization::ComputeHash(Selector(Data))); |
| 1013 | break; |
| 1014 | case DeclarationName::CXXOperatorName: |
| 1015 | ID.AddInteger((OverloadedOperatorKind)Data); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1016 | break; |
| 1017 | case DeclarationName::CXXConstructorName: |
| 1018 | case DeclarationName::CXXDestructorName: |
| 1019 | case DeclarationName::CXXConversionFunctionName: |
| 1020 | case DeclarationName::CXXUsingDirective: |
| 1021 | break; |
| 1022 | } |
| 1023 | |
| 1024 | return ID.ComputeHash(); |
| 1025 | } |
| 1026 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1027 | ModuleFile * |
| 1028 | ASTDeclContextNameLookupTrait::ReadFileRef(const unsigned char *&d) { |
| 1029 | using namespace llvm::support; |
| 1030 | uint32_t ModuleFileID = endian::readNext<uint32_t, little, unaligned>(d); |
| 1031 | return Reader.getLocalModuleFile(F, ModuleFileID); |
| 1032 | } |
| 1033 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1034 | std::pair<unsigned, unsigned> |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1035 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char *&d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1036 | using namespace llvm::support; |
| 1037 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 1038 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1039 | return std::make_pair(KeyLen, DataLen); |
| 1040 | } |
| 1041 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1042 | ASTDeclContextNameLookupTrait::internal_key_type |
| 1043 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char *d, unsigned) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1044 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1045 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1046 | auto Kind = (DeclarationName::NameKind)*d++; |
| 1047 | uint64_t Data; |
| 1048 | switch (Kind) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1049 | case DeclarationName::Identifier: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1050 | case DeclarationName::CXXLiteralOperatorName: |
| 1051 | case DeclarationName::CXXDeductionGuideName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1052 | Data = (uint64_t)Reader.getLocalIdentifier( |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1053 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1054 | break; |
| 1055 | case DeclarationName::ObjCZeroArgSelector: |
| 1056 | case DeclarationName::ObjCOneArgSelector: |
| 1057 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1058 | Data = |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1059 | (uint64_t)Reader.getLocalSelector( |
| 1060 | F, endian::readNext<uint32_t, little, unaligned>( |
| 1061 | d)).getAsOpaquePtr(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1062 | break; |
| 1063 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1064 | Data = *d++; // OverloadedOperatorKind |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1065 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1066 | case DeclarationName::CXXConstructorName: |
| 1067 | case DeclarationName::CXXDestructorName: |
| 1068 | case DeclarationName::CXXConversionFunctionName: |
| 1069 | case DeclarationName::CXXUsingDirective: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1070 | Data = 0; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1071 | break; |
| 1072 | } |
| 1073 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1074 | return DeclarationNameKey(Kind, Data); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1077 | void ASTDeclContextNameLookupTrait::ReadDataInto(internal_key_type, |
| 1078 | const unsigned char *d, |
| 1079 | unsigned DataLen, |
| 1080 | data_type_builder &Val) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1081 | using namespace llvm::support; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1082 | for (unsigned NumDecls = DataLen / 4; NumDecls; --NumDecls) { |
| 1083 | uint32_t LocalID = endian::readNext<uint32_t, little, unaligned>(d); |
| 1084 | Val.insert(Reader.getGlobalDeclID(F, LocalID)); |
| 1085 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1088 | bool ASTReader::ReadLexicalDeclContextStorage(ModuleFile &M, |
| 1089 | BitstreamCursor &Cursor, |
| 1090 | uint64_t Offset, |
| 1091 | DeclContext *DC) { |
| 1092 | assert(Offset != 0); |
| 1093 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1094 | SavedStreamPosition SavedPosition(Cursor); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1095 | Cursor.JumpToBit(Offset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1096 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1097 | RecordData Record; |
| 1098 | StringRef Blob; |
| 1099 | unsigned Code = Cursor.ReadCode(); |
| 1100 | unsigned RecCode = Cursor.readRecord(Code, Record, &Blob); |
| 1101 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 1102 | Error("Expected lexical block"); |
| 1103 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 1106 | assert(!isa<TranslationUnitDecl>(DC) && |
| 1107 | "expected a TU_UPDATE_LEXICAL record for TU"); |
Richard Smith | 9c9173d | 2015-08-11 22:00:24 +0000 | [diff] [blame] | 1108 | // If we are handling a C++ class template instantiation, we can see multiple |
| 1109 | // lexical updates for the same record. It's important that we select only one |
| 1110 | // of them, so that field numbering works properly. Just pick the first one we |
| 1111 | // see. |
| 1112 | auto &Lex = LexicalDecls[DC]; |
| 1113 | if (!Lex.first) { |
| 1114 | Lex = std::make_pair( |
| 1115 | &M, llvm::makeArrayRef( |
| 1116 | reinterpret_cast<const llvm::support::unaligned_uint32_t *>( |
| 1117 | Blob.data()), |
| 1118 | Blob.size() / 4)); |
| 1119 | } |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1120 | DC->setHasExternalLexicalStorage(true); |
| 1121 | return false; |
| 1122 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1123 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1124 | bool ASTReader::ReadVisibleDeclContextStorage(ModuleFile &M, |
| 1125 | BitstreamCursor &Cursor, |
| 1126 | uint64_t Offset, |
| 1127 | DeclID ID) { |
| 1128 | assert(Offset != 0); |
| 1129 | |
| 1130 | SavedStreamPosition SavedPosition(Cursor); |
| 1131 | Cursor.JumpToBit(Offset); |
| 1132 | |
| 1133 | RecordData Record; |
| 1134 | StringRef Blob; |
| 1135 | unsigned Code = Cursor.ReadCode(); |
| 1136 | unsigned RecCode = Cursor.readRecord(Code, Record, &Blob); |
| 1137 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 1138 | Error("Expected visible lookup table block"); |
| 1139 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1140 | } |
| 1141 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1142 | // We can't safely determine the primary context yet, so delay attaching the |
| 1143 | // lookup table until we're done with recursive deserialization. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1144 | auto *Data = (const unsigned char*)Blob.data(); |
| 1145 | PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&M, Data}); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1146 | return false; |
| 1147 | } |
| 1148 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 1149 | void ASTReader::Error(StringRef Msg) const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1150 | Error(diag::err_fe_pch_malformed, Msg); |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 1151 | if (PP.getLangOpts().Modules && !Diags.isDiagnosticInFlight() && |
Richard Smith | fb1e7f7 | 2015-08-14 05:02:58 +0000 | [diff] [blame] | 1152 | !PP.getHeaderSearchInfo().getModuleCachePath().empty()) { |
Douglas Gregor | 940e805 | 2013-05-10 22:15:13 +0000 | [diff] [blame] | 1153 | Diag(diag::note_module_cache_path) |
| 1154 | << PP.getHeaderSearchInfo().getModuleCachePath(); |
| 1155 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | void ASTReader::Error(unsigned DiagID, |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 1159 | StringRef Arg1, StringRef Arg2) const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1160 | if (Diags.isDiagnosticInFlight()) |
| 1161 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 1162 | else |
| 1163 | Diag(DiagID) << Arg1 << Arg2; |
| 1164 | } |
| 1165 | |
| 1166 | //===----------------------------------------------------------------------===// |
| 1167 | // Source Manager Deserialization |
| 1168 | //===----------------------------------------------------------------------===// |
| 1169 | |
| 1170 | /// \brief Read the line table in the source manager block. |
| 1171 | /// \returns true if there was an error. |
| 1172 | bool ASTReader::ParseLineTable(ModuleFile &F, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1173 | const RecordData &Record) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1174 | unsigned Idx = 0; |
| 1175 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1176 | |
| 1177 | // Parse the file names |
| 1178 | std::map<int, int> FileIDs; |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1179 | for (unsigned I = 0; Record[Idx]; ++I) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1180 | // Extract the file name |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1181 | auto Filename = ReadPath(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1182 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
| 1183 | } |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1184 | ++Idx; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1185 | |
| 1186 | // Parse the line entries |
| 1187 | std::vector<LineEntry> Entries; |
| 1188 | while (Idx < Record.size()) { |
| 1189 | int FID = Record[Idx++]; |
| 1190 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 1191 | // Remap FileID from 1-based old view. |
| 1192 | FID += F.SLocEntryBaseID - 1; |
| 1193 | |
| 1194 | // Extract the line entries |
| 1195 | unsigned NumEntries = Record[Idx++]; |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1196 | assert(NumEntries && "no line entries for file ID"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1197 | Entries.clear(); |
| 1198 | Entries.reserve(NumEntries); |
| 1199 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1200 | unsigned FileOffset = Record[Idx++]; |
| 1201 | unsigned LineNo = Record[Idx++]; |
| 1202 | int FilenameID = FileIDs[Record[Idx++]]; |
| 1203 | SrcMgr::CharacteristicKind FileKind |
| 1204 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1205 | unsigned IncludeOffset = Record[Idx++]; |
| 1206 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1207 | FileKind, IncludeOffset)); |
| 1208 | } |
| 1209 | LineTable.AddEntry(FileID::get(FID), Entries); |
| 1210 | } |
| 1211 | |
| 1212 | return false; |
| 1213 | } |
| 1214 | |
| 1215 | /// \brief Read a source manager block |
| 1216 | bool ASTReader::ReadSourceManagerBlock(ModuleFile &F) { |
| 1217 | using namespace SrcMgr; |
| 1218 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1219 | BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1220 | |
| 1221 | // Set the source-location entry cursor to the current position in |
| 1222 | // the stream. This cursor will be used to read the contents of the |
| 1223 | // source manager block initially, and then lazily read |
| 1224 | // source-location entries as needed. |
| 1225 | SLocEntryCursor = F.Stream; |
| 1226 | |
| 1227 | // The stream itself is going to skip over the source manager block. |
| 1228 | if (F.Stream.SkipBlock()) { |
| 1229 | Error("malformed block record in AST file"); |
| 1230 | return true; |
| 1231 | } |
| 1232 | |
| 1233 | // Enter the source manager block. |
| 1234 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
| 1235 | Error("malformed source manager block record in AST file"); |
| 1236 | return true; |
| 1237 | } |
| 1238 | |
| 1239 | RecordData Record; |
| 1240 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1241 | llvm::BitstreamEntry E = SLocEntryCursor.advanceSkippingSubblocks(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1242 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1243 | switch (E.Kind) { |
| 1244 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1245 | case llvm::BitstreamEntry::Error: |
| 1246 | Error("malformed block record in AST file"); |
| 1247 | return true; |
| 1248 | case llvm::BitstreamEntry::EndBlock: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1249 | return false; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1250 | case llvm::BitstreamEntry::Record: |
| 1251 | // The interesting case. |
| 1252 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1253 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1254 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1255 | // Read a record. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1256 | Record.clear(); |
Chris Lattner | 15c3e7d | 2013-01-21 18:28:26 +0000 | [diff] [blame] | 1257 | StringRef Blob; |
| 1258 | switch (SLocEntryCursor.readRecord(E.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1259 | default: // Default behavior: ignore. |
| 1260 | break; |
| 1261 | |
| 1262 | case SM_SLOC_FILE_ENTRY: |
| 1263 | case SM_SLOC_BUFFER_ENTRY: |
| 1264 | case SM_SLOC_EXPANSION_ENTRY: |
| 1265 | // Once we hit one of the source location entries, we're done. |
| 1266 | return false; |
| 1267 | } |
| 1268 | } |
| 1269 | } |
| 1270 | |
| 1271 | /// \brief If a header file is not found at the path that we expect it to be |
| 1272 | /// and the PCH file was moved from its original location, try to resolve the |
| 1273 | /// file by assuming that header+PCH were moved together and the header is in |
| 1274 | /// the same place relative to the PCH. |
| 1275 | static std::string |
| 1276 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1277 | const std::string &OriginalDir, |
| 1278 | const std::string &CurrDir) { |
| 1279 | assert(OriginalDir != CurrDir && |
| 1280 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1281 | using namespace llvm::sys; |
| 1282 | SmallString<128> filePath(Filename); |
| 1283 | fs::make_absolute(filePath); |
| 1284 | assert(path::is_absolute(OriginalDir)); |
| 1285 | SmallString<128> currPCHPath(CurrDir); |
| 1286 | |
| 1287 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1288 | fileDirE = path::end(path::parent_path(filePath)); |
| 1289 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1290 | origDirE = path::end(OriginalDir); |
| 1291 | // Skip the common path components from filePath and OriginalDir. |
| 1292 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1293 | *fileDirI == *origDirI) { |
| 1294 | ++fileDirI; |
| 1295 | ++origDirI; |
| 1296 | } |
| 1297 | for (; origDirI != origDirE; ++origDirI) |
| 1298 | path::append(currPCHPath, ".."); |
| 1299 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1300 | path::append(currPCHPath, path::filename(Filename)); |
| 1301 | return currPCHPath.str(); |
| 1302 | } |
| 1303 | |
| 1304 | bool ASTReader::ReadSLocEntry(int ID) { |
| 1305 | if (ID == 0) |
| 1306 | return false; |
| 1307 | |
| 1308 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
| 1309 | Error("source location entry ID out-of-range for AST file"); |
| 1310 | return true; |
| 1311 | } |
| 1312 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1313 | // Local helper to read the (possibly-compressed) buffer data following the |
| 1314 | // entry record. |
| 1315 | auto ReadBuffer = [this]( |
| 1316 | BitstreamCursor &SLocEntryCursor, |
| 1317 | StringRef Name) -> std::unique_ptr<llvm::MemoryBuffer> { |
| 1318 | RecordData Record; |
| 1319 | StringRef Blob; |
| 1320 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1321 | unsigned RecCode = SLocEntryCursor.readRecord(Code, Record, &Blob); |
| 1322 | |
| 1323 | if (RecCode == SM_SLOC_BUFFER_BLOB_COMPRESSED) { |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 1324 | if (!llvm::zlib::isAvailable()) { |
| 1325 | Error("zlib is not available"); |
| 1326 | return nullptr; |
| 1327 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1328 | SmallString<0> Uncompressed; |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 1329 | if (llvm::Error E = |
| 1330 | llvm::zlib::uncompress(Blob, Uncompressed, Record[0])) { |
| 1331 | Error("could not decompress embedded file contents: " + |
| 1332 | llvm::toString(std::move(E))); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1333 | return nullptr; |
| 1334 | } |
| 1335 | return llvm::MemoryBuffer::getMemBufferCopy(Uncompressed, Name); |
| 1336 | } else if (RecCode == SM_SLOC_BUFFER_BLOB) { |
| 1337 | return llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), Name, true); |
| 1338 | } else { |
| 1339 | Error("AST record has invalid code"); |
| 1340 | return nullptr; |
| 1341 | } |
| 1342 | }; |
| 1343 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1344 | ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second; |
| 1345 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1346 | BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1347 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
| 1348 | |
| 1349 | ++NumSLocEntriesRead; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1350 | llvm::BitstreamEntry Entry = SLocEntryCursor.advance(); |
| 1351 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1352 | Error("incorrectly-formatted source location entry in AST file"); |
| 1353 | return true; |
| 1354 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1355 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1356 | RecordData Record; |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1357 | StringRef Blob; |
| 1358 | switch (SLocEntryCursor.readRecord(Entry.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1359 | default: |
| 1360 | Error("incorrectly-formatted source location entry in AST file"); |
| 1361 | return true; |
| 1362 | |
| 1363 | case SM_SLOC_FILE_ENTRY: { |
| 1364 | // We will detect whether a file changed and return 'Failure' for it, but |
| 1365 | // we will also try to fail gracefully by setting up the SLocEntry. |
| 1366 | unsigned InputID = Record[4]; |
| 1367 | InputFile IF = getInputFile(*F, InputID); |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 1368 | const FileEntry *File = IF.getFile(); |
| 1369 | bool OverriddenBuffer = IF.isOverridden(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1370 | |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 1371 | // Note that we only check if a File was returned. If it was out-of-date |
| 1372 | // we have complained but we will continue creating a FileID to recover |
| 1373 | // gracefully. |
| 1374 | if (!File) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1375 | return true; |
| 1376 | |
| 1377 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
| 1378 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
| 1379 | // This is the module's main file. |
| 1380 | IncludeLoc = getImportLocation(F); |
| 1381 | } |
| 1382 | SrcMgr::CharacteristicKind |
| 1383 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1384 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter, |
| 1385 | ID, BaseOffset + Record[0]); |
| 1386 | SrcMgr::FileInfo &FileInfo = |
| 1387 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
| 1388 | FileInfo.NumCreatedFIDs = Record[5]; |
| 1389 | if (Record[3]) |
| 1390 | FileInfo.setHasLineDirectives(); |
| 1391 | |
| 1392 | const DeclID *FirstDecl = F->FileSortedDecls + Record[6]; |
| 1393 | unsigned NumFileDecls = Record[7]; |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 1394 | if (NumFileDecls && ContextObj) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1395 | assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?"); |
| 1396 | FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl, |
| 1397 | NumFileDecls)); |
| 1398 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1399 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1400 | const SrcMgr::ContentCache *ContentCache |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1401 | = SourceMgr.getOrCreateContentCache(File, isSystem(FileCharacter)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1402 | if (OverriddenBuffer && !ContentCache->BufferOverridden && |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1403 | ContentCache->ContentsEntry == ContentCache->OrigEntry && |
| 1404 | !ContentCache->getRawBuffer()) { |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1405 | auto Buffer = ReadBuffer(SLocEntryCursor, File->getName()); |
| 1406 | if (!Buffer) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1407 | return true; |
David Blaikie | 49cc318 | 2014-08-27 20:54:45 +0000 | [diff] [blame] | 1408 | SourceMgr.overrideFileContents(File, std::move(Buffer)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | break; |
| 1412 | } |
| 1413 | |
| 1414 | case SM_SLOC_BUFFER_ENTRY: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1415 | const char *Name = Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1416 | unsigned Offset = Record[0]; |
| 1417 | SrcMgr::CharacteristicKind |
| 1418 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1419 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 1420 | if (IncludeLoc.isInvalid() && F->isModule()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1421 | IncludeLoc = getImportLocation(F); |
| 1422 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1423 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1424 | auto Buffer = ReadBuffer(SLocEntryCursor, Name); |
| 1425 | if (!Buffer) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1426 | return true; |
David Blaikie | 50a5f97 | 2014-08-29 07:59:55 +0000 | [diff] [blame] | 1427 | SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID, |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 1428 | BaseOffset + Offset, IncludeLoc); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1429 | break; |
| 1430 | } |
| 1431 | |
| 1432 | case SM_SLOC_EXPANSION_ENTRY: { |
| 1433 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
| 1434 | SourceMgr.createExpansionLoc(SpellingLoc, |
| 1435 | ReadSourceLocation(*F, Record[2]), |
| 1436 | ReadSourceLocation(*F, Record[3]), |
| 1437 | Record[4], |
| 1438 | ID, |
| 1439 | BaseOffset + Record[0]); |
| 1440 | break; |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | return false; |
| 1445 | } |
| 1446 | |
| 1447 | std::pair<SourceLocation, StringRef> ASTReader::getModuleImportLoc(int ID) { |
| 1448 | if (ID == 0) |
| 1449 | return std::make_pair(SourceLocation(), ""); |
| 1450 | |
| 1451 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
| 1452 | Error("source location entry ID out-of-range for AST file"); |
| 1453 | return std::make_pair(SourceLocation(), ""); |
| 1454 | } |
| 1455 | |
| 1456 | // Find which module file this entry lands in. |
| 1457 | ModuleFile *M = GlobalSLocEntryMap.find(-ID)->second; |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 1458 | if (!M->isModule()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1459 | return std::make_pair(SourceLocation(), ""); |
| 1460 | |
| 1461 | // FIXME: Can we map this down to a particular submodule? That would be |
| 1462 | // ideal. |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1463 | return std::make_pair(M->ImportLoc, StringRef(M->ModuleName)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | /// \brief Find the location where the module F is imported. |
| 1467 | SourceLocation ASTReader::getImportLocation(ModuleFile *F) { |
| 1468 | if (F->ImportLoc.isValid()) |
| 1469 | return F->ImportLoc; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1470 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1471 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1472 | // location of its includer. |
| 1473 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1474 | // Main file is the importer. |
Yaron Keren | 8b56366 | 2015-10-03 10:46:20 +0000 | [diff] [blame] | 1475 | assert(SourceMgr.getMainFileID().isValid() && "missing main file"); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1476 | return SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1477 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1478 | return F->ImportedBy[0]->FirstLoc; |
| 1479 | } |
| 1480 | |
| 1481 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1482 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1483 | /// and then leave the cursor pointing into the block. |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1484 | bool ASTReader::ReadBlockAbbrevs(BitstreamCursor &Cursor, unsigned BlockID) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1485 | if (Cursor.EnterSubBlock(BlockID)) |
| 1486 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1487 | |
| 1488 | while (true) { |
| 1489 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
| 1490 | unsigned Code = Cursor.ReadCode(); |
| 1491 | |
| 1492 | // We expect all abbrevs to be at the start of the block. |
| 1493 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1494 | Cursor.JumpToBit(Offset); |
| 1495 | return false; |
| 1496 | } |
| 1497 | Cursor.ReadAbbrevRecord(); |
| 1498 | } |
| 1499 | } |
| 1500 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 1501 | Token ASTReader::ReadToken(ModuleFile &F, const RecordDataImpl &Record, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1502 | unsigned &Idx) { |
| 1503 | Token Tok; |
| 1504 | Tok.startToken(); |
| 1505 | Tok.setLocation(ReadSourceLocation(F, Record, Idx)); |
| 1506 | Tok.setLength(Record[Idx++]); |
| 1507 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[Idx++])) |
| 1508 | Tok.setIdentifierInfo(II); |
| 1509 | Tok.setKind((tok::TokenKind)Record[Idx++]); |
| 1510 | Tok.setFlag((Token::TokenFlags)Record[Idx++]); |
| 1511 | return Tok; |
| 1512 | } |
| 1513 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1514 | MacroInfo *ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1515 | BitstreamCursor &Stream = F.MacroCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1516 | |
| 1517 | // Keep track of where we are in the stream, then jump back there |
| 1518 | // after reading this macro. |
| 1519 | SavedStreamPosition SavedPosition(Stream); |
| 1520 | |
| 1521 | Stream.JumpToBit(Offset); |
| 1522 | RecordData Record; |
Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame^] | 1523 | SmallVector<IdentifierInfo*, 16> MacroParams; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1524 | MacroInfo *Macro = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1525 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1526 | while (true) { |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1527 | // Advance to the next record, but if we get to the end of the block, don't |
| 1528 | // pop it (removing all the abbreviations from the cursor) since we want to |
| 1529 | // be able to reseek within the block and read entries. |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1530 | unsigned Flags = BitstreamCursor::AF_DontPopBlockAtEnd; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1531 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(Flags); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1532 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1533 | switch (Entry.Kind) { |
| 1534 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1535 | case llvm::BitstreamEntry::Error: |
| 1536 | Error("malformed block record in AST file"); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1537 | return Macro; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1538 | case llvm::BitstreamEntry::EndBlock: |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1539 | return Macro; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1540 | case llvm::BitstreamEntry::Record: |
| 1541 | // The interesting case. |
| 1542 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | // Read a record. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1546 | Record.clear(); |
| 1547 | PreprocessorRecordTypes RecType = |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1548 | (PreprocessorRecordTypes)Stream.readRecord(Entry.ID, Record); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1549 | switch (RecType) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1550 | case PP_MODULE_MACRO: |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1551 | case PP_MACRO_DIRECTIVE_HISTORY: |
| 1552 | return Macro; |
| 1553 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1554 | case PP_MACRO_OBJECT_LIKE: |
| 1555 | case PP_MACRO_FUNCTION_LIKE: { |
| 1556 | // If we already have a macro, that means that we've hit the end |
| 1557 | // of the definition of the macro we were looking for. We're |
| 1558 | // done. |
| 1559 | if (Macro) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1560 | return Macro; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1561 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1562 | unsigned NextIndex = 1; // Skip identifier ID. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1563 | SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex); |
Richard Smith | 3f6dd7a | 2017-05-12 23:40:52 +0000 | [diff] [blame] | 1564 | MacroInfo *MI = PP.AllocateMacroInfo(Loc); |
Argyrios Kyrtzidis | 7572be2 | 2013-01-07 19:16:23 +0000 | [diff] [blame] | 1565 | MI->setDefinitionEndLoc(ReadSourceLocation(F, Record, NextIndex)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1566 | MI->setIsUsed(Record[NextIndex++]); |
Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 1567 | MI->setUsedForHeaderGuard(Record[NextIndex++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1568 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1569 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
| 1570 | // Decode function-like macro info. |
| 1571 | bool isC99VarArgs = Record[NextIndex++]; |
| 1572 | bool isGNUVarArgs = Record[NextIndex++]; |
| 1573 | bool hasCommaPasting = Record[NextIndex++]; |
Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame^] | 1574 | MacroParams.clear(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1575 | unsigned NumArgs = Record[NextIndex++]; |
| 1576 | for (unsigned i = 0; i != NumArgs; ++i) |
Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame^] | 1577 | MacroParams.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1578 | |
| 1579 | // Install function-like macro info. |
| 1580 | MI->setIsFunctionLike(); |
| 1581 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1582 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
| 1583 | if (hasCommaPasting) MI->setHasCommaPasting(); |
Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame^] | 1584 | MI->setParameterList(MacroParams, PP.getPreprocessorAllocator()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1587 | // Remember that we saw this macro last so that we add the tokens that |
| 1588 | // form its body to it. |
| 1589 | Macro = MI; |
| 1590 | |
| 1591 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() && |
| 1592 | Record[NextIndex]) { |
| 1593 | // We have a macro definition. Register the association |
| 1594 | PreprocessedEntityID |
| 1595 | GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]); |
| 1596 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 1597 | PreprocessingRecord::PPEntityID PPID = |
| 1598 | PPRec.getPPEntityID(GlobalID - 1, /*isLoaded=*/true); |
| 1599 | MacroDefinitionRecord *PPDef = cast_or_null<MacroDefinitionRecord>( |
| 1600 | PPRec.getPreprocessedEntity(PPID)); |
Argyrios Kyrtzidis | 832de9f | 2013-02-22 18:35:59 +0000 | [diff] [blame] | 1601 | if (PPDef) |
| 1602 | PPRec.RegisterMacroDefinition(Macro, PPDef); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | ++NumMacrosRead; |
| 1606 | break; |
| 1607 | } |
| 1608 | |
| 1609 | case PP_TOKEN: { |
| 1610 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1611 | // erroneous, just pretend we didn't see this. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1612 | if (!Macro) break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1613 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1614 | unsigned Idx = 0; |
| 1615 | Token Tok = ReadToken(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1616 | Macro->AddTokenToBody(Tok); |
| 1617 | break; |
| 1618 | } |
| 1619 | } |
| 1620 | } |
| 1621 | } |
| 1622 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1623 | PreprocessedEntityID |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 1624 | ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M, |
| 1625 | unsigned LocalID) const { |
| 1626 | if (!M.ModuleOffsetMap.empty()) |
| 1627 | ReadModuleOffsetMap(M); |
| 1628 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1629 | ContinuousRangeMap<uint32_t, int, 2>::const_iterator |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1630 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1631 | assert(I != M.PreprocessedEntityRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1632 | && "Invalid index into preprocessed entity index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1633 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1634 | return LocalID + I->second; |
| 1635 | } |
| 1636 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1637 | unsigned HeaderFileInfoTrait::ComputeHash(internal_key_ref ikey) { |
| 1638 | return llvm::hash_combine(ikey.Size, ikey.ModTime); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1639 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1640 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1641 | HeaderFileInfoTrait::internal_key_type |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1642 | HeaderFileInfoTrait::GetInternalKey(const FileEntry *FE) { |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1643 | internal_key_type ikey = {FE->getSize(), |
| 1644 | M.HasTimestamps ? FE->getModificationTime() : 0, |
| 1645 | FE->getName(), /*Imported*/ false}; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1646 | return ikey; |
| 1647 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1648 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1649 | bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) { |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1650 | if (a.Size != b.Size || (a.ModTime && b.ModTime && a.ModTime != b.ModTime)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1651 | return false; |
| 1652 | |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1653 | if (llvm::sys::path::is_absolute(a.Filename) && a.Filename == b.Filename) |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1654 | return true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1655 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1656 | // Determine whether the actual files are equivalent. |
Argyrios Kyrtzidis | 2a513e8 | 2013-03-04 20:33:40 +0000 | [diff] [blame] | 1657 | FileManager &FileMgr = Reader.getFileManager(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1658 | auto GetFile = [&](const internal_key_type &Key) -> const FileEntry* { |
| 1659 | if (!Key.Imported) |
| 1660 | return FileMgr.getFile(Key.Filename); |
| 1661 | |
| 1662 | std::string Resolved = Key.Filename; |
| 1663 | Reader.ResolveImportedPath(M, Resolved); |
| 1664 | return FileMgr.getFile(Resolved); |
| 1665 | }; |
| 1666 | |
| 1667 | const FileEntry *FEA = GetFile(a); |
| 1668 | const FileEntry *FEB = GetFile(b); |
| 1669 | return FEA && FEA == FEB; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1670 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1671 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1672 | std::pair<unsigned, unsigned> |
| 1673 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1674 | using namespace llvm::support; |
| 1675 | unsigned KeyLen = (unsigned) endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1676 | unsigned DataLen = (unsigned) *d++; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1677 | return std::make_pair(KeyLen, DataLen); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1678 | } |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1679 | |
| 1680 | HeaderFileInfoTrait::internal_key_type |
| 1681 | HeaderFileInfoTrait::ReadKey(const unsigned char *d, unsigned) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1682 | using namespace llvm::support; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1683 | internal_key_type ikey; |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1684 | ikey.Size = off_t(endian::readNext<uint64_t, little, unaligned>(d)); |
| 1685 | ikey.ModTime = time_t(endian::readNext<uint64_t, little, unaligned>(d)); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1686 | ikey.Filename = (const char *)d; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1687 | ikey.Imported = true; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1688 | return ikey; |
| 1689 | } |
| 1690 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1691 | HeaderFileInfoTrait::data_type |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1692 | HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1693 | unsigned DataLen) { |
| 1694 | const unsigned char *End = d + DataLen; |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1695 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1696 | HeaderFileInfo HFI; |
| 1697 | unsigned Flags = *d++; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1698 | // FIXME: Refactor with mergeHeaderFileInfo in HeaderSearch.cpp. |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1699 | HFI.isImport |= (Flags >> 5) & 0x01; |
| 1700 | HFI.isPragmaOnce |= (Flags >> 4) & 0x01; |
| 1701 | HFI.DirInfo = (Flags >> 1) & 0x07; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1702 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1703 | // FIXME: Find a better way to handle this. Maybe just store a |
| 1704 | // "has been included" flag? |
| 1705 | HFI.NumIncludes = std::max(endian::readNext<uint16_t, little, unaligned>(d), |
| 1706 | HFI.NumIncludes); |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1707 | HFI.ControllingMacroID = Reader.getGlobalIdentifierID( |
| 1708 | M, endian::readNext<uint32_t, little, unaligned>(d)); |
| 1709 | if (unsigned FrameworkOffset = |
| 1710 | endian::readNext<uint32_t, little, unaligned>(d)) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1711 | // The framework offset is 1 greater than the actual offset, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1712 | // since 0 is used as an indicator for "no framework name". |
| 1713 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1714 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1715 | } |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1716 | |
| 1717 | assert((End - d) % 4 == 0 && |
| 1718 | "Wrong data length in HeaderFileInfo deserialization"); |
| 1719 | while (d != End) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1720 | uint32_t LocalSMID = endian::readNext<uint32_t, little, unaligned>(d); |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1721 | auto HeaderRole = static_cast<ModuleMap::ModuleHeaderRole>(LocalSMID & 3); |
| 1722 | LocalSMID >>= 2; |
| 1723 | |
| 1724 | // This header is part of a module. Associate it with the module to enable |
| 1725 | // implicit module import. |
| 1726 | SubmoduleID GlobalSMID = Reader.getGlobalSubmoduleID(M, LocalSMID); |
| 1727 | Module *Mod = Reader.getSubmodule(GlobalSMID); |
| 1728 | FileManager &FileMgr = Reader.getFileManager(); |
| 1729 | ModuleMap &ModMap = |
| 1730 | Reader.getPreprocessor().getHeaderSearchInfo().getModuleMap(); |
| 1731 | |
| 1732 | std::string Filename = key.Filename; |
| 1733 | if (key.Imported) |
| 1734 | Reader.ResolveImportedPath(M, Filename); |
| 1735 | // FIXME: This is not always the right filename-as-written, but we're not |
| 1736 | // going to use this information to rebuild the module, so it doesn't make |
| 1737 | // a lot of difference. |
| 1738 | Module::Header H = { key.Filename, FileMgr.getFile(Filename) }; |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1739 | ModMap.addHeader(Mod, H, HeaderRole, /*Imported*/true); |
| 1740 | HFI.isModuleHeader |= !(HeaderRole & ModuleMap::TextualHeader); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1741 | } |
| 1742 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1743 | // This HeaderFileInfo was externally loaded. |
| 1744 | HFI.External = true; |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1745 | HFI.IsValid = true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1746 | return HFI; |
| 1747 | } |
| 1748 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1749 | void ASTReader::addPendingMacro(IdentifierInfo *II, |
| 1750 | ModuleFile *M, |
| 1751 | uint64_t MacroDirectivesOffset) { |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1752 | assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard"); |
| 1753 | PendingMacroIDs[II].push_back(PendingMacroInfo(M, MacroDirectivesOffset)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | void ASTReader::ReadDefinedMacros() { |
| 1757 | // Note that we are loading defined macros. |
| 1758 | Deserializing Macros(this); |
| 1759 | |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1760 | for (ModuleFile &I : llvm::reverse(ModuleMgr)) { |
| 1761 | BitstreamCursor &MacroCursor = I.MacroCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1762 | |
| 1763 | // If there was no preprocessor block, skip this file. |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 1764 | if (MacroCursor.getBitcodeBytes().empty()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1765 | continue; |
| 1766 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1767 | BitstreamCursor Cursor = MacroCursor; |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1768 | Cursor.JumpToBit(I.MacroStartOffset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1769 | |
| 1770 | RecordData Record; |
| 1771 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1772 | llvm::BitstreamEntry E = Cursor.advanceSkippingSubblocks(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1773 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1774 | switch (E.Kind) { |
| 1775 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1776 | case llvm::BitstreamEntry::Error: |
| 1777 | Error("malformed block record in AST file"); |
| 1778 | return; |
| 1779 | case llvm::BitstreamEntry::EndBlock: |
| 1780 | goto NextCursor; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1781 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1782 | case llvm::BitstreamEntry::Record: |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1783 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1784 | switch (Cursor.readRecord(E.ID, Record)) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1785 | default: // Default behavior: ignore. |
| 1786 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1787 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1788 | case PP_MACRO_OBJECT_LIKE: |
Sean Callanan | f3682a7 | 2016-05-14 06:24:14 +0000 | [diff] [blame] | 1789 | case PP_MACRO_FUNCTION_LIKE: { |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1790 | IdentifierInfo *II = getLocalIdentifier(I, Record[0]); |
Sean Callanan | f3682a7 | 2016-05-14 06:24:14 +0000 | [diff] [blame] | 1791 | if (II->isOutOfDate()) |
| 1792 | updateOutOfDateIdentifier(*II); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1793 | break; |
Sean Callanan | f3682a7 | 2016-05-14 06:24:14 +0000 | [diff] [blame] | 1794 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1795 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1796 | case PP_TOKEN: |
| 1797 | // Ignore tokens. |
| 1798 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1799 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1800 | break; |
| 1801 | } |
| 1802 | } |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1803 | NextCursor: ; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1804 | } |
| 1805 | } |
| 1806 | |
| 1807 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1808 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1809 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 1810 | class IdentifierLookupVisitor { |
| 1811 | StringRef Name; |
Richard Smith | 3b63741 | 2015-07-14 18:42:41 +0000 | [diff] [blame] | 1812 | unsigned NameHash; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1813 | unsigned PriorGeneration; |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1814 | unsigned &NumIdentifierLookups; |
| 1815 | unsigned &NumIdentifierLookupHits; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1816 | IdentifierInfo *Found; |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1817 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1818 | public: |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1819 | IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration, |
| 1820 | unsigned &NumIdentifierLookups, |
| 1821 | unsigned &NumIdentifierLookupHits) |
Richard Smith | 3b63741 | 2015-07-14 18:42:41 +0000 | [diff] [blame] | 1822 | : Name(Name), NameHash(ASTIdentifierLookupTrait::ComputeHash(Name)), |
| 1823 | PriorGeneration(PriorGeneration), |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1824 | NumIdentifierLookups(NumIdentifierLookups), |
| 1825 | NumIdentifierLookupHits(NumIdentifierLookupHits), |
| 1826 | Found() |
| 1827 | { |
| 1828 | } |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 1829 | |
| 1830 | bool operator()(ModuleFile &M) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1831 | // If we've already searched this module file, skip it now. |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1832 | if (M.Generation <= PriorGeneration) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1833 | return true; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1834 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1835 | ASTIdentifierLookupTable *IdTable |
| 1836 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 1837 | if (!IdTable) |
| 1838 | return false; |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 1839 | |
| 1840 | ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), M, |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1841 | Found); |
| 1842 | ++NumIdentifierLookups; |
Richard Smith | 3b63741 | 2015-07-14 18:42:41 +0000 | [diff] [blame] | 1843 | ASTIdentifierLookupTable::iterator Pos = |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1844 | IdTable->find_hashed(Name, NameHash, &Trait); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1845 | if (Pos == IdTable->end()) |
| 1846 | return false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1847 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1848 | // Dereferencing the iterator has the effect of building the |
| 1849 | // IdentifierInfo node and populating it with the various |
| 1850 | // declarations it needs. |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1851 | ++NumIdentifierLookupHits; |
| 1852 | Found = *Pos; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1853 | return true; |
| 1854 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1855 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1856 | // \brief Retrieve the identifier info found within the module |
| 1857 | // files. |
| 1858 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 1859 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1860 | |
| 1861 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1862 | |
| 1863 | void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { |
| 1864 | // Note that we are loading an identifier. |
| 1865 | Deserializing AnIdentifier(this); |
| 1866 | |
| 1867 | unsigned PriorGeneration = 0; |
| 1868 | if (getContext().getLangOpts().Modules) |
| 1869 | PriorGeneration = IdentifierGeneration[&II]; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1870 | |
| 1871 | // If there is a global index, look there first to determine which modules |
| 1872 | // provably do not have any results for this identifier. |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1873 | GlobalModuleIndex::HitSet Hits; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1874 | GlobalModuleIndex::HitSet *HitsPtr = nullptr; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1875 | if (!loadGlobalIndex()) { |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1876 | if (GlobalIndex->lookupIdentifier(II.getName(), Hits)) { |
| 1877 | HitsPtr = &Hits; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1878 | } |
| 1879 | } |
| 1880 | |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1881 | IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration, |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1882 | NumIdentifierLookups, |
| 1883 | NumIdentifierLookupHits); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 1884 | ModuleMgr.visit(Visitor, HitsPtr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1885 | markIdentifierUpToDate(&II); |
| 1886 | } |
| 1887 | |
| 1888 | void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { |
| 1889 | if (!II) |
| 1890 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1891 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1892 | II->setOutOfDate(false); |
| 1893 | |
| 1894 | // Update the generation for this identifier. |
| 1895 | if (getContext().getLangOpts().Modules) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1896 | IdentifierGeneration[II] = getGeneration(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1897 | } |
| 1898 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1899 | void ASTReader::resolvePendingMacro(IdentifierInfo *II, |
| 1900 | const PendingMacroInfo &PMInfo) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1901 | ModuleFile &M = *PMInfo.M; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1902 | |
| 1903 | BitstreamCursor &Cursor = M.MacroCursor; |
| 1904 | SavedStreamPosition SavedPosition(Cursor); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1905 | Cursor.JumpToBit(PMInfo.MacroDirectivesOffset); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1906 | |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1907 | struct ModuleMacroRecord { |
| 1908 | SubmoduleID SubModID; |
| 1909 | MacroInfo *MI; |
| 1910 | SmallVector<SubmoduleID, 8> Overrides; |
| 1911 | }; |
| 1912 | llvm::SmallVector<ModuleMacroRecord, 8> ModuleMacros; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1913 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1914 | // We expect to see a sequence of PP_MODULE_MACRO records listing exported |
| 1915 | // macros, followed by a PP_MACRO_DIRECTIVE_HISTORY record with the complete |
| 1916 | // macro histroy. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1917 | RecordData Record; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1918 | while (true) { |
| 1919 | llvm::BitstreamEntry Entry = |
| 1920 | Cursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd); |
| 1921 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| 1922 | Error("malformed block record in AST file"); |
| 1923 | return; |
| 1924 | } |
| 1925 | |
| 1926 | Record.clear(); |
Aaron Ballman | c75a192 | 2015-04-22 15:25:05 +0000 | [diff] [blame] | 1927 | switch ((PreprocessorRecordTypes)Cursor.readRecord(Entry.ID, Record)) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1928 | case PP_MACRO_DIRECTIVE_HISTORY: |
| 1929 | break; |
| 1930 | |
| 1931 | case PP_MODULE_MACRO: { |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1932 | ModuleMacros.push_back(ModuleMacroRecord()); |
| 1933 | auto &Info = ModuleMacros.back(); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1934 | Info.SubModID = getGlobalSubmoduleID(M, Record[0]); |
| 1935 | Info.MI = getMacro(getGlobalMacroID(M, Record[1])); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1936 | for (int I = 2, N = Record.size(); I != N; ++I) |
| 1937 | Info.Overrides.push_back(getGlobalSubmoduleID(M, Record[I])); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1938 | continue; |
| 1939 | } |
| 1940 | |
| 1941 | default: |
| 1942 | Error("malformed block record in AST file"); |
| 1943 | return; |
| 1944 | } |
| 1945 | |
| 1946 | // We found the macro directive history; that's the last record |
| 1947 | // for this macro. |
| 1948 | break; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1949 | } |
| 1950 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1951 | // Module macros are listed in reverse dependency order. |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1952 | { |
| 1953 | std::reverse(ModuleMacros.begin(), ModuleMacros.end()); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1954 | llvm::SmallVector<ModuleMacro*, 8> Overrides; |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1955 | for (auto &MMR : ModuleMacros) { |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1956 | Overrides.clear(); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1957 | for (unsigned ModID : MMR.Overrides) { |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 1958 | Module *Mod = getSubmodule(ModID); |
| 1959 | auto *Macro = PP.getModuleMacro(Mod, II); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1960 | assert(Macro && "missing definition for overridden macro"); |
Richard Smith | 5dbef92 | 2015-04-22 02:09:43 +0000 | [diff] [blame] | 1961 | Overrides.push_back(Macro); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | bool Inserted = false; |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1965 | Module *Owner = getSubmodule(MMR.SubModID); |
Richard Smith | 20e883e | 2015-04-29 23:20:19 +0000 | [diff] [blame] | 1966 | PP.addModuleMacro(Owner, II, MMR.MI, Overrides, Inserted); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1967 | } |
| 1968 | } |
| 1969 | |
| 1970 | // Don't read the directive history for a module; we don't have anywhere |
| 1971 | // to put it. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 1972 | if (M.isModule()) |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1973 | return; |
| 1974 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1975 | // Deserialize the macro directives history in reverse source-order. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1976 | MacroDirective *Latest = nullptr, *Earliest = nullptr; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1977 | unsigned Idx = 0, N = Record.size(); |
| 1978 | while (Idx < N) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1979 | MacroDirective *MD = nullptr; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1980 | SourceLocation Loc = ReadSourceLocation(M, Record, Idx); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1981 | MacroDirective::Kind K = (MacroDirective::Kind)Record[Idx++]; |
| 1982 | switch (K) { |
| 1983 | case MacroDirective::MD_Define: { |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1984 | MacroInfo *MI = getMacro(getGlobalMacroID(M, Record[Idx++])); |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 1985 | MD = PP.AllocateDefMacroDirective(MI, Loc); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1986 | break; |
| 1987 | } |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 1988 | case MacroDirective::MD_Undefine: { |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 1989 | MD = PP.AllocateUndefMacroDirective(Loc); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1990 | break; |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 1991 | } |
| 1992 | case MacroDirective::MD_Visibility: |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 1993 | bool isPublic = Record[Idx++]; |
| 1994 | MD = PP.AllocateVisibilityMacroDirective(Loc, isPublic); |
| 1995 | break; |
| 1996 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1997 | |
| 1998 | if (!Latest) |
| 1999 | Latest = MD; |
| 2000 | if (Earliest) |
| 2001 | Earliest->setPrevious(MD); |
| 2002 | Earliest = MD; |
| 2003 | } |
| 2004 | |
Richard Smith | d6e8c0d | 2015-05-04 19:58:00 +0000 | [diff] [blame] | 2005 | if (Latest) |
Nico Weber | fd87070 | 2016-12-09 17:32:52 +0000 | [diff] [blame] | 2006 | PP.setLoadedMacroDirective(II, Earliest, Latest); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2007 | } |
| 2008 | |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 2009 | ASTReader::InputFileInfo |
| 2010 | ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) { |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2011 | // Go find this input file. |
| 2012 | BitstreamCursor &Cursor = F.InputFilesCursor; |
| 2013 | SavedStreamPosition SavedPosition(Cursor); |
| 2014 | Cursor.JumpToBit(F.InputFileOffsets[ID-1]); |
| 2015 | |
| 2016 | unsigned Code = Cursor.ReadCode(); |
| 2017 | RecordData Record; |
| 2018 | StringRef Blob; |
| 2019 | |
| 2020 | unsigned Result = Cursor.readRecord(Code, Record, &Blob); |
| 2021 | assert(static_cast<InputFileRecordTypes>(Result) == INPUT_FILE && |
| 2022 | "invalid record type for input file"); |
| 2023 | (void)Result; |
| 2024 | |
| 2025 | assert(Record[0] == ID && "Bogus stored ID or offset"); |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2026 | InputFileInfo R; |
| 2027 | R.StoredSize = static_cast<off_t>(Record[1]); |
| 2028 | R.StoredTime = static_cast<time_t>(Record[2]); |
| 2029 | R.Overridden = static_cast<bool>(Record[3]); |
| 2030 | R.Transient = static_cast<bool>(Record[4]); |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 2031 | R.TopLevelModuleMap = static_cast<bool>(Record[5]); |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2032 | R.Filename = Blob; |
| 2033 | ResolveImportedPath(F, R.Filename); |
Hans Wennborg | 7394514 | 2014-03-14 17:45:06 +0000 | [diff] [blame] | 2034 | return R; |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
Manman Ren | c8c9415 | 2016-10-21 23:35:03 +0000 | [diff] [blame] | 2037 | static unsigned moduleKindForDiagnostic(ModuleKind Kind); |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2038 | InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2039 | // If this ID is bogus, just return an empty input file. |
| 2040 | if (ID == 0 || ID > F.InputFilesLoaded.size()) |
| 2041 | return InputFile(); |
| 2042 | |
| 2043 | // If we've already loaded this input file, return it. |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2044 | if (F.InputFilesLoaded[ID-1].getFile()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2045 | return F.InputFilesLoaded[ID-1]; |
| 2046 | |
Argyrios Kyrtzidis | 9308f0a | 2014-01-08 19:13:34 +0000 | [diff] [blame] | 2047 | if (F.InputFilesLoaded[ID-1].isNotFound()) |
| 2048 | return InputFile(); |
| 2049 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2050 | // Go find this input file. |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2051 | BitstreamCursor &Cursor = F.InputFilesCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2052 | SavedStreamPosition SavedPosition(Cursor); |
| 2053 | Cursor.JumpToBit(F.InputFileOffsets[ID-1]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2054 | |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 2055 | InputFileInfo FI = readInputFileInfo(F, ID); |
| 2056 | off_t StoredSize = FI.StoredSize; |
| 2057 | time_t StoredTime = FI.StoredTime; |
| 2058 | bool Overridden = FI.Overridden; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2059 | bool Transient = FI.Transient; |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 2060 | StringRef Filename = FI.Filename; |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2061 | |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2062 | const FileEntry *File = FileMgr.getFile(Filename, /*OpenFile=*/false); |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2063 | |
| 2064 | // If we didn't find the file, resolve it relative to the |
| 2065 | // original directory from which this AST file was created. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 2066 | if (File == nullptr && !F.OriginalDir.empty() && !CurrentDir.empty() && |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2067 | F.OriginalDir != CurrentDir) { |
| 2068 | std::string Resolved = resolveFileRelativeToOriginalDir(Filename, |
| 2069 | F.OriginalDir, |
| 2070 | CurrentDir); |
| 2071 | if (!Resolved.empty()) |
| 2072 | File = FileMgr.getFile(Resolved); |
| 2073 | } |
| 2074 | |
| 2075 | // For an overridden file, create a virtual file with the stored |
| 2076 | // size/timestamp. |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2077 | if ((Overridden || Transient) && File == nullptr) |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2078 | File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime); |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2079 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 2080 | if (File == nullptr) { |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2081 | if (Complain) { |
| 2082 | std::string ErrorStr = "could not find file '"; |
| 2083 | ErrorStr += Filename; |
Richard Smith | 6814221 | 2015-10-13 01:26:26 +0000 | [diff] [blame] | 2084 | ErrorStr += "' referenced by AST file '"; |
| 2085 | ErrorStr += F.FileName; |
| 2086 | ErrorStr += "'"; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2087 | Error(ErrorStr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2088 | } |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2089 | // Record that we didn't find the file. |
| 2090 | F.InputFilesLoaded[ID-1] = InputFile::getNotFound(); |
| 2091 | return InputFile(); |
| 2092 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2093 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2094 | // Check if there was a request to override the contents of the file |
| 2095 | // that was part of the precompiled header. Overridding such a file |
| 2096 | // can lead to problems when lexing using the source locations from the |
| 2097 | // PCH. |
| 2098 | SourceManager &SM = getSourceManager(); |
Richard Smith | 64daf7b | 2015-12-01 03:32:49 +0000 | [diff] [blame] | 2099 | // FIXME: Reject if the overrides are different. |
| 2100 | if ((!Overridden && !Transient) && SM.isFileOverridden(File)) { |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2101 | if (Complain) |
| 2102 | Error(diag::err_fe_pch_file_overridden, Filename); |
| 2103 | // After emitting the diagnostic, recover by disabling the override so |
| 2104 | // that the original file will be used. |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2105 | // |
| 2106 | // FIXME: This recovery is just as broken as the original state; there may |
| 2107 | // be another precompiled module that's using the overridden contents, or |
| 2108 | // we might be half way through parsing it. Instead, we should treat the |
| 2109 | // overridden contents as belonging to a separate FileEntry. |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2110 | SM.disableFileContentsOverride(File); |
| 2111 | // The FileEntry is a virtual file entry with the size of the contents |
| 2112 | // that would override the original contents. Set it to the original's |
| 2113 | // size/time. |
| 2114 | FileMgr.modifyFileEntry(const_cast<FileEntry*>(File), |
| 2115 | StoredSize, StoredTime); |
| 2116 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2117 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2118 | bool IsOutOfDate = false; |
| 2119 | |
| 2120 | // For an overridden file, there is nothing to validate. |
Richard Smith | 96fdab6 | 2014-10-28 16:24:08 +0000 | [diff] [blame] | 2121 | if (!Overridden && // |
| 2122 | (StoredSize != File->getSize() || |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 2123 | (StoredTime && StoredTime != File->getModificationTime() && |
| 2124 | !DisableValidation) |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2125 | )) { |
| 2126 | if (Complain) { |
| 2127 | // Build a list of the PCH imports that got us here (in reverse). |
| 2128 | SmallVector<ModuleFile *, 4> ImportStack(1, &F); |
| 2129 | while (ImportStack.back()->ImportedBy.size() > 0) |
| 2130 | ImportStack.push_back(ImportStack.back()->ImportedBy[0]); |
Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 2131 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2132 | // The top-level PCH is stale. |
| 2133 | StringRef TopLevelPCHName(ImportStack.back()->FileName); |
Manman Ren | c8c9415 | 2016-10-21 23:35:03 +0000 | [diff] [blame] | 2134 | unsigned DiagnosticKind = moduleKindForDiagnostic(ImportStack.back()->Kind); |
| 2135 | if (DiagnosticKind == 0) |
| 2136 | Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName); |
| 2137 | else if (DiagnosticKind == 1) |
| 2138 | Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName); |
| 2139 | else |
| 2140 | Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName); |
Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 2141 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2142 | // Print the import stack. |
| 2143 | if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) { |
| 2144 | Diag(diag::note_pch_required_by) |
| 2145 | << Filename << ImportStack[0]->FileName; |
| 2146 | for (unsigned I = 1; I < ImportStack.size(); ++I) |
Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 2147 | Diag(diag::note_pch_required_by) |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2148 | << ImportStack[I-1]->FileName << ImportStack[I]->FileName; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 2149 | } |
| 2150 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2151 | if (!Diags.isDiagnosticInFlight()) |
| 2152 | Diag(diag::note_pch_rebuild_required) << TopLevelPCHName; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2153 | } |
| 2154 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2155 | IsOutOfDate = true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2156 | } |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2157 | // FIXME: If the file is overridden and we've already opened it, |
| 2158 | // issue an error (or split it into a separate FileEntry). |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2159 | |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2160 | InputFile IF = InputFile(File, Overridden || Transient, IsOutOfDate); |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2161 | |
| 2162 | // Note that we've loaded this input file. |
| 2163 | F.InputFilesLoaded[ID-1] = IF; |
| 2164 | return IF; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2165 | } |
| 2166 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2167 | /// \brief If we are loading a relocatable PCH or module file, and the filename |
| 2168 | /// is not an absolute path, add the system or module root to the beginning of |
| 2169 | /// the file name. |
| 2170 | void ASTReader::ResolveImportedPath(ModuleFile &M, std::string &Filename) { |
| 2171 | // Resolve relative to the base directory, if we have one. |
| 2172 | if (!M.BaseDirectory.empty()) |
| 2173 | return ResolveImportedPath(Filename, M.BaseDirectory); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2174 | } |
| 2175 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2176 | void ASTReader::ResolveImportedPath(std::string &Filename, StringRef Prefix) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2177 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
| 2178 | return; |
| 2179 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2180 | SmallString<128> Buffer; |
| 2181 | llvm::sys::path::append(Buffer, Prefix, Filename); |
| 2182 | Filename.assign(Buffer.begin(), Buffer.end()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2183 | } |
| 2184 | |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2185 | static bool isDiagnosedResult(ASTReader::ASTReadResult ARR, unsigned Caps) { |
| 2186 | switch (ARR) { |
| 2187 | case ASTReader::Failure: return true; |
| 2188 | case ASTReader::Missing: return !(Caps & ASTReader::ARR_Missing); |
| 2189 | case ASTReader::OutOfDate: return !(Caps & ASTReader::ARR_OutOfDate); |
| 2190 | case ASTReader::VersionMismatch: return !(Caps & ASTReader::ARR_VersionMismatch); |
| 2191 | case ASTReader::ConfigurationMismatch: |
| 2192 | return !(Caps & ASTReader::ARR_ConfigurationMismatch); |
| 2193 | case ASTReader::HadErrors: return true; |
| 2194 | case ASTReader::Success: return false; |
| 2195 | } |
| 2196 | |
| 2197 | llvm_unreachable("unknown ASTReadResult"); |
| 2198 | } |
| 2199 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2200 | ASTReader::ASTReadResult ASTReader::ReadOptionsBlock( |
| 2201 | BitstreamCursor &Stream, unsigned ClientLoadCapabilities, |
| 2202 | bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener, |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2203 | std::string &SuggestedPredefines) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2204 | if (Stream.EnterSubBlock(OPTIONS_BLOCK_ID)) |
| 2205 | return Failure; |
| 2206 | |
| 2207 | // Read all of the records in the options block. |
| 2208 | RecordData Record; |
| 2209 | ASTReadResult Result = Success; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2210 | while (true) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2211 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2212 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2213 | switch (Entry.Kind) { |
| 2214 | case llvm::BitstreamEntry::Error: |
| 2215 | case llvm::BitstreamEntry::SubBlock: |
| 2216 | return Failure; |
| 2217 | |
| 2218 | case llvm::BitstreamEntry::EndBlock: |
| 2219 | return Result; |
| 2220 | |
| 2221 | case llvm::BitstreamEntry::Record: |
| 2222 | // The interesting case. |
| 2223 | break; |
| 2224 | } |
| 2225 | |
| 2226 | // Read and process a record. |
| 2227 | Record.clear(); |
| 2228 | switch ((OptionsRecordTypes)Stream.readRecord(Entry.ID, Record)) { |
| 2229 | case LANGUAGE_OPTIONS: { |
| 2230 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2231 | if (ParseLanguageOptions(Record, Complain, Listener, |
| 2232 | AllowCompatibleConfigurationMismatch)) |
| 2233 | Result = ConfigurationMismatch; |
| 2234 | break; |
| 2235 | } |
| 2236 | |
| 2237 | case TARGET_OPTIONS: { |
| 2238 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2239 | if (ParseTargetOptions(Record, Complain, Listener, |
| 2240 | AllowCompatibleConfigurationMismatch)) |
| 2241 | Result = ConfigurationMismatch; |
| 2242 | break; |
| 2243 | } |
| 2244 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2245 | case FILE_SYSTEM_OPTIONS: { |
| 2246 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2247 | if (!AllowCompatibleConfigurationMismatch && |
| 2248 | ParseFileSystemOptions(Record, Complain, Listener)) |
| 2249 | Result = ConfigurationMismatch; |
| 2250 | break; |
| 2251 | } |
| 2252 | |
| 2253 | case HEADER_SEARCH_OPTIONS: { |
| 2254 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2255 | if (!AllowCompatibleConfigurationMismatch && |
| 2256 | ParseHeaderSearchOptions(Record, Complain, Listener)) |
| 2257 | Result = ConfigurationMismatch; |
| 2258 | break; |
| 2259 | } |
| 2260 | |
| 2261 | case PREPROCESSOR_OPTIONS: |
| 2262 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2263 | if (!AllowCompatibleConfigurationMismatch && |
| 2264 | ParsePreprocessorOptions(Record, Complain, Listener, |
| 2265 | SuggestedPredefines)) |
| 2266 | Result = ConfigurationMismatch; |
| 2267 | break; |
| 2268 | } |
| 2269 | } |
| 2270 | } |
| 2271 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2272 | ASTReader::ASTReadResult |
| 2273 | ASTReader::ReadControlBlock(ModuleFile &F, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2274 | SmallVectorImpl<ImportedModule> &Loaded, |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2275 | const ModuleFile *ImportedBy, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2276 | unsigned ClientLoadCapabilities) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2277 | BitstreamCursor &Stream = F.Stream; |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2278 | ASTReadResult Result = Success; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2279 | |
| 2280 | if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
| 2281 | Error("malformed block record in AST file"); |
| 2282 | return Failure; |
| 2283 | } |
| 2284 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2285 | // Lambda to read the unhashed control block the first time it's called. |
| 2286 | // |
| 2287 | // For PCM files, the unhashed control block cannot be read until after the |
| 2288 | // MODULE_NAME record. However, PCH files have no MODULE_NAME, and yet still |
| 2289 | // need to look ahead before reading the IMPORTS record. For consistency, |
| 2290 | // this block is always read somehow (see BitstreamEntry::EndBlock). |
| 2291 | bool HasReadUnhashedControlBlock = false; |
| 2292 | auto readUnhashedControlBlockOnce = [&]() { |
| 2293 | if (!HasReadUnhashedControlBlock) { |
| 2294 | HasReadUnhashedControlBlock = true; |
| 2295 | if (ASTReadResult Result = |
| 2296 | readUnhashedControlBlock(F, ImportedBy, ClientLoadCapabilities)) |
| 2297 | return Result; |
| 2298 | } |
| 2299 | return Success; |
| 2300 | }; |
| 2301 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2302 | // Read all of the records and blocks in the control block. |
| 2303 | RecordData Record; |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2304 | unsigned NumInputs = 0; |
| 2305 | unsigned NumUserInputs = 0; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2306 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2307 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2308 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2309 | switch (Entry.Kind) { |
| 2310 | case llvm::BitstreamEntry::Error: |
| 2311 | Error("malformed block record in AST file"); |
| 2312 | return Failure; |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2313 | case llvm::BitstreamEntry::EndBlock: { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2314 | // Validate the module before returning. This call catches an AST with |
| 2315 | // no module name and no imports. |
| 2316 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2317 | return Result; |
| 2318 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2319 | // Validate input files. |
| 2320 | const HeaderSearchOptions &HSOpts = |
| 2321 | PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2322 | |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2323 | // All user input files reside at the index range [0, NumUserInputs), and |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2324 | // system input files reside at [NumUserInputs, NumInputs). For explicitly |
| 2325 | // loaded module files, ignore missing inputs. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2326 | if (!DisableValidation && F.Kind != MK_ExplicitModule && |
| 2327 | F.Kind != MK_PrebuiltModule) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2328 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2329 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2330 | // If we are reading a module, we will create a verification timestamp, |
| 2331 | // so we verify all input files. Otherwise, verify only user input |
| 2332 | // files. |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2333 | |
| 2334 | unsigned N = NumUserInputs; |
| 2335 | if (ValidateSystemInputs || |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 2336 | (HSOpts.ModulesValidateOncePerBuildSession && |
Ben Langmuir | acb803e | 2014-11-10 22:13:10 +0000 | [diff] [blame] | 2337 | F.InputFilesValidationTimestamp <= HSOpts.BuildSessionTimestamp && |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 2338 | F.Kind == MK_ImplicitModule)) |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2339 | N = NumInputs; |
| 2340 | |
Ben Langmuir | 3d4417c | 2014-02-07 17:31:11 +0000 | [diff] [blame] | 2341 | for (unsigned I = 0; I < N; ++I) { |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2342 | InputFile IF = getInputFile(F, I+1, Complain); |
| 2343 | if (!IF.getFile() || IF.isOutOfDate()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2344 | return OutOfDate; |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2345 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2346 | } |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2347 | |
Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 2348 | if (Listener) |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 2349 | Listener->visitModuleFile(F.FileName, F.Kind); |
Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 2350 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2351 | if (Listener && Listener->needsInputFileVisitation()) { |
| 2352 | unsigned N = Listener->needsSystemInputFileVisitation() ? NumInputs |
| 2353 | : NumUserInputs; |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 2354 | for (unsigned I = 0; I < N; ++I) { |
| 2355 | bool IsSystem = I >= NumUserInputs; |
| 2356 | InputFileInfo FI = readInputFileInfo(F, I+1); |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 2357 | Listener->visitInputFile(FI.Filename, IsSystem, FI.Overridden, |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2358 | F.Kind == MK_ExplicitModule || |
| 2359 | F.Kind == MK_PrebuiltModule); |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 2360 | } |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2361 | } |
| 2362 | |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2363 | return Result; |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2364 | } |
| 2365 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2366 | case llvm::BitstreamEntry::SubBlock: |
| 2367 | switch (Entry.ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2368 | case INPUT_FILES_BLOCK_ID: |
| 2369 | F.InputFilesCursor = Stream; |
| 2370 | if (Stream.SkipBlock() || // Skip with the main cursor |
| 2371 | // Read the abbreviations |
| 2372 | ReadBlockAbbrevs(F.InputFilesCursor, INPUT_FILES_BLOCK_ID)) { |
| 2373 | Error("malformed block record in AST file"); |
| 2374 | return Failure; |
| 2375 | } |
| 2376 | continue; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2377 | |
| 2378 | case OPTIONS_BLOCK_ID: |
| 2379 | // If we're reading the first module for this group, check its options |
| 2380 | // are compatible with ours. For modules it imports, no further checking |
| 2381 | // is required, because we checked them when we built it. |
| 2382 | if (Listener && !ImportedBy) { |
| 2383 | // Should we allow the configuration of the module file to differ from |
| 2384 | // the configuration of the current translation unit in a compatible |
| 2385 | // way? |
| 2386 | // |
| 2387 | // FIXME: Allow this for files explicitly specified with -include-pch. |
| 2388 | bool AllowCompatibleConfigurationMismatch = |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2389 | F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2390 | |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2391 | Result = ReadOptionsBlock(Stream, ClientLoadCapabilities, |
| 2392 | AllowCompatibleConfigurationMismatch, |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2393 | *Listener, SuggestedPredefines); |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2394 | if (Result == Failure) { |
| 2395 | Error("malformed block record in AST file"); |
| 2396 | return Result; |
| 2397 | } |
| 2398 | |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2399 | if (DisableValidation || |
| 2400 | (AllowConfigurationMismatch && Result == ConfigurationMismatch)) |
| 2401 | Result = Success; |
| 2402 | |
Ben Langmuir | 9b1e442e | 2016-02-11 18:54:02 +0000 | [diff] [blame] | 2403 | // If we can't load the module, exit early since we likely |
| 2404 | // will rebuild the module anyway. The stream may be in the |
| 2405 | // middle of a block. |
| 2406 | if (Result != Success) |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2407 | return Result; |
| 2408 | } else if (Stream.SkipBlock()) { |
| 2409 | Error("malformed block record in AST file"); |
| 2410 | return Failure; |
| 2411 | } |
| 2412 | continue; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2413 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2414 | default: |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2415 | if (Stream.SkipBlock()) { |
| 2416 | Error("malformed block record in AST file"); |
| 2417 | return Failure; |
| 2418 | } |
| 2419 | continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2420 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2421 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2422 | case llvm::BitstreamEntry::Record: |
| 2423 | // The interesting case. |
| 2424 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | // Read and process a record. |
| 2428 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2429 | StringRef Blob; |
| 2430 | switch ((ControlRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2431 | case METADATA: { |
| 2432 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 2433 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 2434 | Diag(Record[0] < VERSION_MAJOR? diag::err_pch_version_too_old |
| 2435 | : diag::err_pch_version_too_new); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2436 | return VersionMismatch; |
| 2437 | } |
| 2438 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 2439 | bool hasErrors = Record[6]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2440 | if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) { |
| 2441 | Diag(diag::err_pch_with_compiler_errors); |
| 2442 | return HadErrors; |
| 2443 | } |
Argyrios Kyrtzidis | 70ec1c7 | 2016-07-13 20:35:26 +0000 | [diff] [blame] | 2444 | if (hasErrors) { |
| 2445 | Diags.ErrorOccurred = true; |
| 2446 | Diags.UncompilableErrorOccurred = true; |
| 2447 | Diags.UnrecoverableErrorOccurred = true; |
| 2448 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2449 | |
| 2450 | F.RelocatablePCH = Record[4]; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2451 | // Relative paths in a relocatable PCH are relative to our sysroot. |
| 2452 | if (F.RelocatablePCH) |
| 2453 | F.BaseDirectory = isysroot.empty() ? "/" : isysroot; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2454 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 2455 | F.HasTimestamps = Record[5]; |
| 2456 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2457 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2458 | StringRef ASTBranch = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2459 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2460 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 2461 | Diag(diag::err_pch_different_branch) << ASTBranch << CurBranch; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2462 | return VersionMismatch; |
| 2463 | } |
| 2464 | break; |
| 2465 | } |
| 2466 | |
| 2467 | case IMPORTS: { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2468 | // Validate the AST before processing any imports (otherwise, untangling |
| 2469 | // them can be error-prone and expensive). A module will have a name and |
| 2470 | // will already have been validated, but this catches the PCH case. |
| 2471 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2472 | return Result; |
| 2473 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2474 | // Load each of the imported PCH files. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2475 | unsigned Idx = 0, N = Record.size(); |
| 2476 | while (Idx < N) { |
| 2477 | // Read information about the AST file. |
| 2478 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 2479 | // The import location will be the local one for now; we will adjust |
| 2480 | // all import locations of module imports after the global source |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2481 | // location info are setup, in ReadAST. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2482 | SourceLocation ImportLoc = |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2483 | ReadUntranslatedSourceLocation(Record[Idx++]); |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 2484 | off_t StoredSize = (off_t)Record[Idx++]; |
| 2485 | time_t StoredModTime = (time_t)Record[Idx++]; |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2486 | ASTFileSignature StoredSignature = { |
| 2487 | {{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++], |
| 2488 | (uint32_t)Record[Idx++], (uint32_t)Record[Idx++], |
| 2489 | (uint32_t)Record[Idx++]}}}; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2490 | auto ImportedFile = ReadPath(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2491 | |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2492 | // If our client can't cope with us being out of date, we can't cope with |
| 2493 | // our dependency being missing. |
| 2494 | unsigned Capabilities = ClientLoadCapabilities; |
| 2495 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 2496 | Capabilities &= ~ARR_Missing; |
| 2497 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2498 | // Load the AST file. |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2499 | auto Result = ReadASTCore(ImportedFile, ImportedKind, ImportLoc, &F, |
| 2500 | Loaded, StoredSize, StoredModTime, |
| 2501 | StoredSignature, Capabilities); |
| 2502 | |
| 2503 | // If we diagnosed a problem, produce a backtrace. |
| 2504 | if (isDiagnosedResult(Result, Capabilities)) |
| 2505 | Diag(diag::note_module_file_imported_by) |
| 2506 | << F.FileName << !F.ModuleName.empty() << F.ModuleName; |
| 2507 | |
| 2508 | switch (Result) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2509 | case Failure: return Failure; |
| 2510 | // 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] | 2511 | case Missing: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2512 | case OutOfDate: return OutOfDate; |
| 2513 | case VersionMismatch: return VersionMismatch; |
| 2514 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 2515 | case HadErrors: return HadErrors; |
| 2516 | case Success: break; |
| 2517 | } |
| 2518 | } |
| 2519 | break; |
| 2520 | } |
| 2521 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2522 | case ORIGINAL_FILE: |
| 2523 | F.OriginalSourceFileID = FileID::get(Record[0]); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2524 | F.ActualOriginalSourceFileName = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2525 | F.OriginalSourceFileName = F.ActualOriginalSourceFileName; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2526 | ResolveImportedPath(F, F.OriginalSourceFileName); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2527 | break; |
| 2528 | |
| 2529 | case ORIGINAL_FILE_ID: |
| 2530 | F.OriginalSourceFileID = FileID::get(Record[0]); |
| 2531 | break; |
| 2532 | |
| 2533 | case ORIGINAL_PCH_DIR: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2534 | F.OriginalDir = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2535 | break; |
| 2536 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2537 | case MODULE_NAME: |
| 2538 | F.ModuleName = Blob; |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 2539 | if (Listener) |
| 2540 | Listener->ReadModuleName(F.ModuleName); |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2541 | |
| 2542 | // Validate the AST as soon as we have a name so we can exit early on |
| 2543 | // failure. |
| 2544 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2545 | return Result; |
| 2546 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2547 | break; |
| 2548 | |
Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2549 | case MODULE_DIRECTORY: { |
| 2550 | assert(!F.ModuleName.empty() && |
| 2551 | "MODULE_DIRECTORY found before MODULE_NAME"); |
| 2552 | // If we've already loaded a module map file covering this module, we may |
| 2553 | // have a better path for it (relative to the current build). |
| 2554 | Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName); |
| 2555 | if (M && M->Directory) { |
| 2556 | // If we're implicitly loading a module, the base directory can't |
| 2557 | // change between the build and use. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2558 | if (F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) { |
Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2559 | const DirectoryEntry *BuildDir = |
| 2560 | PP.getFileManager().getDirectory(Blob); |
| 2561 | if (!BuildDir || BuildDir != M->Directory) { |
| 2562 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 2563 | Diag(diag::err_imported_module_relocated) |
| 2564 | << F.ModuleName << Blob << M->Directory->getName(); |
| 2565 | return OutOfDate; |
| 2566 | } |
| 2567 | } |
| 2568 | F.BaseDirectory = M->Directory->getName(); |
| 2569 | } else { |
| 2570 | F.BaseDirectory = Blob; |
| 2571 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2572 | break; |
Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2573 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2574 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2575 | case MODULE_MAP_FILE: |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 2576 | if (ASTReadResult Result = |
| 2577 | ReadModuleMapFileBlock(Record, F, ImportedBy, ClientLoadCapabilities)) |
| 2578 | return Result; |
Ben Langmuir | 264ea15 | 2014-11-08 00:06:39 +0000 | [diff] [blame] | 2579 | break; |
| 2580 | |
Justin Bogner | ca9c0cc | 2015-06-21 20:32:36 +0000 | [diff] [blame] | 2581 | case INPUT_FILE_OFFSETS: |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2582 | NumInputs = Record[0]; |
| 2583 | NumUserInputs = Record[1]; |
Justin Bogner | 4c18324 | 2015-06-21 20:32:40 +0000 | [diff] [blame] | 2584 | F.InputFileOffsets = |
| 2585 | (const llvm::support::unaligned_uint64_t *)Blob.data(); |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2586 | F.InputFilesLoaded.resize(NumInputs); |
Argyrios Kyrtzidis | a38cb20 | 2017-01-30 06:05:58 +0000 | [diff] [blame] | 2587 | F.NumUserInputFiles = NumUserInputs; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2588 | break; |
| 2589 | } |
| 2590 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2591 | } |
| 2592 | |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2593 | ASTReader::ASTReadResult |
| 2594 | ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2595 | BitstreamCursor &Stream = F.Stream; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2596 | |
| 2597 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
| 2598 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2599 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | // Read all of the records and blocks for the AST file. |
| 2603 | RecordData Record; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2604 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2605 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2606 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2607 | switch (Entry.Kind) { |
| 2608 | case llvm::BitstreamEntry::Error: |
| 2609 | Error("error at end of module block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2610 | return Failure; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2611 | case llvm::BitstreamEntry::EndBlock: { |
Richard Smith | c0fbba7 | 2013-04-03 22:49:41 +0000 | [diff] [blame] | 2612 | // Outside of C++, we do not store a lookup map for the translation unit. |
| 2613 | // Instead, mark it as needing a lookup map to be built if this module |
| 2614 | // contains any declarations lexically within it (which it always does!). |
| 2615 | // This usually has no cost, since we very rarely need the lookup map for |
| 2616 | // the translation unit outside C++. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2617 | if (ASTContext *Ctx = ContextObj) { |
| 2618 | DeclContext *DC = Ctx->getTranslationUnitDecl(); |
| 2619 | if (DC->hasExternalLexicalStorage() && !Ctx->getLangOpts().CPlusPlus) |
| 2620 | DC->setMustBuildLookupTable(); |
| 2621 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2622 | |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2623 | return Success; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2624 | } |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2625 | case llvm::BitstreamEntry::SubBlock: |
| 2626 | switch (Entry.ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2627 | case DECLTYPES_BLOCK_ID: |
| 2628 | // We lazily load the decls block, but we want to set up the |
| 2629 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 2630 | // cursor to it, enter the block and read the abbrevs in that block. |
| 2631 | // With the main cursor, we just skip over it. |
| 2632 | F.DeclsCursor = Stream; |
| 2633 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 2634 | // Read the abbrevs. |
| 2635 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
| 2636 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2637 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2638 | } |
| 2639 | break; |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 2640 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2641 | case PREPROCESSOR_BLOCK_ID: |
| 2642 | F.MacroCursor = Stream; |
| 2643 | if (!PP.getExternalSource()) |
| 2644 | PP.setExternalSource(this); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2645 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2646 | if (Stream.SkipBlock() || |
| 2647 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
| 2648 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2649 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2650 | } |
| 2651 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
| 2652 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2653 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2654 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 2655 | F.PreprocessorDetailCursor = Stream; |
| 2656 | if (Stream.SkipBlock() || |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2657 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2658 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2659 | Error("malformed preprocessor detail record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2660 | return Failure; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2661 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2662 | F.PreprocessorDetailStartOffset |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2663 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2664 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2665 | if (!PP.getPreprocessingRecord()) |
| 2666 | PP.createPreprocessingRecord(); |
| 2667 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2668 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2669 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2670 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2671 | case SOURCE_MANAGER_BLOCK_ID: |
| 2672 | if (ReadSourceManagerBlock(F)) |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2673 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2674 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2675 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2676 | case SUBMODULE_BLOCK_ID: |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2677 | if (ASTReadResult Result = |
| 2678 | ReadSubmoduleBlock(F, ClientLoadCapabilities)) |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2679 | return Result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2680 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2681 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2682 | case COMMENTS_BLOCK_ID: { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2683 | BitstreamCursor C = Stream; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2684 | if (Stream.SkipBlock() || |
| 2685 | ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) { |
| 2686 | Error("malformed comments block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2687 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2688 | } |
| 2689 | CommentsCursors.push_back(std::make_pair(C, &F)); |
| 2690 | break; |
| 2691 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2692 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2693 | default: |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2694 | if (Stream.SkipBlock()) { |
| 2695 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2696 | return Failure; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2697 | } |
| 2698 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2699 | } |
| 2700 | continue; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2701 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2702 | case llvm::BitstreamEntry::Record: |
| 2703 | // The interesting case. |
| 2704 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2705 | } |
| 2706 | |
| 2707 | // Read and process a record. |
| 2708 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2709 | StringRef Blob; |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2710 | auto RecordType = |
| 2711 | (ASTRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob); |
| 2712 | |
| 2713 | // If we're not loading an AST context, we don't care about most records. |
| 2714 | if (!ContextObj) { |
| 2715 | switch (RecordType) { |
| 2716 | case IDENTIFIER_TABLE: |
| 2717 | case IDENTIFIER_OFFSET: |
| 2718 | case INTERESTING_IDENTIFIERS: |
| 2719 | case STATISTICS: |
| 2720 | case PP_CONDITIONAL_STACK: |
| 2721 | case PP_COUNTER_VALUE: |
| 2722 | case SOURCE_LOCATION_OFFSETS: |
| 2723 | case MODULE_OFFSET_MAP: |
| 2724 | case SOURCE_MANAGER_LINE_TABLE: |
| 2725 | case SOURCE_LOCATION_PRELOADS: |
| 2726 | case PPD_ENTITIES_OFFSETS: |
| 2727 | case HEADER_SEARCH_TABLE: |
| 2728 | case IMPORTED_MODULES: |
| 2729 | case MACRO_OFFSET: |
| 2730 | break; |
| 2731 | default: |
| 2732 | continue; |
| 2733 | } |
| 2734 | } |
| 2735 | |
| 2736 | switch (RecordType) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2737 | default: // Default behavior: ignore. |
| 2738 | break; |
| 2739 | |
| 2740 | case TYPE_OFFSET: { |
| 2741 | if (F.LocalNumTypes != 0) { |
| 2742 | Error("duplicate TYPE_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2743 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2744 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2745 | F.TypeOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2746 | F.LocalNumTypes = Record[0]; |
| 2747 | unsigned LocalBaseTypeIndex = Record[1]; |
| 2748 | F.BaseTypeIndex = getTotalNumTypes(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2749 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2750 | if (F.LocalNumTypes > 0) { |
| 2751 | // Introduce the global -> local mapping for types within this module. |
| 2752 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2753 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2754 | // Introduce the local -> global mapping for types within this module. |
| 2755 | F.TypeRemap.insertOrReplace( |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2756 | std::make_pair(LocalBaseTypeIndex, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2757 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2758 | |
| 2759 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2760 | } |
| 2761 | break; |
| 2762 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2763 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2764 | case DECL_OFFSET: { |
| 2765 | if (F.LocalNumDecls != 0) { |
| 2766 | Error("duplicate DECL_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2767 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2768 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2769 | F.DeclOffsets = (const DeclOffset *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2770 | F.LocalNumDecls = Record[0]; |
| 2771 | unsigned LocalBaseDeclID = Record[1]; |
| 2772 | F.BaseDeclID = getTotalNumDecls(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2773 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2774 | if (F.LocalNumDecls > 0) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2775 | // Introduce the global -> local mapping for declarations within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2776 | // module. |
| 2777 | GlobalDeclMap.insert( |
| 2778 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2779 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2780 | // Introduce the local -> global mapping for declarations within this |
| 2781 | // module. |
| 2782 | F.DeclRemap.insertOrReplace( |
| 2783 | std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2784 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2785 | // Introduce the global -> local mapping for declarations within this |
| 2786 | // module. |
| 2787 | F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID; |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 2788 | |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2789 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 2790 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2791 | break; |
| 2792 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2793 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2794 | case TU_UPDATE_LEXICAL: { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2795 | DeclContext *TU = ContextObj->getTranslationUnitDecl(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2796 | LexicalContents Contents( |
| 2797 | reinterpret_cast<const llvm::support::unaligned_uint32_t *>( |
| 2798 | Blob.data()), |
| 2799 | static_cast<unsigned int>(Blob.size() / 4)); |
| 2800 | TULexicalDecls.push_back(std::make_pair(&F, Contents)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2801 | TU->setHasExternalLexicalStorage(true); |
| 2802 | break; |
| 2803 | } |
| 2804 | |
| 2805 | case UPDATE_VISIBLE: { |
| 2806 | unsigned Idx = 0; |
| 2807 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 2808 | auto *Data = (const unsigned char*)Blob.data(); |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 2809 | PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&F, Data}); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 2810 | // If we've already loaded the decl, perform the updates when we finish |
| 2811 | // loading this block. |
| 2812 | if (Decl *D = GetExistingDecl(ID)) |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 2813 | PendingUpdateRecords.push_back( |
| 2814 | PendingUpdateRecord(ID, D, /*JustLoaded=*/false)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2815 | break; |
| 2816 | } |
| 2817 | |
| 2818 | case IDENTIFIER_TABLE: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2819 | F.IdentifierTableData = Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2820 | if (Record[0]) { |
Justin Bogner | da4e650 | 2014-04-14 16:34:29 +0000 | [diff] [blame] | 2821 | F.IdentifierLookupTable = ASTIdentifierLookupTable::Create( |
| 2822 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2823 | (const unsigned char *)F.IdentifierTableData + sizeof(uint32_t), |
| 2824 | (const unsigned char *)F.IdentifierTableData, |
| 2825 | ASTIdentifierLookupTrait(*this, F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2826 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2827 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
| 2828 | } |
| 2829 | break; |
| 2830 | |
| 2831 | case IDENTIFIER_OFFSET: { |
| 2832 | if (F.LocalNumIdentifiers != 0) { |
| 2833 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2834 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2835 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2836 | F.IdentifierOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2837 | F.LocalNumIdentifiers = Record[0]; |
| 2838 | unsigned LocalBaseIdentifierID = Record[1]; |
| 2839 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2840 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2841 | if (F.LocalNumIdentifiers > 0) { |
| 2842 | // Introduce the global -> local mapping for identifiers within this |
| 2843 | // module. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2844 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2845 | &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2846 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2847 | // Introduce the local -> global mapping for identifiers within this |
| 2848 | // module. |
| 2849 | F.IdentifierRemap.insertOrReplace( |
| 2850 | std::make_pair(LocalBaseIdentifierID, |
| 2851 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 2852 | |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2853 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 2854 | + F.LocalNumIdentifiers); |
| 2855 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2856 | break; |
| 2857 | } |
| 2858 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 2859 | case INTERESTING_IDENTIFIERS: |
| 2860 | F.PreloadIdentifierOffsets.assign(Record.begin(), Record.end()); |
| 2861 | break; |
| 2862 | |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2863 | case EAGERLY_DESERIALIZED_DECLS: |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 2864 | // FIXME: Skip reading this record if our ASTConsumer doesn't care |
| 2865 | // about "interesting" decls (for instance, if we're building a module). |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2866 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2867 | EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2868 | break; |
| 2869 | |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2870 | case MODULAR_CODEGEN_DECLS: |
| 2871 | // FIXME: Skip reading this record if our ASTConsumer doesn't care about |
| 2872 | // them (ie: if we're not codegenerating this module). |
| 2873 | if (F.Kind == MK_MainFile) |
| 2874 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2875 | EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2876 | break; |
| 2877 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2878 | case SPECIAL_TYPES: |
Douglas Gregor | 44180f8 | 2013-02-01 23:45:03 +0000 | [diff] [blame] | 2879 | if (SpecialTypes.empty()) { |
| 2880 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2881 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
| 2882 | break; |
| 2883 | } |
| 2884 | |
| 2885 | if (SpecialTypes.size() != Record.size()) { |
| 2886 | Error("invalid special-types record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2887 | return Failure; |
Douglas Gregor | 44180f8 | 2013-02-01 23:45:03 +0000 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 2891 | serialization::TypeID ID = getGlobalTypeID(F, Record[I]); |
| 2892 | if (!SpecialTypes[I]) |
| 2893 | SpecialTypes[I] = ID; |
| 2894 | // FIXME: If ID && SpecialTypes[I] != ID, do we need a separate |
| 2895 | // merge step? |
| 2896 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2897 | break; |
| 2898 | |
| 2899 | case STATISTICS: |
| 2900 | TotalNumStatements += Record[0]; |
| 2901 | TotalNumMacros += Record[1]; |
| 2902 | TotalLexicalDeclContexts += Record[2]; |
| 2903 | TotalVisibleDeclContexts += Record[3]; |
| 2904 | break; |
| 2905 | |
| 2906 | case UNUSED_FILESCOPED_DECLS: |
| 2907 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2908 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2909 | break; |
| 2910 | |
| 2911 | case DELEGATING_CTORS: |
| 2912 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2913 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2914 | break; |
| 2915 | |
| 2916 | case WEAK_UNDECLARED_IDENTIFIERS: |
| 2917 | if (Record.size() % 4 != 0) { |
| 2918 | Error("invalid weak identifiers record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2919 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2920 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2921 | |
| 2922 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2923 | // files. This isn't the way to do it :) |
| 2924 | WeakUndeclaredIdentifiers.clear(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2925 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2926 | // Translate the weak, undeclared identifiers into global IDs. |
| 2927 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 2928 | WeakUndeclaredIdentifiers.push_back( |
| 2929 | getGlobalIdentifierID(F, Record[I++])); |
| 2930 | WeakUndeclaredIdentifiers.push_back( |
| 2931 | getGlobalIdentifierID(F, Record[I++])); |
| 2932 | WeakUndeclaredIdentifiers.push_back( |
| 2933 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2934 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 2935 | } |
| 2936 | break; |
| 2937 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2938 | case SELECTOR_OFFSETS: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2939 | F.SelectorOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2940 | F.LocalNumSelectors = Record[0]; |
| 2941 | unsigned LocalBaseSelectorID = Record[1]; |
| 2942 | F.BaseSelectorID = getTotalNumSelectors(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2943 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2944 | if (F.LocalNumSelectors > 0) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2945 | // Introduce the global -> local mapping for selectors within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2946 | // module. |
| 2947 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2948 | |
| 2949 | // Introduce the local -> global mapping for selectors within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2950 | // module. |
| 2951 | F.SelectorRemap.insertOrReplace( |
| 2952 | std::make_pair(LocalBaseSelectorID, |
| 2953 | F.BaseSelectorID - LocalBaseSelectorID)); |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2954 | |
| 2955 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2956 | } |
| 2957 | break; |
| 2958 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2959 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2960 | case METHOD_POOL: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2961 | F.SelectorLookupTableData = (const unsigned char *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2962 | if (Record[0]) |
| 2963 | F.SelectorLookupTable |
| 2964 | = ASTSelectorLookupTable::Create( |
| 2965 | F.SelectorLookupTableData + Record[0], |
| 2966 | F.SelectorLookupTableData, |
| 2967 | ASTSelectorLookupTrait(*this, F)); |
| 2968 | TotalNumMethodPoolEntries += Record[1]; |
| 2969 | break; |
| 2970 | |
| 2971 | case REFERENCED_SELECTOR_POOL: |
| 2972 | if (!Record.empty()) { |
| 2973 | 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] | 2974 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2975 | Record[Idx++])); |
| 2976 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 2977 | getRawEncoding()); |
| 2978 | } |
| 2979 | } |
| 2980 | break; |
| 2981 | |
Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 2982 | case PP_CONDITIONAL_STACK: |
| 2983 | if (!Record.empty()) { |
| 2984 | SmallVector<PPConditionalInfo, 4> ConditionalStack; |
| 2985 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; /* in loop */) { |
| 2986 | auto Loc = ReadSourceLocation(F, Record, Idx); |
| 2987 | bool WasSkipping = Record[Idx++]; |
| 2988 | bool FoundNonSkip = Record[Idx++]; |
| 2989 | bool FoundElse = Record[Idx++]; |
| 2990 | ConditionalStack.push_back( |
| 2991 | {Loc, WasSkipping, FoundNonSkip, FoundElse}); |
| 2992 | } |
| 2993 | PP.setReplayablePreambleConditionalStack(ConditionalStack); |
| 2994 | } |
| 2995 | break; |
| 2996 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2997 | case PP_COUNTER_VALUE: |
| 2998 | if (!Record.empty() && Listener) |
| 2999 | Listener->ReadCounter(F, Record[0]); |
| 3000 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3001 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3002 | case FILE_SORTED_DECLS: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3003 | F.FileSortedDecls = (const DeclID *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3004 | F.NumFileSortedDecls = Record[0]; |
| 3005 | break; |
| 3006 | |
| 3007 | case SOURCE_LOCATION_OFFSETS: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3008 | F.SLocEntryOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3009 | F.LocalNumSLocEntries = Record[0]; |
| 3010 | unsigned SLocSpaceSize = Record[1]; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 3011 | std::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3012 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3013 | SLocSpaceSize); |
Richard Smith | 78d81ec | 2015-08-12 22:25:24 +0000 | [diff] [blame] | 3014 | if (!F.SLocEntryBaseID) { |
| 3015 | Error("ran out of source locations"); |
| 3016 | break; |
| 3017 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3018 | // Make our entry in the range map. BaseID is negative and growing, so |
| 3019 | // we invert it. Because we invert it, though, we need the other end of |
| 3020 | // the range. |
| 3021 | unsigned RangeStart = |
| 3022 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 3023 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 3024 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 3025 | |
| 3026 | // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. |
| 3027 | assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); |
| 3028 | GlobalSLocOffsetMap.insert( |
| 3029 | std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset |
| 3030 | - SLocSpaceSize,&F)); |
| 3031 | |
| 3032 | // Initialize the remapping table. |
| 3033 | // Invalid stays invalid. |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 3034 | F.SLocRemap.insertOrReplace(std::make_pair(0U, 0)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3035 | // This module. Base was 2 when being compiled. |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 3036 | F.SLocRemap.insertOrReplace(std::make_pair(2U, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3037 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3038 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3039 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
| 3040 | break; |
| 3041 | } |
| 3042 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3043 | case MODULE_OFFSET_MAP: |
| 3044 | F.ModuleOffsetMap = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3045 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3046 | |
| 3047 | case SOURCE_MANAGER_LINE_TABLE: |
| 3048 | if (ParseLineTable(F, Record)) |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3049 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3050 | break; |
| 3051 | |
| 3052 | case SOURCE_LOCATION_PRELOADS: { |
| 3053 | // Need to transform from the local view (1-based IDs) to the global view, |
| 3054 | // which is based off F.SLocEntryBaseID. |
| 3055 | if (!F.PreloadSLocEntries.empty()) { |
| 3056 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3057 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3058 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3059 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3060 | F.PreloadSLocEntries.swap(Record); |
| 3061 | break; |
| 3062 | } |
| 3063 | |
| 3064 | case EXT_VECTOR_DECLS: |
| 3065 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3066 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 3067 | break; |
| 3068 | |
| 3069 | case VTABLE_USES: |
| 3070 | if (Record.size() % 3 != 0) { |
| 3071 | Error("Invalid VTABLE_USES record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3072 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3073 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3074 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3075 | // Later tables overwrite earlier ones. |
| 3076 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 3077 | // the right way to do this. |
| 3078 | VTableUses.clear(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3079 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3080 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 3081 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 3082 | VTableUses.push_back( |
| 3083 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 3084 | VTableUses.push_back(Record[Idx++]); |
| 3085 | } |
| 3086 | break; |
| 3087 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3088 | case PENDING_IMPLICIT_INSTANTIATIONS: |
| 3089 | if (PendingInstantiations.size() % 2 != 0) { |
| 3090 | Error("Invalid existing PendingInstantiations"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3091 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3092 | } |
| 3093 | |
| 3094 | if (Record.size() % 2 != 0) { |
| 3095 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3096 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 3100 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 3101 | PendingInstantiations.push_back( |
| 3102 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3103 | } |
| 3104 | break; |
| 3105 | |
| 3106 | case SEMA_DECL_REFS: |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 3107 | if (Record.size() != 3) { |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 3108 | Error("Invalid SEMA_DECL_REFS block"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3109 | return Failure; |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 3110 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3111 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3112 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
| 3113 | break; |
| 3114 | |
| 3115 | case PPD_ENTITIES_OFFSETS: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3116 | F.PreprocessedEntityOffsets = (const PPEntityOffset *)Blob.data(); |
| 3117 | assert(Blob.size() % sizeof(PPEntityOffset) == 0); |
| 3118 | F.NumPreprocessedEntities = Blob.size() / sizeof(PPEntityOffset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3119 | |
| 3120 | unsigned LocalBasePreprocessedEntityID = Record[0]; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3121 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3122 | unsigned StartingID; |
| 3123 | if (!PP.getPreprocessingRecord()) |
| 3124 | PP.createPreprocessingRecord(); |
| 3125 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 3126 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3127 | StartingID |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3128 | = PP.getPreprocessingRecord() |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3129 | ->allocateLoadedEntities(F.NumPreprocessedEntities); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3130 | F.BasePreprocessedEntityID = StartingID; |
| 3131 | |
| 3132 | if (F.NumPreprocessedEntities > 0) { |
| 3133 | // Introduce the global -> local mapping for preprocessed entities in |
| 3134 | // this module. |
| 3135 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
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 | // Introduce the local -> global mapping for preprocessed entities in |
| 3138 | // this module. |
| 3139 | F.PreprocessedEntityRemap.insertOrReplace( |
| 3140 | std::make_pair(LocalBasePreprocessedEntityID, |
| 3141 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 3142 | } |
| 3143 | |
| 3144 | break; |
| 3145 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3146 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3147 | case DECL_UPDATE_OFFSETS: { |
| 3148 | if (Record.size() % 2 != 0) { |
| 3149 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3150 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3151 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3152 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) { |
| 3153 | GlobalDeclID ID = getGlobalDeclID(F, Record[I]); |
| 3154 | DeclUpdateOffsets[ID].push_back(std::make_pair(&F, Record[I + 1])); |
| 3155 | |
| 3156 | // If we've already loaded the decl, perform the updates when we finish |
| 3157 | // loading this block. |
| 3158 | if (Decl *D = GetExistingDecl(ID)) |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3159 | PendingUpdateRecords.push_back( |
| 3160 | PendingUpdateRecord(ID, D, /*JustLoaded=*/false)); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3161 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3162 | break; |
| 3163 | } |
| 3164 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3165 | case OBJC_CATEGORIES_MAP: { |
| 3166 | if (F.LocalNumObjCCategoriesInMap != 0) { |
| 3167 | Error("duplicate OBJC_CATEGORIES_MAP record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3168 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3169 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3170 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3171 | F.LocalNumObjCCategoriesInMap = Record[0]; |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3172 | F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3173 | break; |
| 3174 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3175 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3176 | case OBJC_CATEGORIES: |
| 3177 | F.ObjCCategories.swap(Record); |
| 3178 | break; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 3179 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3180 | case CUDA_SPECIAL_DECL_REFS: |
| 3181 | // Later tables overwrite earlier ones. |
| 3182 | // FIXME: Modules will have trouble with this. |
| 3183 | CUDASpecialDeclRefs.clear(); |
| 3184 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3185 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
| 3186 | break; |
| 3187 | |
| 3188 | case HEADER_SEARCH_TABLE: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3189 | F.HeaderFileInfoTableData = Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3190 | F.LocalNumHeaderFileInfos = Record[1]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3191 | if (Record[0]) { |
| 3192 | F.HeaderFileInfoTable |
| 3193 | = HeaderFileInfoLookupTable::Create( |
| 3194 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 3195 | (const unsigned char *)F.HeaderFileInfoTableData, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3196 | HeaderFileInfoTrait(*this, F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3197 | &PP.getHeaderSearchInfo(), |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3198 | Blob.data() + Record[2])); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3199 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3200 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 3201 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 3202 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
| 3203 | } |
| 3204 | break; |
| 3205 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3206 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3207 | case FP_PRAGMA_OPTIONS: |
| 3208 | // Later tables overwrite earlier ones. |
| 3209 | FPPragmaOptions.swap(Record); |
| 3210 | break; |
| 3211 | |
| 3212 | case OPENCL_EXTENSIONS: |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3213 | for (unsigned I = 0, E = Record.size(); I != E; ) { |
| 3214 | auto Name = ReadString(Record, I); |
| 3215 | auto &Opt = OpenCLExtensions.OptMap[Name]; |
Yaxun Liu | cc2741c | 2016-12-18 06:35:06 +0000 | [diff] [blame] | 3216 | Opt.Supported = Record[I++] != 0; |
| 3217 | Opt.Enabled = Record[I++] != 0; |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3218 | Opt.Avail = Record[I++]; |
| 3219 | Opt.Core = Record[I++]; |
| 3220 | } |
| 3221 | break; |
| 3222 | |
| 3223 | case OPENCL_EXTENSION_TYPES: |
| 3224 | for (unsigned I = 0, E = Record.size(); I != E;) { |
| 3225 | auto TypeID = static_cast<::TypeID>(Record[I++]); |
| 3226 | auto *Type = GetType(TypeID).getTypePtr(); |
| 3227 | auto NumExt = static_cast<unsigned>(Record[I++]); |
| 3228 | for (unsigned II = 0; II != NumExt; ++II) { |
| 3229 | auto Ext = ReadString(Record, I); |
| 3230 | OpenCLTypeExtMap[Type].insert(Ext); |
| 3231 | } |
| 3232 | } |
| 3233 | break; |
| 3234 | |
| 3235 | case OPENCL_EXTENSION_DECLS: |
| 3236 | for (unsigned I = 0, E = Record.size(); I != E;) { |
| 3237 | auto DeclID = static_cast<::DeclID>(Record[I++]); |
| 3238 | auto *Decl = GetDecl(DeclID); |
| 3239 | auto NumExt = static_cast<unsigned>(Record[I++]); |
| 3240 | for (unsigned II = 0; II != NumExt; ++II) { |
| 3241 | auto Ext = ReadString(Record, I); |
| 3242 | OpenCLDeclExtMap[Decl].insert(Ext); |
| 3243 | } |
| 3244 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3245 | break; |
| 3246 | |
| 3247 | case TENTATIVE_DEFINITIONS: |
| 3248 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3249 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
| 3250 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3251 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3252 | case KNOWN_NAMESPACES: |
| 3253 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3254 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
| 3255 | break; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3256 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3257 | case UNDEFINED_BUT_USED: |
| 3258 | if (UndefinedButUsed.size() % 2 != 0) { |
| 3259 | Error("Invalid existing UndefinedButUsed"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3260 | return Failure; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3261 | } |
| 3262 | |
| 3263 | if (Record.size() % 2 != 0) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3264 | Error("invalid undefined-but-used record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3265 | return Failure; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3266 | } |
| 3267 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3268 | UndefinedButUsed.push_back(getGlobalDeclID(F, Record[I++])); |
| 3269 | UndefinedButUsed.push_back( |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3270 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3271 | } |
| 3272 | break; |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 3273 | case DELETE_EXPRS_TO_ANALYZE: |
| 3274 | for (unsigned I = 0, N = Record.size(); I != N;) { |
| 3275 | DelayedDeleteExprs.push_back(getGlobalDeclID(F, Record[I++])); |
| 3276 | const uint64_t Count = Record[I++]; |
| 3277 | DelayedDeleteExprs.push_back(Count); |
| 3278 | for (uint64_t C = 0; C < Count; ++C) { |
| 3279 | DelayedDeleteExprs.push_back(ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3280 | bool IsArrayForm = Record[I++] == 1; |
| 3281 | DelayedDeleteExprs.push_back(IsArrayForm); |
| 3282 | } |
| 3283 | } |
| 3284 | break; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3285 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3286 | case IMPORTED_MODULES: { |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 3287 | if (!F.isModule()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3288 | // If we aren't loading a module (which has its own exports), make |
| 3289 | // all of the imported modules visible. |
| 3290 | // FIXME: Deal with macros-only imports. |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 3291 | for (unsigned I = 0, N = Record.size(); I != N; /**/) { |
| 3292 | unsigned GlobalID = getGlobalSubmoduleID(F, Record[I++]); |
| 3293 | SourceLocation Loc = ReadSourceLocation(F, Record, I); |
Graydon Hoare | 9c98244 | 2017-01-18 20:36:59 +0000 | [diff] [blame] | 3294 | if (GlobalID) { |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 3295 | ImportedModules.push_back(ImportedSubmodule(GlobalID, Loc)); |
Graydon Hoare | 9c98244 | 2017-01-18 20:36:59 +0000 | [diff] [blame] | 3296 | if (DeserializationListener) |
| 3297 | DeserializationListener->ModuleImportRead(GlobalID, Loc); |
| 3298 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3299 | } |
| 3300 | } |
| 3301 | break; |
| 3302 | } |
| 3303 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3304 | case MACRO_OFFSET: { |
| 3305 | if (F.LocalNumMacros != 0) { |
| 3306 | Error("duplicate MACRO_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3307 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3308 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3309 | F.MacroOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3310 | F.LocalNumMacros = Record[0]; |
| 3311 | unsigned LocalBaseMacroID = Record[1]; |
| 3312 | F.BaseMacroID = getTotalNumMacros(); |
| 3313 | |
| 3314 | if (F.LocalNumMacros > 0) { |
| 3315 | // Introduce the global -> local mapping for macros within this module. |
| 3316 | GlobalMacroMap.insert(std::make_pair(getTotalNumMacros() + 1, &F)); |
| 3317 | |
| 3318 | // Introduce the local -> global mapping for macros within this module. |
| 3319 | F.MacroRemap.insertOrReplace( |
| 3320 | std::make_pair(LocalBaseMacroID, |
| 3321 | F.BaseMacroID - LocalBaseMacroID)); |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3322 | |
| 3323 | MacrosLoaded.resize(MacrosLoaded.size() + F.LocalNumMacros); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3324 | } |
| 3325 | break; |
| 3326 | } |
| 3327 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3328 | case LATE_PARSED_TEMPLATE: { |
| 3329 | LateParsedTemplates.append(Record.begin(), Record.end()); |
| 3330 | break; |
| 3331 | } |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 3332 | |
| 3333 | case OPTIMIZE_PRAGMA_OPTIONS: |
| 3334 | if (Record.size() != 1) { |
| 3335 | Error("invalid pragma optimize record"); |
| 3336 | return Failure; |
| 3337 | } |
| 3338 | OptimizeOffPragmaLocation = ReadSourceLocation(F, Record[0]); |
| 3339 | break; |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 3340 | |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 3341 | case MSSTRUCT_PRAGMA_OPTIONS: |
| 3342 | if (Record.size() != 1) { |
| 3343 | Error("invalid pragma ms_struct record"); |
| 3344 | return Failure; |
| 3345 | } |
| 3346 | PragmaMSStructState = Record[0]; |
| 3347 | break; |
| 3348 | |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 3349 | case POINTERS_TO_MEMBERS_PRAGMA_OPTIONS: |
| 3350 | if (Record.size() != 2) { |
| 3351 | Error("invalid pragma ms_struct record"); |
| 3352 | return Failure; |
| 3353 | } |
| 3354 | PragmaMSPointersToMembersState = Record[0]; |
| 3355 | PointersToMembersPragmaLocation = ReadSourceLocation(F, Record[1]); |
| 3356 | break; |
| 3357 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 3358 | case UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES: |
| 3359 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3360 | UnusedLocalTypedefNameCandidates.push_back( |
| 3361 | getGlobalDeclID(F, Record[I])); |
| 3362 | break; |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 3363 | |
| 3364 | case CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH: |
| 3365 | if (Record.size() != 1) { |
| 3366 | Error("invalid cuda pragma options record"); |
| 3367 | return Failure; |
| 3368 | } |
| 3369 | ForceCUDAHostDeviceDepth = Record[0]; |
| 3370 | break; |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 3371 | |
| 3372 | case PACK_PRAGMA_OPTIONS: { |
| 3373 | if (Record.size() < 3) { |
| 3374 | Error("invalid pragma pack record"); |
| 3375 | return Failure; |
| 3376 | } |
| 3377 | PragmaPackCurrentValue = Record[0]; |
| 3378 | PragmaPackCurrentLocation = ReadSourceLocation(F, Record[1]); |
| 3379 | unsigned NumStackEntries = Record[2]; |
| 3380 | unsigned Idx = 3; |
| 3381 | // Reset the stack when importing a new module. |
| 3382 | PragmaPackStack.clear(); |
| 3383 | for (unsigned I = 0; I < NumStackEntries; ++I) { |
| 3384 | PragmaPackStackEntry Entry; |
| 3385 | Entry.Value = Record[Idx++]; |
| 3386 | Entry.Location = ReadSourceLocation(F, Record[Idx++]); |
| 3387 | PragmaPackStrings.push_back(ReadString(Record, Idx)); |
| 3388 | Entry.SlotLabel = PragmaPackStrings.back(); |
| 3389 | PragmaPackStack.push_back(Entry); |
| 3390 | } |
| 3391 | break; |
| 3392 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3393 | } |
| 3394 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3395 | } |
| 3396 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3397 | void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const { |
| 3398 | assert(!F.ModuleOffsetMap.empty() && "no module offset map to read"); |
| 3399 | |
| 3400 | // Additional remapping information. |
| 3401 | const unsigned char *Data = (const unsigned char*)F.ModuleOffsetMap.data(); |
| 3402 | const unsigned char *DataEnd = Data + F.ModuleOffsetMap.size(); |
| 3403 | F.ModuleOffsetMap = StringRef(); |
| 3404 | |
| 3405 | // If we see this entry before SOURCE_LOCATION_OFFSETS, add placeholders. |
| 3406 | if (F.SLocRemap.find(0) == F.SLocRemap.end()) { |
| 3407 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 3408 | F.SLocRemap.insert(std::make_pair(2U, 1)); |
| 3409 | } |
| 3410 | |
| 3411 | // Continuous range maps we may be updating in our module. |
| 3412 | typedef ContinuousRangeMap<uint32_t, int, 2>::Builder |
| 3413 | RemapBuilder; |
| 3414 | RemapBuilder SLocRemap(F.SLocRemap); |
| 3415 | RemapBuilder IdentifierRemap(F.IdentifierRemap); |
| 3416 | RemapBuilder MacroRemap(F.MacroRemap); |
| 3417 | RemapBuilder PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 3418 | RemapBuilder SubmoduleRemap(F.SubmoduleRemap); |
| 3419 | RemapBuilder SelectorRemap(F.SelectorRemap); |
| 3420 | RemapBuilder DeclRemap(F.DeclRemap); |
| 3421 | RemapBuilder TypeRemap(F.TypeRemap); |
| 3422 | |
| 3423 | while (Data < DataEnd) { |
| 3424 | // FIXME: Looking up dependency modules by filename is horrible. |
| 3425 | using namespace llvm::support; |
| 3426 | uint16_t Len = endian::readNext<uint16_t, little, unaligned>(Data); |
| 3427 | StringRef Name = StringRef((const char*)Data, Len); |
| 3428 | Data += Len; |
| 3429 | ModuleFile *OM = ModuleMgr.lookup(Name); |
| 3430 | if (!OM) { |
| 3431 | std::string Msg = |
| 3432 | "SourceLocation remap refers to unknown module, cannot find "; |
| 3433 | Msg.append(Name); |
| 3434 | Error(Msg); |
| 3435 | return; |
| 3436 | } |
| 3437 | |
| 3438 | uint32_t SLocOffset = |
| 3439 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3440 | uint32_t IdentifierIDOffset = |
| 3441 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3442 | uint32_t MacroIDOffset = |
| 3443 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3444 | uint32_t PreprocessedEntityIDOffset = |
| 3445 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3446 | uint32_t SubmoduleIDOffset = |
| 3447 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3448 | uint32_t SelectorIDOffset = |
| 3449 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3450 | uint32_t DeclIDOffset = |
| 3451 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3452 | uint32_t TypeIndexOffset = |
| 3453 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3454 | |
| 3455 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 3456 | |
| 3457 | auto mapOffset = [&](uint32_t Offset, uint32_t BaseOffset, |
| 3458 | RemapBuilder &Remap) { |
| 3459 | if (Offset != None) |
| 3460 | Remap.insert(std::make_pair(Offset, |
| 3461 | static_cast<int>(BaseOffset - Offset))); |
| 3462 | }; |
| 3463 | mapOffset(SLocOffset, OM->SLocEntryBaseOffset, SLocRemap); |
| 3464 | mapOffset(IdentifierIDOffset, OM->BaseIdentifierID, IdentifierRemap); |
| 3465 | mapOffset(MacroIDOffset, OM->BaseMacroID, MacroRemap); |
| 3466 | mapOffset(PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID, |
| 3467 | PreprocessedEntityRemap); |
| 3468 | mapOffset(SubmoduleIDOffset, OM->BaseSubmoduleID, SubmoduleRemap); |
| 3469 | mapOffset(SelectorIDOffset, OM->BaseSelectorID, SelectorRemap); |
| 3470 | mapOffset(DeclIDOffset, OM->BaseDeclID, DeclRemap); |
| 3471 | mapOffset(TypeIndexOffset, OM->BaseTypeIndex, TypeRemap); |
| 3472 | |
| 3473 | // Global -> local mappings. |
| 3474 | F.GlobalToLocalDeclIDs[OM] = DeclIDOffset; |
| 3475 | } |
| 3476 | } |
| 3477 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3478 | ASTReader::ASTReadResult |
| 3479 | ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, |
| 3480 | const ModuleFile *ImportedBy, |
| 3481 | unsigned ClientLoadCapabilities) { |
| 3482 | unsigned Idx = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3483 | F.ModuleMapPath = ReadPath(F, Record, Idx); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3484 | |
| 3485 | // Try to resolve ModuleName in the current header search context and |
| 3486 | // verify that it is found in the same module map file as we saved. If the |
| 3487 | // top-level AST file is a main file, skip this check because there is no |
| 3488 | // usable header search context. |
| 3489 | assert(!F.ModuleName.empty() && |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3490 | "MODULE_NAME should come before MODULE_MAP_FILE"); |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 3491 | if (F.Kind == MK_ImplicitModule && ModuleMgr.begin()->Kind != MK_MainFile) { |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3492 | // An implicitly-loaded module file should have its module listed in some |
| 3493 | // module map file that we've already loaded. |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3494 | Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName); |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3495 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
| 3496 | const FileEntry *ModMap = M ? Map.getModuleMapFileForUniquing(M) : nullptr; |
| 3497 | if (!ModMap) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3498 | assert(ImportedBy && "top-level import should be verified"); |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3499 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) { |
| 3500 | if (auto *ASTFE = M ? M->getASTFile() : nullptr) |
| 3501 | // This module was defined by an imported (explicit) module. |
| 3502 | Diag(diag::err_module_file_conflict) << F.ModuleName << F.FileName |
| 3503 | << ASTFE->getName(); |
| 3504 | else |
| 3505 | // This module was built with a different module map. |
| 3506 | Diag(diag::err_imported_module_not_found) |
| 3507 | << F.ModuleName << F.FileName << ImportedBy->FileName |
| 3508 | << F.ModuleMapPath; |
| 3509 | } |
| 3510 | return OutOfDate; |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3511 | } |
| 3512 | |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3513 | assert(M->Name == F.ModuleName && "found module with different name"); |
| 3514 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3515 | // Check the primary module map file. |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3516 | const FileEntry *StoredModMap = FileMgr.getFile(F.ModuleMapPath); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3517 | if (StoredModMap == nullptr || StoredModMap != ModMap) { |
| 3518 | assert(ModMap && "found module is missing module map file"); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3519 | assert(ImportedBy && "top-level import should be verified"); |
| 3520 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3521 | Diag(diag::err_imported_module_modmap_changed) |
| 3522 | << F.ModuleName << ImportedBy->FileName |
| 3523 | << ModMap->getName() << F.ModuleMapPath; |
| 3524 | return OutOfDate; |
| 3525 | } |
| 3526 | |
| 3527 | llvm::SmallPtrSet<const FileEntry *, 1> AdditionalStoredMaps; |
| 3528 | for (unsigned I = 0, N = Record[Idx++]; I < N; ++I) { |
| 3529 | // FIXME: we should use input files rather than storing names. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3530 | std::string Filename = ReadPath(F, Record, Idx); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3531 | const FileEntry *F = |
| 3532 | FileMgr.getFile(Filename, false, false); |
| 3533 | if (F == nullptr) { |
| 3534 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3535 | Error("could not find file '" + Filename +"' referenced by AST file"); |
| 3536 | return OutOfDate; |
| 3537 | } |
| 3538 | AdditionalStoredMaps.insert(F); |
| 3539 | } |
| 3540 | |
| 3541 | // Check any additional module map files (e.g. module.private.modulemap) |
| 3542 | // that are not in the pcm. |
| 3543 | if (auto *AdditionalModuleMaps = Map.getAdditionalModuleMapFiles(M)) { |
| 3544 | for (const FileEntry *ModMap : *AdditionalModuleMaps) { |
| 3545 | // Remove files that match |
| 3546 | // Note: SmallPtrSet::erase is really remove |
| 3547 | if (!AdditionalStoredMaps.erase(ModMap)) { |
| 3548 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3549 | Diag(diag::err_module_different_modmap) |
| 3550 | << F.ModuleName << /*new*/0 << ModMap->getName(); |
| 3551 | return OutOfDate; |
| 3552 | } |
| 3553 | } |
| 3554 | } |
| 3555 | |
| 3556 | // Check any additional module map files that are in the pcm, but not |
| 3557 | // found in header search. Cases that match are already removed. |
| 3558 | for (const FileEntry *ModMap : AdditionalStoredMaps) { |
| 3559 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3560 | Diag(diag::err_module_different_modmap) |
| 3561 | << F.ModuleName << /*not new*/1 << ModMap->getName(); |
| 3562 | return OutOfDate; |
| 3563 | } |
| 3564 | } |
| 3565 | |
| 3566 | if (Listener) |
| 3567 | Listener->ReadModuleMapFile(F.ModuleMapPath); |
| 3568 | return Success; |
| 3569 | } |
| 3570 | |
| 3571 | |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3572 | /// \brief Move the given method to the back of the global list of methods. |
| 3573 | static void moveMethodToBackOfGlobalList(Sema &S, ObjCMethodDecl *Method) { |
| 3574 | // Find the entry for this selector in the method pool. |
| 3575 | Sema::GlobalMethodPool::iterator Known |
| 3576 | = S.MethodPool.find(Method->getSelector()); |
| 3577 | if (Known == S.MethodPool.end()) |
| 3578 | return; |
| 3579 | |
| 3580 | // Retrieve the appropriate method list. |
| 3581 | ObjCMethodList &Start = Method->isInstanceMethod()? Known->second.first |
| 3582 | : Known->second.second; |
| 3583 | bool Found = false; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3584 | for (ObjCMethodList *List = &Start; List; List = List->getNext()) { |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3585 | if (!Found) { |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3586 | if (List->getMethod() == Method) { |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3587 | Found = true; |
| 3588 | } else { |
| 3589 | // Keep searching. |
| 3590 | continue; |
| 3591 | } |
| 3592 | } |
| 3593 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3594 | if (List->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3595 | List->setMethod(List->getNext()->getMethod()); |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3596 | else |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3597 | List->setMethod(Method); |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3598 | } |
| 3599 | } |
| 3600 | |
Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 3601 | void ASTReader::makeNamesVisible(const HiddenNames &Names, Module *Owner) { |
Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 3602 | assert(Owner->NameVisibility != Module::Hidden && "nothing to make visible?"); |
Richard Smith | 20e883e | 2015-04-29 23:20:19 +0000 | [diff] [blame] | 3603 | for (Decl *D : Names) { |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 3604 | bool wasHidden = D->isHidden(); |
| 3605 | D->setVisibleDespiteOwningModule(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3606 | |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3607 | if (wasHidden && SemaObj) { |
| 3608 | if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D)) { |
| 3609 | moveMethodToBackOfGlobalList(*SemaObj, Method); |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3610 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3611 | } |
| 3612 | } |
| 3613 | } |
| 3614 | |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3615 | void ASTReader::makeModuleVisible(Module *Mod, |
Argyrios Kyrtzidis | 125df05 | 2013-02-01 16:36:12 +0000 | [diff] [blame] | 3616 | Module::NameVisibilityKind NameVisibility, |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 3617 | SourceLocation ImportLoc) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3618 | llvm::SmallPtrSet<Module *, 4> Visited; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3619 | SmallVector<Module *, 4> Stack; |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3620 | Stack.push_back(Mod); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3621 | while (!Stack.empty()) { |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3622 | Mod = Stack.pop_back_val(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3623 | |
| 3624 | if (NameVisibility <= Mod->NameVisibility) { |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3625 | // This module already has this level of visibility (or greater), so |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3626 | // there is nothing more to do. |
| 3627 | continue; |
| 3628 | } |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3629 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3630 | if (!Mod->isAvailable()) { |
| 3631 | // Modules that aren't available cannot be made visible. |
| 3632 | continue; |
| 3633 | } |
| 3634 | |
| 3635 | // Update the module's name visibility. |
| 3636 | Mod->NameVisibility = NameVisibility; |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3637 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3638 | // If we've already deserialized any names from this module, |
| 3639 | // mark them as visible. |
| 3640 | HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod); |
| 3641 | if (Hidden != HiddenNamesMap.end()) { |
Richard Smith | 57721ac | 2014-07-21 04:10:40 +0000 | [diff] [blame] | 3642 | auto HiddenNames = std::move(*Hidden); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3643 | HiddenNamesMap.erase(Hidden); |
Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 3644 | makeNamesVisible(HiddenNames.second, HiddenNames.first); |
Richard Smith | 57721ac | 2014-07-21 04:10:40 +0000 | [diff] [blame] | 3645 | assert(HiddenNamesMap.find(Mod) == HiddenNamesMap.end() && |
| 3646 | "making names visible added hidden names"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3647 | } |
Dmitri Gribenko | e9bcf5b | 2013-11-04 21:51:33 +0000 | [diff] [blame] | 3648 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3649 | // Push any exported modules onto the stack to be marked as visible. |
Argyrios Kyrtzidis | 8739f7b | 2013-02-19 19:34:40 +0000 | [diff] [blame] | 3650 | SmallVector<Module *, 16> Exports; |
| 3651 | Mod->getExportedModules(Exports); |
| 3652 | for (SmallVectorImpl<Module *>::iterator |
| 3653 | I = Exports.begin(), E = Exports.end(); I != E; ++I) { |
| 3654 | Module *Exported = *I; |
David Blaikie | 82e95a3 | 2014-11-19 07:49:47 +0000 | [diff] [blame] | 3655 | if (Visited.insert(Exported).second) |
Argyrios Kyrtzidis | 8739f7b | 2013-02-19 19:34:40 +0000 | [diff] [blame] | 3656 | Stack.push_back(Exported); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3657 | } |
| 3658 | } |
| 3659 | } |
| 3660 | |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 3661 | /// We've merged the definition \p MergedDef into the existing definition |
| 3662 | /// \p Def. Ensure that \p Def is made visible whenever \p MergedDef is made |
| 3663 | /// visible. |
| 3664 | void ASTReader::mergeDefinitionVisibility(NamedDecl *Def, |
| 3665 | NamedDecl *MergedDef) { |
Benjamin Kramer | a72a70a | 2016-10-17 13:00:44 +0000 | [diff] [blame] | 3666 | // FIXME: This doesn't correctly handle the case where MergedDef is visible |
| 3667 | // in modules other than its owning module. We should instead give the |
| 3668 | // ASTContext a list of merged definitions for Def. |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 3669 | if (Def->isHidden()) { |
| 3670 | // If MergedDef is visible or becomes visible, make the definition visible. |
Benjamin Kramer | a72a70a | 2016-10-17 13:00:44 +0000 | [diff] [blame] | 3671 | if (!MergedDef->isHidden()) |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 3672 | Def->setVisibleDespiteOwningModule(); |
Benjamin Kramer | a72a70a | 2016-10-17 13:00:44 +0000 | [diff] [blame] | 3673 | else if (getContext().getLangOpts().ModulesLocalVisibility) { |
| 3674 | getContext().mergeDefinitionIntoModule( |
| 3675 | Def, MergedDef->getImportedOwningModule(), |
| 3676 | /*NotifyListeners*/ false); |
| 3677 | PendingMergedDefinitionsToDeduplicate.insert(Def); |
| 3678 | } else { |
| 3679 | auto SubmoduleID = MergedDef->getOwningModuleID(); |
| 3680 | assert(SubmoduleID && "hidden definition in no module"); |
| 3681 | HiddenNamesMap[getSubmodule(SubmoduleID)].push_back(Def); |
| 3682 | } |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 3683 | } |
| 3684 | } |
| 3685 | |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3686 | bool ASTReader::loadGlobalIndex() { |
| 3687 | if (GlobalIndex) |
| 3688 | return false; |
| 3689 | |
| 3690 | if (TriedLoadingGlobalIndex || !UseGlobalIndex || |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3691 | !PP.getLangOpts().Modules) |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3692 | return true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3693 | |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3694 | // Try to load the global index. |
| 3695 | TriedLoadingGlobalIndex = true; |
| 3696 | StringRef ModuleCachePath |
| 3697 | = getPreprocessor().getHeaderSearchInfo().getModuleCachePath(); |
| 3698 | std::pair<GlobalModuleIndex *, GlobalModuleIndex::ErrorCode> Result |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3699 | = GlobalModuleIndex::readIndex(ModuleCachePath); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3700 | if (!Result.first) |
| 3701 | return true; |
| 3702 | |
| 3703 | GlobalIndex.reset(Result.first); |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 3704 | ModuleMgr.setGlobalIndex(GlobalIndex.get()); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3705 | return false; |
| 3706 | } |
| 3707 | |
| 3708 | bool ASTReader::isGlobalIndexUnavailable() const { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3709 | return PP.getLangOpts().Modules && UseGlobalIndex && |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3710 | !hasGlobalIndex() && TriedLoadingGlobalIndex; |
| 3711 | } |
| 3712 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3713 | static void updateModuleTimestamp(ModuleFile &MF) { |
| 3714 | // Overwrite the timestamp file contents so that file's mtime changes. |
| 3715 | std::string TimestampFilename = MF.getTimestampFilename(); |
Rafael Espindola | dae941a | 2014-08-25 18:17:04 +0000 | [diff] [blame] | 3716 | std::error_code EC; |
| 3717 | llvm::raw_fd_ostream OS(TimestampFilename, EC, llvm::sys::fs::F_Text); |
| 3718 | if (EC) |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3719 | return; |
| 3720 | OS << "Timestamp file\n"; |
Alex Lorenz | 0bafa02 | 2017-06-02 10:36:56 +0000 | [diff] [blame] | 3721 | OS.close(); |
| 3722 | OS.clear_error(); // Avoid triggering a fatal error. |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3723 | } |
| 3724 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3725 | /// \brief Given a cursor at the start of an AST file, scan ahead and drop the |
| 3726 | /// cursor into the start of the given block ID, returning false on success and |
| 3727 | /// true on failure. |
| 3728 | static bool SkipCursorToBlock(BitstreamCursor &Cursor, unsigned BlockID) { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3729 | while (true) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3730 | llvm::BitstreamEntry Entry = Cursor.advance(); |
| 3731 | switch (Entry.Kind) { |
| 3732 | case llvm::BitstreamEntry::Error: |
| 3733 | case llvm::BitstreamEntry::EndBlock: |
| 3734 | return true; |
| 3735 | |
| 3736 | case llvm::BitstreamEntry::Record: |
| 3737 | // Ignore top-level records. |
| 3738 | Cursor.skipRecord(Entry.ID); |
| 3739 | break; |
| 3740 | |
| 3741 | case llvm::BitstreamEntry::SubBlock: |
| 3742 | if (Entry.ID == BlockID) { |
| 3743 | if (Cursor.EnterSubBlock(BlockID)) |
| 3744 | return true; |
| 3745 | // Found it! |
| 3746 | return false; |
| 3747 | } |
| 3748 | |
| 3749 | if (Cursor.SkipBlock()) |
| 3750 | return true; |
| 3751 | } |
| 3752 | } |
| 3753 | } |
| 3754 | |
Benjamin Kramer | 0772c42 | 2016-02-13 13:42:54 +0000 | [diff] [blame] | 3755 | ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3756 | ModuleKind Type, |
| 3757 | SourceLocation ImportLoc, |
Graydon Hoare | e7196af | 2016-12-09 21:45:49 +0000 | [diff] [blame] | 3758 | unsigned ClientLoadCapabilities, |
| 3759 | SmallVectorImpl<ImportedSubmodule> *Imported) { |
Argyrios Kyrtzidis | dc9fdaf | 2013-05-24 05:44:08 +0000 | [diff] [blame] | 3760 | llvm::SaveAndRestore<SourceLocation> |
| 3761 | SetCurImportLocRAII(CurrentImportLoc, ImportLoc); |
| 3762 | |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 3763 | // Defer any pending actions until we get to the end of reading the AST file. |
| 3764 | Deserializing AnASTFile(this); |
| 3765 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3766 | // Bump the generation number. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3767 | unsigned PreviousGeneration = 0; |
| 3768 | if (ContextObj) |
| 3769 | PreviousGeneration = incrementGeneration(*ContextObj); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3770 | |
| 3771 | unsigned NumModules = ModuleMgr.size(); |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3772 | SmallVector<ImportedModule, 4> Loaded; |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 3773 | switch (ASTReadResult ReadResult = |
| 3774 | ReadASTCore(FileName, Type, ImportLoc, |
| 3775 | /*ImportedBy=*/nullptr, Loaded, 0, 0, |
| 3776 | ASTFileSignature(), ClientLoadCapabilities)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3777 | case Failure: |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3778 | case Missing: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3779 | case OutOfDate: |
| 3780 | case VersionMismatch: |
| 3781 | case ConfigurationMismatch: |
Ben Langmuir | 9801b25 | 2014-06-20 00:24:56 +0000 | [diff] [blame] | 3782 | case HadErrors: { |
| 3783 | llvm::SmallPtrSet<ModuleFile *, 4> LoadedSet; |
| 3784 | for (const ImportedModule &IM : Loaded) |
| 3785 | LoadedSet.insert(IM.Mod); |
| 3786 | |
Duncan P. N. Exon Smith | 8e6bc197 | 2017-01-28 23:02:12 +0000 | [diff] [blame] | 3787 | ModuleMgr.removeModules(ModuleMgr.begin() + NumModules, LoadedSet, |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3788 | PP.getLangOpts().Modules |
Duncan P. N. Exon Smith | 8e6bc197 | 2017-01-28 23:02:12 +0000 | [diff] [blame] | 3789 | ? &PP.getHeaderSearchInfo().getModuleMap() |
| 3790 | : nullptr); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3791 | |
| 3792 | // If we find that any modules are unusable, the global index is going |
| 3793 | // to be out-of-date. Just remove it. |
| 3794 | GlobalIndex.reset(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3795 | ModuleMgr.setGlobalIndex(nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3796 | return ReadResult; |
Ben Langmuir | 9801b25 | 2014-06-20 00:24:56 +0000 | [diff] [blame] | 3797 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3798 | case Success: |
| 3799 | break; |
| 3800 | } |
| 3801 | |
| 3802 | // Here comes stuff that we only do once the entire chain is loaded. |
| 3803 | |
| 3804 | // Load the AST blocks of all of the modules that we loaded. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3805 | for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(), |
| 3806 | MEnd = Loaded.end(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3807 | M != MEnd; ++M) { |
| 3808 | ModuleFile &F = *M->Mod; |
| 3809 | |
| 3810 | // Read the AST block. |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3811 | if (ASTReadResult Result = ReadASTBlock(F, ClientLoadCapabilities)) |
| 3812 | return Result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3813 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3814 | // Read the extension blocks. |
| 3815 | while (!SkipCursorToBlock(F.Stream, EXTENSION_BLOCK_ID)) { |
| 3816 | if (ASTReadResult Result = ReadExtensionBlock(F)) |
| 3817 | return Result; |
| 3818 | } |
| 3819 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3820 | // 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] | 3821 | // bits of all files we've seen. |
| 3822 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 3823 | TotalModulesSizeInBits += F.SizeInBits; |
| 3824 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3825 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3826 | // Preload SLocEntries. |
| 3827 | for (unsigned I = 0, N = F.PreloadSLocEntries.size(); I != N; ++I) { |
| 3828 | int Index = int(F.PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
| 3829 | // Load it through the SourceManager and don't call ReadSLocEntry() |
| 3830 | // directly because the entry may have already been loaded in which case |
| 3831 | // calling ReadSLocEntry() directly would trigger an assertion in |
| 3832 | // SourceManager. |
| 3833 | SourceMgr.getLoadedSLocEntryByID(Index); |
| 3834 | } |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3835 | |
Richard Smith | ea74148 | 2017-05-01 22:10:47 +0000 | [diff] [blame] | 3836 | // Map the original source file ID into the ID space of the current |
| 3837 | // compilation. |
| 3838 | if (F.OriginalSourceFileID.isValid()) { |
| 3839 | F.OriginalSourceFileID = FileID::get( |
| 3840 | F.SLocEntryBaseID + F.OriginalSourceFileID.getOpaqueValue() - 1); |
| 3841 | } |
| 3842 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3843 | // Preload all the pending interesting identifiers by marking them out of |
| 3844 | // date. |
| 3845 | for (auto Offset : F.PreloadIdentifierOffsets) { |
| 3846 | const unsigned char *Data = reinterpret_cast<const unsigned char *>( |
| 3847 | F.IdentifierTableData + Offset); |
| 3848 | |
| 3849 | ASTIdentifierLookupTrait Trait(*this, F); |
| 3850 | auto KeyDataLen = Trait.ReadKeyDataLength(Data); |
| 3851 | auto Key = Trait.ReadKey(Data, KeyDataLen.first); |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 3852 | auto &II = PP.getIdentifierTable().getOwn(Key); |
| 3853 | II.setOutOfDate(true); |
| 3854 | |
| 3855 | // Mark this identifier as being from an AST file so that we can track |
| 3856 | // whether we need to serialize it. |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 3857 | markIdentifierFromAST(*this, II); |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 3858 | |
| 3859 | // Associate the ID with the identifier so that the writer can reuse it. |
| 3860 | auto ID = Trait.ReadIdentifierID(Data + KeyDataLen.first); |
| 3861 | SetIdentifierInfo(ID, &II); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3862 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3863 | } |
| 3864 | |
Douglas Gregor | 603cd86 | 2013-03-22 18:50:14 +0000 | [diff] [blame] | 3865 | // Setup the import locations and notify the module manager that we've |
| 3866 | // committed to these module files. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3867 | for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(), |
| 3868 | MEnd = Loaded.end(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3869 | M != MEnd; ++M) { |
| 3870 | ModuleFile &F = *M->Mod; |
Douglas Gregor | 603cd86 | 2013-03-22 18:50:14 +0000 | [diff] [blame] | 3871 | |
| 3872 | ModuleMgr.moduleFileAccepted(&F); |
| 3873 | |
| 3874 | // Set the import location. |
Argyrios Kyrtzidis | 71c1af8 | 2013-02-01 16:36:14 +0000 | [diff] [blame] | 3875 | F.DirectImportLoc = ImportLoc; |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 3876 | // FIXME: We assume that locations from PCH / preamble do not need |
| 3877 | // any translation. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3878 | if (!M->ImportedBy) |
| 3879 | F.ImportLoc = M->ImportLoc; |
| 3880 | else |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 3881 | F.ImportLoc = TranslateSourceLocation(*M->ImportedBy, M->ImportLoc); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3882 | } |
| 3883 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3884 | if (!PP.getLangOpts().CPlusPlus || |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 3885 | (Type != MK_ImplicitModule && Type != MK_ExplicitModule && |
| 3886 | Type != MK_PrebuiltModule)) { |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3887 | // Mark all of the identifiers in the identifier table as being out of date, |
| 3888 | // so that various accessors know to check the loaded modules when the |
| 3889 | // identifier is used. |
| 3890 | // |
| 3891 | // For C++ modules, we don't need information on many identifiers (just |
| 3892 | // those that provide macros or are poisoned), so we mark all of |
| 3893 | // the interesting ones via PreloadIdentifierOffsets. |
| 3894 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 3895 | IdEnd = PP.getIdentifierTable().end(); |
| 3896 | Id != IdEnd; ++Id) |
| 3897 | Id->second->setOutOfDate(true); |
| 3898 | } |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 3899 | // Mark selectors as out of date. |
| 3900 | for (auto Sel : SelectorGeneration) |
| 3901 | SelectorOutOfDate[Sel.first] = true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3902 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3903 | // Resolve any unresolved module exports. |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3904 | for (unsigned I = 0, N = UnresolvedModuleRefs.size(); I != N; ++I) { |
| 3905 | UnresolvedModuleRef &Unresolved = UnresolvedModuleRefs[I]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3906 | SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID); |
| 3907 | Module *ResolvedMod = getSubmodule(GlobalID); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3908 | |
| 3909 | switch (Unresolved.Kind) { |
| 3910 | case UnresolvedModuleRef::Conflict: |
| 3911 | if (ResolvedMod) { |
| 3912 | Module::Conflict Conflict; |
| 3913 | Conflict.Other = ResolvedMod; |
| 3914 | Conflict.Message = Unresolved.String.str(); |
| 3915 | Unresolved.Mod->Conflicts.push_back(Conflict); |
| 3916 | } |
| 3917 | continue; |
| 3918 | |
| 3919 | case UnresolvedModuleRef::Import: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3920 | if (ResolvedMod) |
Richard Smith | 38477db | 2015-05-02 00:45:56 +0000 | [diff] [blame] | 3921 | Unresolved.Mod->Imports.insert(ResolvedMod); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3922 | continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3923 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3924 | case UnresolvedModuleRef::Export: |
| 3925 | if (ResolvedMod || Unresolved.IsWildcard) |
| 3926 | Unresolved.Mod->Exports.push_back( |
| 3927 | Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard)); |
| 3928 | continue; |
| 3929 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3930 | } |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3931 | UnresolvedModuleRefs.clear(); |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 3932 | |
Graydon Hoare | e7196af | 2016-12-09 21:45:49 +0000 | [diff] [blame] | 3933 | if (Imported) |
| 3934 | Imported->append(ImportedModules.begin(), |
| 3935 | ImportedModules.end()); |
| 3936 | |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 3937 | // FIXME: How do we load the 'use'd modules? They may not be submodules. |
| 3938 | // Might be unnecessary as use declarations are only used to build the |
| 3939 | // module itself. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3940 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3941 | if (ContextObj) |
| 3942 | InitializeContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3943 | |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 3944 | if (SemaObj) |
| 3945 | UpdateSema(); |
| 3946 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3947 | if (DeserializationListener) |
| 3948 | DeserializationListener->ReaderInitialized(this); |
| 3949 | |
| 3950 | ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule(); |
Yaron Keren | 8b56366 | 2015-10-03 10:46:20 +0000 | [diff] [blame] | 3951 | if (PrimaryModule.OriginalSourceFileID.isValid()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3952 | // If this AST file is a precompiled preamble, then set the |
| 3953 | // preamble file ID of the source manager to the file source file |
| 3954 | // from which the preamble was built. |
| 3955 | if (Type == MK_Preamble) { |
| 3956 | SourceMgr.setPreambleFileID(PrimaryModule.OriginalSourceFileID); |
| 3957 | } else if (Type == MK_MainFile) { |
| 3958 | SourceMgr.setMainFileID(PrimaryModule.OriginalSourceFileID); |
| 3959 | } |
| 3960 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3961 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3962 | // For any Objective-C class definitions we have already loaded, make sure |
| 3963 | // that we load any additional categories. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3964 | if (ContextObj) { |
| 3965 | for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) { |
| 3966 | loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(), |
| 3967 | ObjCClassesLoaded[I], |
| 3968 | PreviousGeneration); |
| 3969 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3970 | } |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3971 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3972 | if (PP.getHeaderSearchInfo() |
| 3973 | .getHeaderSearchOpts() |
| 3974 | .ModulesValidateOncePerBuildSession) { |
| 3975 | // Now we are certain that the module and all modules it depends on are |
| 3976 | // up to date. Create or update timestamp files for modules that are |
| 3977 | // located in the module cache (not for PCH files that could be anywhere |
| 3978 | // in the filesystem). |
| 3979 | for (unsigned I = 0, N = Loaded.size(); I != N; ++I) { |
| 3980 | ImportedModule &M = Loaded[I]; |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3981 | if (M.Mod->Kind == MK_ImplicitModule) { |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3982 | updateModuleTimestamp(*M.Mod); |
| 3983 | } |
| 3984 | } |
| 3985 | } |
| 3986 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3987 | return Success; |
| 3988 | } |
| 3989 | |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 3990 | static ASTFileSignature readASTFileSignature(StringRef PCH); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 3991 | |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 3992 | /// \brief Whether \p Stream starts with the AST/PCH file magic number 'CPCH'. |
| 3993 | static bool startsWithASTFileMagic(BitstreamCursor &Stream) { |
Peter Collingbourne | 028eb5a | 2016-11-02 00:08:19 +0000 | [diff] [blame] | 3994 | return Stream.canSkipToPos(4) && |
| 3995 | Stream.Read(8) == 'C' && |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 3996 | Stream.Read(8) == 'P' && |
| 3997 | Stream.Read(8) == 'C' && |
| 3998 | Stream.Read(8) == 'H'; |
| 3999 | } |
| 4000 | |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4001 | static unsigned moduleKindForDiagnostic(ModuleKind Kind) { |
| 4002 | switch (Kind) { |
| 4003 | case MK_PCH: |
| 4004 | return 0; // PCH |
| 4005 | case MK_ImplicitModule: |
| 4006 | case MK_ExplicitModule: |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 4007 | case MK_PrebuiltModule: |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4008 | return 1; // module |
| 4009 | case MK_MainFile: |
| 4010 | case MK_Preamble: |
| 4011 | return 2; // main source file |
| 4012 | } |
| 4013 | llvm_unreachable("unknown module kind"); |
| 4014 | } |
| 4015 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4016 | ASTReader::ASTReadResult |
| 4017 | ASTReader::ReadASTCore(StringRef FileName, |
| 4018 | ModuleKind Type, |
| 4019 | SourceLocation ImportLoc, |
| 4020 | ModuleFile *ImportedBy, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4021 | SmallVectorImpl<ImportedModule> &Loaded, |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4022 | off_t ExpectedSize, time_t ExpectedModTime, |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4023 | ASTFileSignature ExpectedSignature, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4024 | unsigned ClientLoadCapabilities) { |
| 4025 | ModuleFile *M; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4026 | std::string ErrorStr; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4027 | ModuleManager::AddModuleResult AddResult |
| 4028 | = ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy, |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 4029 | getGeneration(), ExpectedSize, ExpectedModTime, |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4030 | ExpectedSignature, readASTFileSignature, |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4031 | M, ErrorStr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4032 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4033 | switch (AddResult) { |
| 4034 | case ModuleManager::AlreadyLoaded: |
| 4035 | return Success; |
| 4036 | |
| 4037 | case ModuleManager::NewlyLoaded: |
| 4038 | // Load module file below. |
| 4039 | break; |
| 4040 | |
| 4041 | case ModuleManager::Missing: |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 4042 | // The module file was missing; if the client can handle that, return |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4043 | // it. |
| 4044 | if (ClientLoadCapabilities & ARR_Missing) |
| 4045 | return Missing; |
| 4046 | |
| 4047 | // Otherwise, return an error. |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4048 | Diag(diag::err_module_file_not_found) << moduleKindForDiagnostic(Type) |
Adrian Prantl | b3b5a73 | 2016-08-29 20:46:59 +0000 | [diff] [blame] | 4049 | << FileName << !ErrorStr.empty() |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4050 | << ErrorStr; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4051 | return Failure; |
| 4052 | |
| 4053 | case ModuleManager::OutOfDate: |
| 4054 | // We couldn't load the module file because it is out-of-date. If the |
| 4055 | // client can handle out-of-date, return it. |
| 4056 | if (ClientLoadCapabilities & ARR_OutOfDate) |
| 4057 | return OutOfDate; |
| 4058 | |
| 4059 | // Otherwise, return an error. |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4060 | Diag(diag::err_module_file_out_of_date) << moduleKindForDiagnostic(Type) |
Adrian Prantl | 9a06a88 | 2016-08-29 20:46:56 +0000 | [diff] [blame] | 4061 | << FileName << !ErrorStr.empty() |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4062 | << ErrorStr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4063 | return Failure; |
| 4064 | } |
| 4065 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4066 | assert(M && "Missing module file"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4067 | |
| 4068 | // FIXME: This seems rather a hack. Should CurrentDir be part of the |
| 4069 | // module? |
| 4070 | if (FileName != "-") { |
| 4071 | CurrentDir = llvm::sys::path::parent_path(FileName); |
| 4072 | if (CurrentDir.empty()) CurrentDir = "."; |
| 4073 | } |
| 4074 | |
| 4075 | ModuleFile &F = *M; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4076 | BitstreamCursor &Stream = F.Stream; |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4077 | Stream = BitstreamCursor(PCHContainerRdr.ExtractPCH(*F.Buffer)); |
Adrian Prantl | cbc368c | 2015-02-25 02:44:04 +0000 | [diff] [blame] | 4078 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4079 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4080 | // Sniff for the signature. |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4081 | if (!startsWithASTFileMagic(Stream)) { |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4082 | Diag(diag::err_module_file_invalid) << moduleKindForDiagnostic(Type) |
| 4083 | << FileName; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4084 | return Failure; |
| 4085 | } |
| 4086 | |
| 4087 | // This is used for compatibility with older PCH formats. |
| 4088 | bool HaveReadControlBlock = false; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4089 | while (true) { |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4090 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4091 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4092 | switch (Entry.Kind) { |
| 4093 | case llvm::BitstreamEntry::Error: |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4094 | case llvm::BitstreamEntry::Record: |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4095 | case llvm::BitstreamEntry::EndBlock: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4096 | Error("invalid record at top-level of AST file"); |
| 4097 | return Failure; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4098 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4099 | case llvm::BitstreamEntry::SubBlock: |
| 4100 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4101 | } |
| 4102 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4103 | switch (Entry.ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4104 | case CONTROL_BLOCK_ID: |
| 4105 | HaveReadControlBlock = true; |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4106 | switch (ReadControlBlock(F, Loaded, ImportedBy, ClientLoadCapabilities)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4107 | case Success: |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4108 | // Check that we didn't try to load a non-module AST file as a module. |
| 4109 | // |
| 4110 | // FIXME: Should we also perform the converse check? Loading a module as |
| 4111 | // a PCH file sort of works, but it's a bit wonky. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 4112 | if ((Type == MK_ImplicitModule || Type == MK_ExplicitModule || |
| 4113 | Type == MK_PrebuiltModule) && |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4114 | F.ModuleName.empty()) { |
| 4115 | auto Result = (Type == MK_ImplicitModule) ? OutOfDate : Failure; |
| 4116 | if (Result != OutOfDate || |
| 4117 | (ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 4118 | Diag(diag::err_module_file_not_module) << FileName; |
| 4119 | return Result; |
| 4120 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4121 | break; |
| 4122 | |
| 4123 | case Failure: return Failure; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4124 | case Missing: return Missing; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4125 | case OutOfDate: return OutOfDate; |
| 4126 | case VersionMismatch: return VersionMismatch; |
| 4127 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 4128 | case HadErrors: return HadErrors; |
| 4129 | } |
| 4130 | break; |
Richard Smith | f8c3255 | 2015-09-02 17:45:54 +0000 | [diff] [blame] | 4131 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4132 | case AST_BLOCK_ID: |
| 4133 | if (!HaveReadControlBlock) { |
| 4134 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 4135 | Diag(diag::err_pch_version_too_old); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4136 | return VersionMismatch; |
| 4137 | } |
| 4138 | |
| 4139 | // Record that we've loaded this module. |
| 4140 | Loaded.push_back(ImportedModule(M, ImportedBy, ImportLoc)); |
| 4141 | return Success; |
| 4142 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4143 | case UNHASHED_CONTROL_BLOCK_ID: |
| 4144 | // This block is handled using look-ahead during ReadControlBlock. We |
| 4145 | // shouldn't get here! |
| 4146 | Error("malformed block record in AST file"); |
| 4147 | return Failure; |
| 4148 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4149 | default: |
| 4150 | if (Stream.SkipBlock()) { |
| 4151 | Error("malformed block record in AST file"); |
| 4152 | return Failure; |
| 4153 | } |
| 4154 | break; |
| 4155 | } |
| 4156 | } |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4157 | |
| 4158 | return Success; |
| 4159 | } |
| 4160 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4161 | ASTReader::ASTReadResult |
| 4162 | ASTReader::readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy, |
| 4163 | unsigned ClientLoadCapabilities) { |
| 4164 | const HeaderSearchOptions &HSOpts = |
| 4165 | PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 4166 | bool AllowCompatibleConfigurationMismatch = |
| 4167 | F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule; |
| 4168 | |
| 4169 | ASTReadResult Result = readUnhashedControlBlockImpl( |
| 4170 | &F, F.Data, ClientLoadCapabilities, AllowCompatibleConfigurationMismatch, |
| 4171 | Listener.get(), |
| 4172 | WasImportedBy ? false : HSOpts.ModulesValidateDiagnosticOptions); |
| 4173 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4174 | // If F was directly imported by another module, it's implicitly validated by |
| 4175 | // the importing module. |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4176 | if (DisableValidation || WasImportedBy || |
| 4177 | (AllowConfigurationMismatch && Result == ConfigurationMismatch)) |
| 4178 | return Success; |
| 4179 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4180 | if (Result == Failure) { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4181 | Error("malformed block record in AST file"); |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4182 | return Failure; |
| 4183 | } |
| 4184 | |
| 4185 | if (Result == OutOfDate && F.Kind == MK_ImplicitModule) { |
| 4186 | // If this module has already been finalized in the PCMCache, we're stuck |
| 4187 | // with it; we can only load a single version of each module. |
| 4188 | // |
| 4189 | // This can happen when a module is imported in two contexts: in one, as a |
| 4190 | // user module; in another, as a system module (due to an import from |
| 4191 | // another module marked with the [system] flag). It usually indicates a |
| 4192 | // bug in the module map: this module should also be marked with [system]. |
| 4193 | // |
| 4194 | // If -Wno-system-headers (the default), and the first import is as a |
| 4195 | // system module, then validation will fail during the as-user import, |
| 4196 | // since -Werror flags won't have been validated. However, it's reasonable |
| 4197 | // to treat this consistently as a system module. |
| 4198 | // |
| 4199 | // If -Wsystem-headers, the PCM on disk was built with |
| 4200 | // -Wno-system-headers, and the first import is as a user module, then |
| 4201 | // validation will fail during the as-system import since the PCM on disk |
| 4202 | // doesn't guarantee that -Werror was respected. However, the -Werror |
| 4203 | // flags were checked during the initial as-user import. |
| 4204 | if (PCMCache.isBufferFinal(F.FileName)) { |
| 4205 | Diag(diag::warn_module_system_bit_conflict) << F.FileName; |
| 4206 | return Success; |
| 4207 | } |
| 4208 | } |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4209 | |
| 4210 | return Result; |
| 4211 | } |
| 4212 | |
| 4213 | ASTReader::ASTReadResult ASTReader::readUnhashedControlBlockImpl( |
| 4214 | ModuleFile *F, llvm::StringRef StreamData, unsigned ClientLoadCapabilities, |
| 4215 | bool AllowCompatibleConfigurationMismatch, ASTReaderListener *Listener, |
| 4216 | bool ValidateDiagnosticOptions) { |
| 4217 | // Initialize a stream. |
| 4218 | BitstreamCursor Stream(StreamData); |
| 4219 | |
| 4220 | // Sniff for the signature. |
| 4221 | if (!startsWithASTFileMagic(Stream)) |
| 4222 | return Failure; |
| 4223 | |
| 4224 | // Scan for the UNHASHED_CONTROL_BLOCK_ID block. |
| 4225 | if (SkipCursorToBlock(Stream, UNHASHED_CONTROL_BLOCK_ID)) |
| 4226 | return Failure; |
| 4227 | |
| 4228 | // Read all of the records in the options block. |
| 4229 | RecordData Record; |
| 4230 | ASTReadResult Result = Success; |
| 4231 | while (1) { |
| 4232 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4233 | |
| 4234 | switch (Entry.Kind) { |
| 4235 | case llvm::BitstreamEntry::Error: |
| 4236 | case llvm::BitstreamEntry::SubBlock: |
| 4237 | return Failure; |
| 4238 | |
| 4239 | case llvm::BitstreamEntry::EndBlock: |
| 4240 | return Result; |
| 4241 | |
| 4242 | case llvm::BitstreamEntry::Record: |
| 4243 | // The interesting case. |
| 4244 | break; |
| 4245 | } |
| 4246 | |
| 4247 | // Read and process a record. |
| 4248 | Record.clear(); |
| 4249 | switch ( |
| 4250 | (UnhashedControlBlockRecordTypes)Stream.readRecord(Entry.ID, Record)) { |
| 4251 | case SIGNATURE: { |
| 4252 | if (F) |
| 4253 | std::copy(Record.begin(), Record.end(), F->Signature.data()); |
| 4254 | break; |
| 4255 | } |
| 4256 | case DIAGNOSTIC_OPTIONS: { |
| 4257 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
| 4258 | if (Listener && ValidateDiagnosticOptions && |
| 4259 | !AllowCompatibleConfigurationMismatch && |
| 4260 | ParseDiagnosticOptions(Record, Complain, *Listener)) |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4261 | Result = OutOfDate; // Don't return early. Read the signature. |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4262 | break; |
| 4263 | } |
| 4264 | case DIAG_PRAGMA_MAPPINGS: |
| 4265 | if (!F) |
| 4266 | break; |
| 4267 | if (F->PragmaDiagMappings.empty()) |
| 4268 | F->PragmaDiagMappings.swap(Record); |
| 4269 | else |
| 4270 | F->PragmaDiagMappings.insert(F->PragmaDiagMappings.end(), |
| 4271 | Record.begin(), Record.end()); |
| 4272 | break; |
| 4273 | } |
| 4274 | } |
| 4275 | } |
| 4276 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4277 | /// Parse a record and blob containing module file extension metadata. |
| 4278 | static bool parseModuleFileExtensionMetadata( |
| 4279 | const SmallVectorImpl<uint64_t> &Record, |
| 4280 | StringRef Blob, |
| 4281 | ModuleFileExtensionMetadata &Metadata) { |
| 4282 | if (Record.size() < 4) return true; |
| 4283 | |
| 4284 | Metadata.MajorVersion = Record[0]; |
| 4285 | Metadata.MinorVersion = Record[1]; |
| 4286 | |
| 4287 | unsigned BlockNameLen = Record[2]; |
| 4288 | unsigned UserInfoLen = Record[3]; |
| 4289 | |
| 4290 | if (BlockNameLen + UserInfoLen > Blob.size()) return true; |
| 4291 | |
| 4292 | Metadata.BlockName = std::string(Blob.data(), Blob.data() + BlockNameLen); |
| 4293 | Metadata.UserInfo = std::string(Blob.data() + BlockNameLen, |
| 4294 | Blob.data() + BlockNameLen + UserInfoLen); |
| 4295 | return false; |
| 4296 | } |
| 4297 | |
| 4298 | ASTReader::ASTReadResult ASTReader::ReadExtensionBlock(ModuleFile &F) { |
| 4299 | BitstreamCursor &Stream = F.Stream; |
| 4300 | |
| 4301 | RecordData Record; |
| 4302 | while (true) { |
| 4303 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4304 | switch (Entry.Kind) { |
| 4305 | case llvm::BitstreamEntry::SubBlock: |
| 4306 | if (Stream.SkipBlock()) |
| 4307 | return Failure; |
| 4308 | |
| 4309 | continue; |
| 4310 | |
| 4311 | case llvm::BitstreamEntry::EndBlock: |
| 4312 | return Success; |
| 4313 | |
| 4314 | case llvm::BitstreamEntry::Error: |
| 4315 | return HadErrors; |
| 4316 | |
| 4317 | case llvm::BitstreamEntry::Record: |
| 4318 | break; |
| 4319 | } |
| 4320 | |
| 4321 | Record.clear(); |
| 4322 | StringRef Blob; |
| 4323 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
| 4324 | switch (RecCode) { |
| 4325 | case EXTENSION_METADATA: { |
| 4326 | ModuleFileExtensionMetadata Metadata; |
| 4327 | if (parseModuleFileExtensionMetadata(Record, Blob, Metadata)) |
| 4328 | return Failure; |
| 4329 | |
| 4330 | // Find a module file extension with this block name. |
| 4331 | auto Known = ModuleFileExtensions.find(Metadata.BlockName); |
| 4332 | if (Known == ModuleFileExtensions.end()) break; |
| 4333 | |
| 4334 | // Form a reader. |
| 4335 | if (auto Reader = Known->second->createExtensionReader(Metadata, *this, |
| 4336 | F, Stream)) { |
| 4337 | F.ExtensionReaders.push_back(std::move(Reader)); |
| 4338 | } |
| 4339 | |
| 4340 | break; |
| 4341 | } |
| 4342 | } |
| 4343 | } |
| 4344 | |
| 4345 | return Success; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4346 | } |
| 4347 | |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4348 | void ASTReader::InitializeContext() { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4349 | assert(ContextObj && "no context to initialize"); |
| 4350 | ASTContext &Context = *ContextObj; |
| 4351 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4352 | // If there's a listener, notify them that we "read" the translation unit. |
| 4353 | if (DeserializationListener) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4354 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4355 | Context.getTranslationUnitDecl()); |
| 4356 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4357 | // FIXME: Find a better way to deal with collisions between these |
| 4358 | // built-in types. Right now, we just ignore the problem. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4359 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4360 | // Load the special types. |
| 4361 | if (SpecialTypes.size() >= NumSpecialTypeIDs) { |
| 4362 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 4363 | if (!Context.CFConstantStringTypeDecl) |
| 4364 | Context.setCFConstantStringType(GetType(String)); |
| 4365 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4366 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4367 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 4368 | QualType FileType = GetType(File); |
| 4369 | if (FileType.isNull()) { |
| 4370 | Error("FILE type is NULL"); |
| 4371 | return; |
| 4372 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4373 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4374 | if (!Context.FILEDecl) { |
| 4375 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 4376 | Context.setFILEDecl(Typedef->getDecl()); |
| 4377 | else { |
| 4378 | const TagType *Tag = FileType->getAs<TagType>(); |
| 4379 | if (!Tag) { |
| 4380 | Error("Invalid FILE type in AST file"); |
| 4381 | return; |
| 4382 | } |
| 4383 | Context.setFILEDecl(Tag->getDecl()); |
| 4384 | } |
| 4385 | } |
| 4386 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4387 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4388 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) { |
| 4389 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 4390 | if (Jmp_bufType.isNull()) { |
| 4391 | Error("jmp_buf type is NULL"); |
| 4392 | return; |
| 4393 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4394 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4395 | if (!Context.jmp_bufDecl) { |
| 4396 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 4397 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 4398 | else { |
| 4399 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 4400 | if (!Tag) { |
| 4401 | Error("Invalid jmp_buf type in AST file"); |
| 4402 | return; |
| 4403 | } |
| 4404 | Context.setjmp_bufDecl(Tag->getDecl()); |
| 4405 | } |
| 4406 | } |
| 4407 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4408 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4409 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) { |
| 4410 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 4411 | if (Sigjmp_bufType.isNull()) { |
| 4412 | Error("sigjmp_buf type is NULL"); |
| 4413 | return; |
| 4414 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4415 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4416 | if (!Context.sigjmp_bufDecl) { |
| 4417 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 4418 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 4419 | else { |
| 4420 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 4421 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 4422 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 4423 | } |
| 4424 | } |
| 4425 | } |
| 4426 | |
| 4427 | if (unsigned ObjCIdRedef |
| 4428 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 4429 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 4430 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 4431 | } |
| 4432 | |
| 4433 | if (unsigned ObjCClassRedef |
| 4434 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 4435 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 4436 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 4437 | } |
| 4438 | |
| 4439 | if (unsigned ObjCSelRedef |
| 4440 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 4441 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 4442 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 4443 | } |
| 4444 | |
| 4445 | if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) { |
| 4446 | QualType Ucontext_tType = GetType(Ucontext_t); |
| 4447 | if (Ucontext_tType.isNull()) { |
| 4448 | Error("ucontext_t type is NULL"); |
| 4449 | return; |
| 4450 | } |
| 4451 | |
| 4452 | if (!Context.ucontext_tDecl) { |
| 4453 | if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>()) |
| 4454 | Context.setucontext_tDecl(Typedef->getDecl()); |
| 4455 | else { |
| 4456 | const TagType *Tag = Ucontext_tType->getAs<TagType>(); |
| 4457 | assert(Tag && "Invalid ucontext_t type in AST file"); |
| 4458 | Context.setucontext_tDecl(Tag->getDecl()); |
| 4459 | } |
| 4460 | } |
| 4461 | } |
| 4462 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4463 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4464 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
| 4465 | |
| 4466 | // If there were any CUDA special declarations, deserialize them. |
| 4467 | if (!CUDASpecialDeclRefs.empty()) { |
| 4468 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 4469 | Context.setcudaConfigureCallDecl( |
| 4470 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 4471 | } |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4472 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4473 | // 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] | 4474 | // FIXME: This does not make macro-only imports visible again. |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4475 | for (auto &Import : ImportedModules) { |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4476 | if (Module *Imported = getSubmodule(Import.ID)) { |
Argyrios Kyrtzidis | 125df05 | 2013-02-01 16:36:12 +0000 | [diff] [blame] | 4477 | makeModuleVisible(Imported, Module::AllVisible, |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4478 | /*ImportLoc=*/Import.ImportLoc); |
Ben Langmuir | 6d25fdc | 2016-02-11 17:04:42 +0000 | [diff] [blame] | 4479 | if (Import.ImportLoc.isValid()) |
| 4480 | PP.makeModuleVisible(Imported, Import.ImportLoc); |
| 4481 | // FIXME: should we tell Sema to make the module visible too? |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4482 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4483 | } |
| 4484 | ImportedModules.clear(); |
| 4485 | } |
| 4486 | |
| 4487 | void ASTReader::finalizeForWriting() { |
Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 4488 | // Nothing to do for now. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4489 | } |
| 4490 | |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4491 | /// \brief Reads and return the signature record from \p PCH's control block, or |
| 4492 | /// else returns 0. |
| 4493 | static ASTFileSignature readASTFileSignature(StringRef PCH) { |
| 4494 | BitstreamCursor Stream(PCH); |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4495 | if (!startsWithASTFileMagic(Stream)) |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4496 | return ASTFileSignature(); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4497 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4498 | // Scan for the UNHASHED_CONTROL_BLOCK_ID block. |
| 4499 | if (SkipCursorToBlock(Stream, UNHASHED_CONTROL_BLOCK_ID)) |
| 4500 | return ASTFileSignature(); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4501 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4502 | // Scan for SIGNATURE inside the diagnostic options block. |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4503 | ASTReader::RecordData Record; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4504 | while (true) { |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4505 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
Simon Pilgrim | 0b33f11 | 2016-11-16 16:11:08 +0000 | [diff] [blame] | 4506 | if (Entry.Kind != llvm::BitstreamEntry::Record) |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4507 | return ASTFileSignature(); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4508 | |
| 4509 | Record.clear(); |
| 4510 | StringRef Blob; |
| 4511 | if (SIGNATURE == Stream.readRecord(Entry.ID, Record, &Blob)) |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4512 | return {{{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2], |
| 4513 | (uint32_t)Record[3], (uint32_t)Record[4]}}}; |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4514 | } |
| 4515 | } |
| 4516 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4517 | /// \brief Retrieve the name of the original source file name |
| 4518 | /// directly from the AST file, without actually loading the AST |
| 4519 | /// file. |
Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame] | 4520 | std::string ASTReader::getOriginalSourceFile( |
| 4521 | const std::string &ASTFileName, FileManager &FileMgr, |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 4522 | const PCHContainerReader &PCHContainerRdr, DiagnosticsEngine &Diags) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4523 | // Open the AST file. |
Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 4524 | auto Buffer = FileMgr.getBufferForFile(ASTFileName); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4525 | if (!Buffer) { |
Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 4526 | Diags.Report(diag::err_fe_unable_to_read_pch_file) |
| 4527 | << ASTFileName << Buffer.getError().message(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4528 | return std::string(); |
| 4529 | } |
| 4530 | |
| 4531 | // Initialize the stream |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4532 | BitstreamCursor Stream(PCHContainerRdr.ExtractPCH(**Buffer)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4533 | |
| 4534 | // Sniff for the signature. |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4535 | if (!startsWithASTFileMagic(Stream)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4536 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
| 4537 | return std::string(); |
| 4538 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4539 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4540 | // Scan for the CONTROL_BLOCK_ID block. |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4541 | if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4542 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
| 4543 | return std::string(); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4544 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4545 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4546 | // Scan for ORIGINAL_FILE inside the control block. |
| 4547 | RecordData Record; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4548 | while (true) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4549 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4550 | if (Entry.Kind == llvm::BitstreamEntry::EndBlock) |
| 4551 | return std::string(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4552 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4553 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| 4554 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
| 4555 | return std::string(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4556 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4557 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4558 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4559 | StringRef Blob; |
| 4560 | if (Stream.readRecord(Entry.ID, Record, &Blob) == ORIGINAL_FILE) |
| 4561 | return Blob.str(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4562 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4563 | } |
| 4564 | |
| 4565 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4566 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4567 | class SimplePCHValidator : public ASTReaderListener { |
| 4568 | const LangOptions &ExistingLangOpts; |
| 4569 | const TargetOptions &ExistingTargetOpts; |
| 4570 | const PreprocessorOptions &ExistingPPOpts; |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4571 | std::string ExistingModuleCachePath; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4572 | FileManager &FileMgr; |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4573 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4574 | public: |
| 4575 | SimplePCHValidator(const LangOptions &ExistingLangOpts, |
| 4576 | const TargetOptions &ExistingTargetOpts, |
| 4577 | const PreprocessorOptions &ExistingPPOpts, |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4578 | StringRef ExistingModuleCachePath, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4579 | FileManager &FileMgr) |
| 4580 | : ExistingLangOpts(ExistingLangOpts), |
| 4581 | ExistingTargetOpts(ExistingTargetOpts), |
| 4582 | ExistingPPOpts(ExistingPPOpts), |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4583 | ExistingModuleCachePath(ExistingModuleCachePath), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4584 | FileMgr(FileMgr) |
| 4585 | { |
| 4586 | } |
| 4587 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 4588 | bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, |
| 4589 | bool AllowCompatibleDifferences) override { |
| 4590 | return checkLanguageOptions(ExistingLangOpts, LangOpts, nullptr, |
| 4591 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4592 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4593 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 4594 | bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, |
| 4595 | bool AllowCompatibleDifferences) override { |
| 4596 | return checkTargetOptions(ExistingTargetOpts, TargetOpts, nullptr, |
| 4597 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4598 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4599 | |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4600 | bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 4601 | StringRef SpecificModuleCachePath, |
| 4602 | bool Complain) override { |
| 4603 | return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 4604 | ExistingModuleCachePath, |
| 4605 | nullptr, ExistingLangOpts); |
| 4606 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4607 | |
Craig Topper | 3e89dfe | 2014-03-13 02:13:41 +0000 | [diff] [blame] | 4608 | bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 4609 | bool Complain, |
| 4610 | std::string &SuggestedPredefines) override { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4611 | return checkPreprocessorOptions(ExistingPPOpts, PPOpts, nullptr, FileMgr, |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 4612 | SuggestedPredefines, ExistingLangOpts); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4613 | } |
| 4614 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4615 | |
| 4616 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4617 | |
Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame] | 4618 | bool ASTReader::readASTFileControlBlock( |
| 4619 | StringRef Filename, FileManager &FileMgr, |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 4620 | const PCHContainerReader &PCHContainerRdr, |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4621 | bool FindModuleFileExtensions, |
Manman Ren | 47a4445 | 2016-07-26 17:12:17 +0000 | [diff] [blame] | 4622 | ASTReaderListener &Listener, bool ValidateDiagnosticOptions) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4623 | // Open the AST file. |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 4624 | // FIXME: This allows use of the VFS; we do not allow use of the |
| 4625 | // VFS when actually loading a module. |
Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 4626 | auto Buffer = FileMgr.getBufferForFile(Filename); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4627 | if (!Buffer) { |
| 4628 | return true; |
| 4629 | } |
| 4630 | |
| 4631 | // Initialize the stream |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4632 | StringRef Bytes = PCHContainerRdr.ExtractPCH(**Buffer); |
| 4633 | BitstreamCursor Stream(Bytes); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4634 | |
| 4635 | // Sniff for the signature. |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4636 | if (!startsWithASTFileMagic(Stream)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4637 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4638 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4639 | // Scan for the CONTROL_BLOCK_ID block. |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4640 | if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4641 | return true; |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4642 | |
| 4643 | bool NeedsInputFiles = Listener.needsInputFileVisitation(); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 4644 | bool NeedsSystemInputFiles = Listener.needsSystemInputFileVisitation(); |
Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4645 | bool NeedsImports = Listener.needsImportVisitation(); |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4646 | BitstreamCursor InputFilesCursor; |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4647 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4648 | RecordData Record; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4649 | std::string ModuleDir; |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4650 | bool DoneWithControlBlock = false; |
| 4651 | while (!DoneWithControlBlock) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4652 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4653 | |
| 4654 | switch (Entry.Kind) { |
| 4655 | case llvm::BitstreamEntry::SubBlock: { |
| 4656 | switch (Entry.ID) { |
| 4657 | case OPTIONS_BLOCK_ID: { |
| 4658 | std::string IgnoredSuggestedPredefines; |
| 4659 | if (ReadOptionsBlock(Stream, ARR_ConfigurationMismatch | ARR_OutOfDate, |
| 4660 | /*AllowCompatibleConfigurationMismatch*/ false, |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4661 | Listener, IgnoredSuggestedPredefines) != Success) |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4662 | return true; |
| 4663 | break; |
| 4664 | } |
| 4665 | |
| 4666 | case INPUT_FILES_BLOCK_ID: |
| 4667 | InputFilesCursor = Stream; |
| 4668 | if (Stream.SkipBlock() || |
| 4669 | (NeedsInputFiles && |
| 4670 | ReadBlockAbbrevs(InputFilesCursor, INPUT_FILES_BLOCK_ID))) |
| 4671 | return true; |
| 4672 | break; |
| 4673 | |
| 4674 | default: |
| 4675 | if (Stream.SkipBlock()) |
| 4676 | return true; |
| 4677 | break; |
| 4678 | } |
| 4679 | |
| 4680 | continue; |
| 4681 | } |
| 4682 | |
| 4683 | case llvm::BitstreamEntry::EndBlock: |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4684 | DoneWithControlBlock = true; |
| 4685 | break; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4686 | |
| 4687 | case llvm::BitstreamEntry::Error: |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4688 | return true; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4689 | |
| 4690 | case llvm::BitstreamEntry::Record: |
| 4691 | break; |
| 4692 | } |
| 4693 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4694 | if (DoneWithControlBlock) break; |
| 4695 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4696 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4697 | StringRef Blob; |
| 4698 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4699 | switch ((ControlRecordTypes)RecCode) { |
| 4700 | case METADATA: { |
| 4701 | if (Record[0] != VERSION_MAJOR) |
| 4702 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4703 | |
Douglas Gregor | bf7fc9c | 2013-03-27 16:47:18 +0000 | [diff] [blame] | 4704 | if (Listener.ReadFullVersionInformation(Blob)) |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4705 | return true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4706 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4707 | break; |
| 4708 | } |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 4709 | case MODULE_NAME: |
| 4710 | Listener.ReadModuleName(Blob); |
| 4711 | break; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4712 | case MODULE_DIRECTORY: |
| 4713 | ModuleDir = Blob; |
| 4714 | break; |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 4715 | case MODULE_MAP_FILE: { |
| 4716 | unsigned Idx = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4717 | auto Path = ReadString(Record, Idx); |
| 4718 | ResolveImportedPath(Path, ModuleDir); |
| 4719 | Listener.ReadModuleMapFile(Path); |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 4720 | break; |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 4721 | } |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4722 | case INPUT_FILE_OFFSETS: { |
| 4723 | if (!NeedsInputFiles) |
| 4724 | break; |
| 4725 | |
| 4726 | unsigned NumInputFiles = Record[0]; |
| 4727 | unsigned NumUserFiles = Record[1]; |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 4728 | const uint64_t *InputFileOffs = (const uint64_t *)Blob.data(); |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4729 | for (unsigned I = 0; I != NumInputFiles; ++I) { |
| 4730 | // Go find this input file. |
| 4731 | bool isSystemFile = I >= NumUserFiles; |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 4732 | |
| 4733 | if (isSystemFile && !NeedsSystemInputFiles) |
| 4734 | break; // the rest are system input files |
| 4735 | |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4736 | BitstreamCursor &Cursor = InputFilesCursor; |
| 4737 | SavedStreamPosition SavedPosition(Cursor); |
| 4738 | Cursor.JumpToBit(InputFileOffs[I]); |
| 4739 | |
| 4740 | unsigned Code = Cursor.ReadCode(); |
| 4741 | RecordData Record; |
| 4742 | StringRef Blob; |
| 4743 | bool shouldContinue = false; |
| 4744 | switch ((InputFileRecordTypes)Cursor.readRecord(Code, Record, &Blob)) { |
| 4745 | case INPUT_FILE: |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 4746 | bool Overridden = static_cast<bool>(Record[3]); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4747 | std::string Filename = Blob; |
| 4748 | ResolveImportedPath(Filename, ModuleDir); |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 4749 | shouldContinue = Listener.visitInputFile( |
| 4750 | Filename, isSystemFile, Overridden, /*IsExplicitModule*/false); |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4751 | break; |
| 4752 | } |
| 4753 | if (!shouldContinue) |
| 4754 | break; |
| 4755 | } |
| 4756 | break; |
| 4757 | } |
| 4758 | |
Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4759 | case IMPORTS: { |
| 4760 | if (!NeedsImports) |
| 4761 | break; |
| 4762 | |
| 4763 | unsigned Idx = 0, N = Record.size(); |
| 4764 | while (Idx < N) { |
| 4765 | // Read information about the AST file. |
Richard Smith | 79c98cc | 2014-10-27 23:25:15 +0000 | [diff] [blame] | 4766 | Idx += 5; // ImportLoc, Size, ModTime, Signature |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4767 | std::string Filename = ReadString(Record, Idx); |
| 4768 | ResolveImportedPath(Filename, ModuleDir); |
| 4769 | Listener.visitImport(Filename); |
Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4770 | } |
| 4771 | break; |
| 4772 | } |
| 4773 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4774 | default: |
| 4775 | // No other validation to perform. |
| 4776 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4777 | } |
| 4778 | } |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4779 | |
| 4780 | // Look for module file extension blocks, if requested. |
| 4781 | if (FindModuleFileExtensions) { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4782 | BitstreamCursor SavedStream = Stream; |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4783 | while (!SkipCursorToBlock(Stream, EXTENSION_BLOCK_ID)) { |
| 4784 | bool DoneWithExtensionBlock = false; |
| 4785 | while (!DoneWithExtensionBlock) { |
| 4786 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4787 | |
| 4788 | switch (Entry.Kind) { |
| 4789 | case llvm::BitstreamEntry::SubBlock: |
| 4790 | if (Stream.SkipBlock()) |
| 4791 | return true; |
| 4792 | |
| 4793 | continue; |
| 4794 | |
| 4795 | case llvm::BitstreamEntry::EndBlock: |
| 4796 | DoneWithExtensionBlock = true; |
| 4797 | continue; |
| 4798 | |
| 4799 | case llvm::BitstreamEntry::Error: |
| 4800 | return true; |
| 4801 | |
| 4802 | case llvm::BitstreamEntry::Record: |
| 4803 | break; |
| 4804 | } |
| 4805 | |
| 4806 | Record.clear(); |
| 4807 | StringRef Blob; |
| 4808 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
| 4809 | switch (RecCode) { |
| 4810 | case EXTENSION_METADATA: { |
| 4811 | ModuleFileExtensionMetadata Metadata; |
| 4812 | if (parseModuleFileExtensionMetadata(Record, Blob, Metadata)) |
| 4813 | return true; |
| 4814 | |
| 4815 | Listener.readModuleFileExtension(Metadata); |
| 4816 | break; |
| 4817 | } |
| 4818 | } |
| 4819 | } |
| 4820 | } |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4821 | Stream = SavedStream; |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4822 | } |
| 4823 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4824 | // Scan for the UNHASHED_CONTROL_BLOCK_ID block. |
| 4825 | if (readUnhashedControlBlockImpl( |
| 4826 | nullptr, Bytes, ARR_ConfigurationMismatch | ARR_OutOfDate, |
| 4827 | /*AllowCompatibleConfigurationMismatch*/ false, &Listener, |
| 4828 | ValidateDiagnosticOptions) != Success) |
| 4829 | return true; |
| 4830 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4831 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4832 | } |
| 4833 | |
Benjamin Kramer | f6021ec | 2017-03-21 21:35:04 +0000 | [diff] [blame] | 4834 | bool ASTReader::isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, |
| 4835 | const PCHContainerReader &PCHContainerRdr, |
| 4836 | const LangOptions &LangOpts, |
| 4837 | const TargetOptions &TargetOpts, |
| 4838 | const PreprocessorOptions &PPOpts, |
| 4839 | StringRef ExistingModuleCachePath) { |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4840 | SimplePCHValidator validator(LangOpts, TargetOpts, PPOpts, |
| 4841 | ExistingModuleCachePath, FileMgr); |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 4842 | return !readASTFileControlBlock(Filename, FileMgr, PCHContainerRdr, |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4843 | /*FindModuleFileExtensions=*/false, |
Manman Ren | 47a4445 | 2016-07-26 17:12:17 +0000 | [diff] [blame] | 4844 | validator, |
| 4845 | /*ValidateDiagnosticOptions=*/true); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4846 | } |
| 4847 | |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4848 | ASTReader::ASTReadResult |
| 4849 | ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4850 | // Enter the submodule block. |
| 4851 | if (F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) { |
| 4852 | Error("malformed submodule block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4853 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4854 | } |
| 4855 | |
| 4856 | ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap(); |
| 4857 | bool First = true; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4858 | Module *CurrentModule = nullptr; |
Richard Smith | 145e15a | 2017-04-24 23:12:30 +0000 | [diff] [blame] | 4859 | Module::ModuleKind ModuleKind = Module::ModuleMapModule; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4860 | RecordData Record; |
| 4861 | while (true) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4862 | llvm::BitstreamEntry Entry = F.Stream.advanceSkippingSubblocks(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4863 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4864 | switch (Entry.Kind) { |
| 4865 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 4866 | case llvm::BitstreamEntry::Error: |
| 4867 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4868 | return Failure; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4869 | case llvm::BitstreamEntry::EndBlock: |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4870 | return Success; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4871 | case llvm::BitstreamEntry::Record: |
| 4872 | // The interesting case. |
| 4873 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4874 | } |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4875 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4876 | // Read a record. |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4877 | StringRef Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4878 | Record.clear(); |
Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4879 | auto Kind = F.Stream.readRecord(Entry.ID, Record, &Blob); |
| 4880 | |
| 4881 | if ((Kind == SUBMODULE_METADATA) != First) { |
| 4882 | Error("submodule metadata record should be at beginning of block"); |
| 4883 | return Failure; |
| 4884 | } |
| 4885 | First = false; |
| 4886 | |
| 4887 | // Submodule information is only valid if we have a current module. |
| 4888 | // FIXME: Should we error on these cases? |
| 4889 | if (!CurrentModule && Kind != SUBMODULE_METADATA && |
| 4890 | Kind != SUBMODULE_DEFINITION) |
| 4891 | continue; |
| 4892 | |
| 4893 | switch (Kind) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4894 | default: // Default behavior: ignore. |
| 4895 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4896 | |
Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4897 | case SUBMODULE_DEFINITION: { |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4898 | if (Record.size() < 8) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4899 | Error("malformed module definition"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4900 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4901 | } |
Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4902 | |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4903 | StringRef Name = Blob; |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 4904 | unsigned Idx = 0; |
| 4905 | SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[Idx++]); |
| 4906 | SubmoduleID Parent = getGlobalSubmoduleID(F, Record[Idx++]); |
| 4907 | bool IsFramework = Record[Idx++]; |
| 4908 | bool IsExplicit = Record[Idx++]; |
| 4909 | bool IsSystem = Record[Idx++]; |
| 4910 | bool IsExternC = Record[Idx++]; |
| 4911 | bool InferSubmodules = Record[Idx++]; |
| 4912 | bool InferExplicitSubmodules = Record[Idx++]; |
| 4913 | bool InferExportWildcard = Record[Idx++]; |
| 4914 | bool ConfigMacrosExhaustive = Record[Idx++]; |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4915 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4916 | Module *ParentModule = nullptr; |
Ben Langmuir | 9d6448b | 2014-08-09 00:57:23 +0000 | [diff] [blame] | 4917 | if (Parent) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4918 | ParentModule = getSubmodule(Parent); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4919 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4920 | // Retrieve this (sub)module from the module map, creating it if |
| 4921 | // necessary. |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 4922 | CurrentModule = |
| 4923 | ModMap.findOrCreateModule(Name, ParentModule, IsFramework, IsExplicit) |
| 4924 | .first; |
Ben Langmuir | 9d6448b | 2014-08-09 00:57:23 +0000 | [diff] [blame] | 4925 | |
| 4926 | // FIXME: set the definition loc for CurrentModule, or call |
| 4927 | // ModMap.setInferredModuleAllowedBy() |
| 4928 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4929 | SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS; |
| 4930 | if (GlobalIndex >= SubmodulesLoaded.size() || |
| 4931 | SubmodulesLoaded[GlobalIndex]) { |
| 4932 | Error("too many submodules"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4933 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4934 | } |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4935 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4936 | if (!ParentModule) { |
| 4937 | if (const FileEntry *CurFile = CurrentModule->getASTFile()) { |
| 4938 | if (CurFile != F.File) { |
| 4939 | if (!Diags.isDiagnosticInFlight()) { |
| 4940 | Diag(diag::err_module_file_conflict) |
| 4941 | << CurrentModule->getTopLevelModuleName() |
| 4942 | << CurFile->getName() |
| 4943 | << F.File->getName(); |
| 4944 | } |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4945 | return Failure; |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4946 | } |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4947 | } |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4948 | |
| 4949 | CurrentModule->setASTFile(F.File); |
Richard Smith | ab75597 | 2017-06-05 18:10:11 +0000 | [diff] [blame] | 4950 | CurrentModule->PresumedModuleMapFile = F.ModuleMapPath; |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 4951 | } |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4952 | |
Richard Smith | 145e15a | 2017-04-24 23:12:30 +0000 | [diff] [blame] | 4953 | CurrentModule->Kind = ModuleKind; |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 4954 | CurrentModule->Signature = F.Signature; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4955 | CurrentModule->IsFromModuleFile = true; |
| 4956 | CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem; |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 4957 | CurrentModule->IsExternC = IsExternC; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4958 | CurrentModule->InferSubmodules = InferSubmodules; |
| 4959 | CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules; |
| 4960 | CurrentModule->InferExportWildcard = InferExportWildcard; |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4961 | CurrentModule->ConfigMacrosExhaustive = ConfigMacrosExhaustive; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4962 | if (DeserializationListener) |
| 4963 | DeserializationListener->ModuleRead(GlobalID, CurrentModule); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4964 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4965 | SubmodulesLoaded[GlobalIndex] = CurrentModule; |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 4966 | |
Richard Smith | 8a3e39a | 2016-03-28 21:31:09 +0000 | [diff] [blame] | 4967 | // 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] | 4968 | CurrentModule->LinkLibraries.clear(); |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4969 | CurrentModule->ConfigMacros.clear(); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4970 | CurrentModule->UnresolvedConflicts.clear(); |
| 4971 | CurrentModule->Conflicts.clear(); |
Richard Smith | 8a3e39a | 2016-03-28 21:31:09 +0000 | [diff] [blame] | 4972 | |
| 4973 | // The module is available unless it's missing a requirement; relevant |
| 4974 | // requirements will be (re-)added by SUBMODULE_REQUIRES records. |
| 4975 | // Missing headers that were present when the module was built do not |
| 4976 | // make it unavailable -- if we got this far, this must be an explicitly |
| 4977 | // imported module file. |
| 4978 | CurrentModule->Requirements.clear(); |
| 4979 | CurrentModule->MissingHeaders.clear(); |
| 4980 | CurrentModule->IsMissingRequirement = |
| 4981 | ParentModule && ParentModule->IsMissingRequirement; |
| 4982 | CurrentModule->IsAvailable = !CurrentModule->IsMissingRequirement; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4983 | break; |
| 4984 | } |
Richard Smith | 8a3e39a | 2016-03-28 21:31:09 +0000 | [diff] [blame] | 4985 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4986 | case SUBMODULE_UMBRELLA_HEADER: { |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 4987 | std::string Filename = Blob; |
| 4988 | ResolveImportedPath(F, Filename); |
| 4989 | if (auto *Umbrella = PP.getFileManager().getFile(Filename)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4990 | if (!CurrentModule->getUmbrellaHeader()) |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 4991 | ModMap.setUmbrellaHeader(CurrentModule, Umbrella, Blob); |
| 4992 | else if (CurrentModule->getUmbrellaHeader().Entry != Umbrella) { |
Bruno Cardoso Lopes | 573b13f | 2017-03-22 00:11:21 +0000 | [diff] [blame] | 4993 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 4994 | Error("mismatched umbrella headers in submodule"); |
| 4995 | return OutOfDate; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4996 | } |
| 4997 | } |
| 4998 | break; |
| 4999 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5000 | |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 5001 | case SUBMODULE_HEADER: |
| 5002 | case SUBMODULE_EXCLUDED_HEADER: |
| 5003 | case SUBMODULE_PRIVATE_HEADER: |
| 5004 | // We lazily associate headers with their modules via the HeaderInfo table. |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 5005 | // FIXME: Re-evaluate this section; maybe only store InputFile IDs instead |
| 5006 | // of complete filenames or remove it entirely. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 5007 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5008 | |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 5009 | case SUBMODULE_TEXTUAL_HEADER: |
| 5010 | case SUBMODULE_PRIVATE_TEXTUAL_HEADER: |
| 5011 | // FIXME: Textual headers are not marked in the HeaderInfo table. Load |
| 5012 | // them here. |
| 5013 | break; |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 5014 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5015 | case SUBMODULE_TOPHEADER: { |
Argyrios Kyrtzidis | 3c5305c | 2013-03-13 21:13:43 +0000 | [diff] [blame] | 5016 | CurrentModule->addTopHeaderFilename(Blob); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5017 | break; |
| 5018 | } |
| 5019 | |
| 5020 | case SUBMODULE_UMBRELLA_DIR: { |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 5021 | std::string Dirname = Blob; |
| 5022 | ResolveImportedPath(F, Dirname); |
| 5023 | if (auto *Umbrella = PP.getFileManager().getDirectory(Dirname)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5024 | if (!CurrentModule->getUmbrellaDir()) |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 5025 | ModMap.setUmbrellaDir(CurrentModule, Umbrella, Blob); |
| 5026 | else if (CurrentModule->getUmbrellaDir().Entry != Umbrella) { |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 5027 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 5028 | Error("mismatched umbrella directories in submodule"); |
| 5029 | return OutOfDate; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5030 | } |
| 5031 | } |
| 5032 | break; |
| 5033 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5034 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5035 | case SUBMODULE_METADATA: { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5036 | F.BaseSubmoduleID = getTotalNumSubmodules(); |
| 5037 | F.LocalNumSubmodules = Record[0]; |
| 5038 | unsigned LocalBaseSubmoduleID = Record[1]; |
| 5039 | if (F.LocalNumSubmodules > 0) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5040 | // Introduce the global -> local mapping for submodules within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5041 | // module. |
| 5042 | GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5043 | |
| 5044 | // Introduce the local -> global mapping for submodules within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5045 | // module. |
| 5046 | F.SubmoduleRemap.insertOrReplace( |
| 5047 | std::make_pair(LocalBaseSubmoduleID, |
| 5048 | F.BaseSubmoduleID - LocalBaseSubmoduleID)); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 5049 | |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 5050 | SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules); |
| 5051 | } |
Richard Smith | 145e15a | 2017-04-24 23:12:30 +0000 | [diff] [blame] | 5052 | ModuleKind = (Module::ModuleKind)Record[2]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5053 | break; |
| 5054 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5055 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5056 | case SUBMODULE_IMPORTS: { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5057 | for (unsigned Idx = 0; Idx != Record.size(); ++Idx) { |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5058 | UnresolvedModuleRef Unresolved; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5059 | Unresolved.File = &F; |
| 5060 | Unresolved.Mod = CurrentModule; |
| 5061 | Unresolved.ID = Record[Idx]; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5062 | Unresolved.Kind = UnresolvedModuleRef::Import; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5063 | Unresolved.IsWildcard = false; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5064 | UnresolvedModuleRefs.push_back(Unresolved); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5065 | } |
| 5066 | break; |
| 5067 | } |
| 5068 | |
| 5069 | case SUBMODULE_EXPORTS: { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5070 | for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) { |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5071 | UnresolvedModuleRef Unresolved; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5072 | Unresolved.File = &F; |
| 5073 | Unresolved.Mod = CurrentModule; |
| 5074 | Unresolved.ID = Record[Idx]; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5075 | Unresolved.Kind = UnresolvedModuleRef::Export; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5076 | Unresolved.IsWildcard = Record[Idx + 1]; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5077 | UnresolvedModuleRefs.push_back(Unresolved); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5078 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5079 | |
| 5080 | // 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] | 5081 | // the parsed, unresolved exports around. |
| 5082 | CurrentModule->UnresolvedExports.clear(); |
| 5083 | break; |
| 5084 | } |
| 5085 | case SUBMODULE_REQUIRES: { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5086 | CurrentModule->addRequirement(Blob, Record[0], PP.getLangOpts(), |
| 5087 | PP.getTargetInfo()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5088 | break; |
| 5089 | } |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5090 | |
| 5091 | case SUBMODULE_LINK_LIBRARY: |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5092 | CurrentModule->LinkLibraries.push_back( |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5093 | Module::LinkLibrary(Blob, Record[0])); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5094 | break; |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 5095 | |
| 5096 | case SUBMODULE_CONFIG_MACRO: |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 5097 | CurrentModule->ConfigMacros.push_back(Blob.str()); |
| 5098 | break; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5099 | |
| 5100 | case SUBMODULE_CONFLICT: { |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5101 | UnresolvedModuleRef Unresolved; |
| 5102 | Unresolved.File = &F; |
| 5103 | Unresolved.Mod = CurrentModule; |
| 5104 | Unresolved.ID = Record[0]; |
| 5105 | Unresolved.Kind = UnresolvedModuleRef::Conflict; |
| 5106 | Unresolved.IsWildcard = false; |
| 5107 | Unresolved.String = Blob; |
| 5108 | UnresolvedModuleRefs.push_back(Unresolved); |
| 5109 | break; |
| 5110 | } |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 5111 | |
| 5112 | case SUBMODULE_INITIALIZERS: |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5113 | if (!ContextObj) |
| 5114 | break; |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 5115 | SmallVector<uint32_t, 16> Inits; |
| 5116 | for (auto &ID : Record) |
| 5117 | Inits.push_back(getGlobalDeclID(F, ID)); |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5118 | ContextObj->addLazyModuleInitializers(CurrentModule, Inits); |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 5119 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5120 | } |
| 5121 | } |
| 5122 | } |
| 5123 | |
| 5124 | /// \brief Parse the record that corresponds to a LangOptions data |
| 5125 | /// structure. |
| 5126 | /// |
| 5127 | /// This routine parses the language options from the AST file and then gives |
| 5128 | /// them to the AST listener if one is set. |
| 5129 | /// |
| 5130 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
| 5131 | bool ASTReader::ParseLanguageOptions(const RecordData &Record, |
| 5132 | bool Complain, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 5133 | ASTReaderListener &Listener, |
| 5134 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5135 | LangOptions LangOpts; |
| 5136 | unsigned Idx = 0; |
| 5137 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 5138 | LangOpts.Name = Record[Idx++]; |
| 5139 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 5140 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 5141 | #include "clang/Basic/LangOptions.def" |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 5142 | #define SANITIZER(NAME, ID) \ |
| 5143 | LangOpts.Sanitize.set(SanitizerKind::ID, Record[Idx++]); |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 5144 | #include "clang/Basic/Sanitizers.def" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5145 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 5146 | for (unsigned N = Record[Idx++]; N; --N) |
| 5147 | LangOpts.ModuleFeatures.push_back(ReadString(Record, Idx)); |
| 5148 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5149 | ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++]; |
| 5150 | VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx); |
| 5151 | LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 5152 | |
Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 5153 | LangOpts.CurrentModule = ReadString(Record, Idx); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 5154 | |
| 5155 | // Comment options. |
| 5156 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5157 | LangOpts.CommentOpts.BlockCommandNames.push_back( |
| 5158 | ReadString(Record, Idx)); |
| 5159 | } |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 5160 | LangOpts.CommentOpts.ParseAllComments = Record[Idx++]; |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 5161 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 5162 | // OpenMP offloading options. |
| 5163 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5164 | LangOpts.OMPTargetTriples.push_back(llvm::Triple(ReadString(Record, Idx))); |
| 5165 | } |
| 5166 | |
| 5167 | LangOpts.OMPHostIRFile = ReadString(Record, Idx); |
| 5168 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 5169 | return Listener.ReadLanguageOptions(LangOpts, Complain, |
| 5170 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5171 | } |
| 5172 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 5173 | bool ASTReader::ParseTargetOptions(const RecordData &Record, bool Complain, |
| 5174 | ASTReaderListener &Listener, |
| 5175 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5176 | unsigned Idx = 0; |
| 5177 | TargetOptions TargetOpts; |
| 5178 | TargetOpts.Triple = ReadString(Record, Idx); |
| 5179 | TargetOpts.CPU = ReadString(Record, Idx); |
| 5180 | TargetOpts.ABI = ReadString(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5181 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5182 | TargetOpts.FeaturesAsWritten.push_back(ReadString(Record, Idx)); |
| 5183 | } |
| 5184 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5185 | TargetOpts.Features.push_back(ReadString(Record, Idx)); |
| 5186 | } |
| 5187 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 5188 | return Listener.ReadTargetOptions(TargetOpts, Complain, |
| 5189 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5190 | } |
| 5191 | |
| 5192 | bool ASTReader::ParseDiagnosticOptions(const RecordData &Record, bool Complain, |
| 5193 | ASTReaderListener &Listener) { |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5194 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5195 | unsigned Idx = 0; |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5196 | #define DIAGOPT(Name, Bits, Default) DiagOpts->Name = Record[Idx++]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5197 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5198 | DiagOpts->set##Name(static_cast<Type>(Record[Idx++])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5199 | #include "clang/Basic/DiagnosticOptions.def" |
| 5200 | |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 5201 | for (unsigned N = Record[Idx++]; N; --N) |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5202 | DiagOpts->Warnings.push_back(ReadString(Record, Idx)); |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 5203 | for (unsigned N = Record[Idx++]; N; --N) |
| 5204 | DiagOpts->Remarks.push_back(ReadString(Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5205 | |
| 5206 | return Listener.ReadDiagnosticOptions(DiagOpts, Complain); |
| 5207 | } |
| 5208 | |
| 5209 | bool ASTReader::ParseFileSystemOptions(const RecordData &Record, bool Complain, |
| 5210 | ASTReaderListener &Listener) { |
| 5211 | FileSystemOptions FSOpts; |
| 5212 | unsigned Idx = 0; |
| 5213 | FSOpts.WorkingDir = ReadString(Record, Idx); |
| 5214 | return Listener.ReadFileSystemOptions(FSOpts, Complain); |
| 5215 | } |
| 5216 | |
| 5217 | bool ASTReader::ParseHeaderSearchOptions(const RecordData &Record, |
| 5218 | bool Complain, |
| 5219 | ASTReaderListener &Listener) { |
| 5220 | HeaderSearchOptions HSOpts; |
| 5221 | unsigned Idx = 0; |
| 5222 | HSOpts.Sysroot = ReadString(Record, Idx); |
| 5223 | |
| 5224 | // Include entries. |
| 5225 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5226 | std::string Path = ReadString(Record, Idx); |
| 5227 | frontend::IncludeDirGroup Group |
| 5228 | = static_cast<frontend::IncludeDirGroup>(Record[Idx++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5229 | bool IsFramework = Record[Idx++]; |
| 5230 | bool IgnoreSysRoot = Record[Idx++]; |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 5231 | HSOpts.UserEntries.emplace_back(std::move(Path), Group, IsFramework, |
| 5232 | IgnoreSysRoot); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5233 | } |
| 5234 | |
| 5235 | // System header prefixes. |
| 5236 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5237 | std::string Prefix = ReadString(Record, Idx); |
| 5238 | bool IsSystemHeader = Record[Idx++]; |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 5239 | HSOpts.SystemHeaderPrefixes.emplace_back(std::move(Prefix), IsSystemHeader); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5240 | } |
| 5241 | |
| 5242 | HSOpts.ResourceDir = ReadString(Record, Idx); |
| 5243 | HSOpts.ModuleCachePath = ReadString(Record, Idx); |
Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 5244 | HSOpts.ModuleUserBuildPath = ReadString(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5245 | HSOpts.DisableModuleHash = Record[Idx++]; |
Richard Smith | 1893475 | 2017-06-06 00:32:01 +0000 | [diff] [blame] | 5246 | HSOpts.ImplicitModuleMaps = Record[Idx++]; |
| 5247 | HSOpts.ModuleMapFileHomeIsCwd = Record[Idx++]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5248 | HSOpts.UseBuiltinIncludes = Record[Idx++]; |
| 5249 | HSOpts.UseStandardSystemIncludes = Record[Idx++]; |
| 5250 | HSOpts.UseStandardCXXIncludes = Record[Idx++]; |
| 5251 | HSOpts.UseLibcxx = Record[Idx++]; |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 5252 | std::string SpecificModuleCachePath = ReadString(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5253 | |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 5254 | return Listener.ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 5255 | Complain); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5256 | } |
| 5257 | |
| 5258 | bool ASTReader::ParsePreprocessorOptions(const RecordData &Record, |
| 5259 | bool Complain, |
| 5260 | ASTReaderListener &Listener, |
| 5261 | std::string &SuggestedPredefines) { |
| 5262 | PreprocessorOptions PPOpts; |
| 5263 | unsigned Idx = 0; |
| 5264 | |
| 5265 | // Macro definitions/undefs |
| 5266 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5267 | std::string Macro = ReadString(Record, Idx); |
| 5268 | bool IsUndef = Record[Idx++]; |
| 5269 | PPOpts.Macros.push_back(std::make_pair(Macro, IsUndef)); |
| 5270 | } |
| 5271 | |
| 5272 | // Includes |
| 5273 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5274 | PPOpts.Includes.push_back(ReadString(Record, Idx)); |
| 5275 | } |
| 5276 | |
| 5277 | // Macro Includes |
| 5278 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5279 | PPOpts.MacroIncludes.push_back(ReadString(Record, Idx)); |
| 5280 | } |
| 5281 | |
| 5282 | PPOpts.UsePredefines = Record[Idx++]; |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 5283 | PPOpts.DetailedRecord = Record[Idx++]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5284 | PPOpts.ImplicitPCHInclude = ReadString(Record, Idx); |
| 5285 | PPOpts.ImplicitPTHInclude = ReadString(Record, Idx); |
| 5286 | PPOpts.ObjCXXARCStandardLibrary = |
| 5287 | static_cast<ObjCXXARCStandardLibraryKind>(Record[Idx++]); |
| 5288 | SuggestedPredefines.clear(); |
| 5289 | return Listener.ReadPreprocessorOptions(PPOpts, Complain, |
| 5290 | SuggestedPredefines); |
| 5291 | } |
| 5292 | |
| 5293 | std::pair<ModuleFile *, unsigned> |
| 5294 | ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { |
| 5295 | GlobalPreprocessedEntityMapType::iterator |
| 5296 | I = GlobalPreprocessedEntityMap.find(GlobalIndex); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5297 | assert(I != GlobalPreprocessedEntityMap.end() && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5298 | "Corrupted global preprocessed entity map"); |
| 5299 | ModuleFile *M = I->second; |
| 5300 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; |
| 5301 | return std::make_pair(M, LocalIndex); |
| 5302 | } |
| 5303 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5304 | llvm::iterator_range<PreprocessingRecord::iterator> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5305 | ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const { |
| 5306 | if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord()) |
| 5307 | return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID, |
| 5308 | Mod.NumPreprocessedEntities); |
| 5309 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5310 | return llvm::make_range(PreprocessingRecord::iterator(), |
| 5311 | PreprocessingRecord::iterator()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5312 | } |
| 5313 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5314 | llvm::iterator_range<ASTReader::ModuleDeclIterator> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5315 | ASTReader::getModuleFileLevelDecls(ModuleFile &Mod) { |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5316 | return llvm::make_range( |
| 5317 | ModuleDeclIterator(this, &Mod, Mod.FileSortedDecls), |
| 5318 | ModuleDeclIterator(this, &Mod, |
| 5319 | Mod.FileSortedDecls + Mod.NumFileSortedDecls)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5320 | } |
| 5321 | |
| 5322 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { |
| 5323 | PreprocessedEntityID PPID = Index+1; |
| 5324 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 5325 | ModuleFile &M = *PPInfo.first; |
| 5326 | unsigned LocalIndex = PPInfo.second; |
| 5327 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 5328 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5329 | if (!PP.getPreprocessingRecord()) { |
| 5330 | Error("no preprocessing record"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5331 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5332 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5333 | |
| 5334 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5335 | M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset); |
| 5336 | |
| 5337 | llvm::BitstreamEntry Entry = |
| 5338 | M.PreprocessorDetailCursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd); |
| 5339 | if (Entry.Kind != llvm::BitstreamEntry::Record) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5340 | return nullptr; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5341 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5342 | // Read the record. |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 5343 | SourceRange Range(TranslateSourceLocation(M, PPOffs.getBegin()), |
| 5344 | TranslateSourceLocation(M, PPOffs.getEnd())); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5345 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5346 | StringRef Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5347 | RecordData Record; |
| 5348 | PreprocessorDetailRecordTypes RecType = |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5349 | (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.readRecord( |
| 5350 | Entry.ID, Record, &Blob); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5351 | switch (RecType) { |
| 5352 | case PPD_MACRO_EXPANSION: { |
| 5353 | bool isBuiltin = Record[0]; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5354 | IdentifierInfo *Name = nullptr; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5355 | MacroDefinitionRecord *Def = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5356 | if (isBuiltin) |
| 5357 | Name = getLocalIdentifier(M, Record[1]); |
| 5358 | else { |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5359 | PreprocessedEntityID GlobalID = |
| 5360 | getGlobalPreprocessedEntityID(M, Record[1]); |
| 5361 | Def = cast<MacroDefinitionRecord>( |
| 5362 | PPRec.getLoadedPreprocessedEntity(GlobalID - 1)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5363 | } |
| 5364 | |
| 5365 | MacroExpansion *ME; |
| 5366 | if (isBuiltin) |
| 5367 | ME = new (PPRec) MacroExpansion(Name, Range); |
| 5368 | else |
| 5369 | ME = new (PPRec) MacroExpansion(Def, Range); |
| 5370 | |
| 5371 | return ME; |
| 5372 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5373 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5374 | case PPD_MACRO_DEFINITION: { |
| 5375 | // Decode the identifier info and then check again; if the macro is |
| 5376 | // still defined and associated with the identifier, |
| 5377 | IdentifierInfo *II = getLocalIdentifier(M, Record[0]); |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5378 | MacroDefinitionRecord *MD = new (PPRec) MacroDefinitionRecord(II, Range); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5379 | |
| 5380 | if (DeserializationListener) |
| 5381 | DeserializationListener->MacroDefinitionRead(PPID, MD); |
| 5382 | |
| 5383 | return MD; |
| 5384 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5385 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5386 | case PPD_INCLUSION_DIRECTIVE: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5387 | const char *FullFileNameStart = Blob.data() + Record[0]; |
| 5388 | StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5389 | const FileEntry *File = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5390 | if (!FullFileName.empty()) |
| 5391 | File = PP.getFileManager().getFile(FullFileName); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5392 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5393 | // FIXME: Stable encoding |
| 5394 | InclusionDirective::InclusionKind Kind |
| 5395 | = static_cast<InclusionDirective::InclusionKind>(Record[2]); |
| 5396 | InclusionDirective *ID |
| 5397 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5398 | StringRef(Blob.data(), Record[0]), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5399 | Record[1], Record[3], |
| 5400 | File, |
| 5401 | Range); |
| 5402 | return ID; |
| 5403 | } |
| 5404 | } |
| 5405 | |
| 5406 | llvm_unreachable("Invalid PreprocessorDetailRecordTypes"); |
| 5407 | } |
| 5408 | |
| 5409 | /// \brief \arg SLocMapI points at a chunk of a module that contains no |
| 5410 | /// preprocessed entities or the entities it contains are not the ones we are |
| 5411 | /// looking for. Find the next module that contains entities and return the ID |
| 5412 | /// of the first entry. |
| 5413 | PreprocessedEntityID ASTReader::findNextPreprocessedEntity( |
| 5414 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const { |
| 5415 | ++SLocMapI; |
| 5416 | for (GlobalSLocOffsetMapType::const_iterator |
| 5417 | EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) { |
| 5418 | ModuleFile &M = *SLocMapI->second; |
| 5419 | if (M.NumPreprocessedEntities) |
| 5420 | return M.BasePreprocessedEntityID; |
| 5421 | } |
| 5422 | |
| 5423 | return getTotalNumPreprocessedEntities(); |
| 5424 | } |
| 5425 | |
| 5426 | namespace { |
| 5427 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5428 | struct PPEntityComp { |
| 5429 | const ASTReader &Reader; |
| 5430 | ModuleFile &M; |
| 5431 | |
| 5432 | PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) { } |
| 5433 | |
| 5434 | bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const { |
| 5435 | SourceLocation LHS = getLoc(L); |
| 5436 | SourceLocation RHS = getLoc(R); |
| 5437 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5438 | } |
| 5439 | |
| 5440 | bool operator()(const PPEntityOffset &L, SourceLocation RHS) const { |
| 5441 | SourceLocation LHS = getLoc(L); |
| 5442 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5443 | } |
| 5444 | |
| 5445 | bool operator()(SourceLocation LHS, const PPEntityOffset &R) const { |
| 5446 | SourceLocation RHS = getLoc(R); |
| 5447 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5448 | } |
| 5449 | |
| 5450 | SourceLocation getLoc(const PPEntityOffset &PPE) const { |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5451 | return Reader.TranslateSourceLocation(M, PPE.getBegin()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5452 | } |
| 5453 | }; |
| 5454 | |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5455 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5456 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5457 | PreprocessedEntityID ASTReader::findPreprocessedEntity(SourceLocation Loc, |
| 5458 | bool EndsAfter) const { |
| 5459 | if (SourceMgr.isLocalSourceLocation(Loc)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5460 | return getTotalNumPreprocessedEntities(); |
| 5461 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5462 | GlobalSLocOffsetMapType::const_iterator SLocMapI = GlobalSLocOffsetMap.find( |
| 5463 | SourceManager::MaxLoadedOffset - Loc.getOffset() - 1); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5464 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 5465 | "Corrupted global sloc offset map"); |
| 5466 | |
| 5467 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 5468 | return findNextPreprocessedEntity(SLocMapI); |
| 5469 | |
| 5470 | ModuleFile &M = *SLocMapI->second; |
| 5471 | typedef const PPEntityOffset *pp_iterator; |
| 5472 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 5473 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
| 5474 | |
| 5475 | size_t Count = M.NumPreprocessedEntities; |
| 5476 | size_t Half; |
| 5477 | pp_iterator First = pp_begin; |
| 5478 | pp_iterator PPI; |
| 5479 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5480 | if (EndsAfter) { |
| 5481 | PPI = std::upper_bound(pp_begin, pp_end, Loc, |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5482 | PPEntityComp(*this, M)); |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5483 | } else { |
| 5484 | // Do a binary search manually instead of using std::lower_bound because |
| 5485 | // The end locations of entities may be unordered (when a macro expansion |
| 5486 | // is inside another macro argument), but for this case it is not important |
| 5487 | // whether we get the first macro expansion or its containing macro. |
| 5488 | while (Count > 0) { |
| 5489 | Half = Count / 2; |
| 5490 | PPI = First; |
| 5491 | std::advance(PPI, Half); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5492 | if (SourceMgr.isBeforeInTranslationUnit( |
| 5493 | TranslateSourceLocation(M, PPI->getEnd()), Loc)) { |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5494 | First = PPI; |
| 5495 | ++First; |
| 5496 | Count = Count - Half - 1; |
| 5497 | } else |
| 5498 | Count = Half; |
| 5499 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5500 | } |
| 5501 | |
| 5502 | if (PPI == pp_end) |
| 5503 | return findNextPreprocessedEntity(SLocMapI); |
| 5504 | |
| 5505 | return M.BasePreprocessedEntityID + (PPI - pp_begin); |
| 5506 | } |
| 5507 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5508 | /// \brief Returns a pair of [Begin, End) indices of preallocated |
| 5509 | /// preprocessed entities that \arg Range encompasses. |
| 5510 | std::pair<unsigned, unsigned> |
| 5511 | ASTReader::findPreprocessedEntitiesInRange(SourceRange Range) { |
| 5512 | if (Range.isInvalid()) |
| 5513 | return std::make_pair(0,0); |
| 5514 | assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); |
| 5515 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5516 | PreprocessedEntityID BeginID = |
| 5517 | findPreprocessedEntity(Range.getBegin(), false); |
| 5518 | PreprocessedEntityID EndID = findPreprocessedEntity(Range.getEnd(), true); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5519 | return std::make_pair(BeginID, EndID); |
| 5520 | } |
| 5521 | |
| 5522 | /// \brief Optionally returns true or false if the preallocated preprocessed |
| 5523 | /// entity with index \arg Index came from file \arg FID. |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5524 | Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5525 | FileID FID) { |
| 5526 | if (FID.isInvalid()) |
| 5527 | return false; |
| 5528 | |
| 5529 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 5530 | ModuleFile &M = *PPInfo.first; |
| 5531 | unsigned LocalIndex = PPInfo.second; |
| 5532 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5533 | |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 5534 | SourceLocation Loc = TranslateSourceLocation(M, PPOffs.getBegin()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5535 | if (Loc.isInvalid()) |
| 5536 | return false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5537 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5538 | if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) |
| 5539 | return true; |
| 5540 | else |
| 5541 | return false; |
| 5542 | } |
| 5543 | |
| 5544 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5545 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5546 | /// \brief Visitor used to search for information about a header file. |
| 5547 | class HeaderFileInfoVisitor { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5548 | const FileEntry *FE; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5549 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5550 | Optional<HeaderFileInfo> HFI; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5551 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5552 | public: |
Argyrios Kyrtzidis | 61a3896 | 2013-03-06 18:12:44 +0000 | [diff] [blame] | 5553 | explicit HeaderFileInfoVisitor(const FileEntry *FE) |
| 5554 | : FE(FE) { } |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 5555 | |
| 5556 | bool operator()(ModuleFile &M) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5557 | HeaderFileInfoLookupTable *Table |
| 5558 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 5559 | if (!Table) |
| 5560 | return false; |
| 5561 | |
| 5562 | // 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] | 5563 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5564 | if (Pos == Table->end()) |
| 5565 | return false; |
| 5566 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 5567 | HFI = *Pos; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5568 | return true; |
| 5569 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5570 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5571 | Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5572 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5573 | |
| 5574 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5575 | |
| 5576 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Argyrios Kyrtzidis | 61a3896 | 2013-03-06 18:12:44 +0000 | [diff] [blame] | 5577 | HeaderFileInfoVisitor Visitor(FE); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 5578 | ModuleMgr.visit(Visitor); |
Argyrios Kyrtzidis | 1054bbf | 2013-05-08 23:46:55 +0000 | [diff] [blame] | 5579 | if (Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5580 | return *HFI; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5581 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5582 | return HeaderFileInfo(); |
| 5583 | } |
| 5584 | |
| 5585 | void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5586 | using DiagState = DiagnosticsEngine::DiagState; |
| 5587 | SmallVector<DiagState *, 32> DiagStates; |
| 5588 | |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 5589 | for (ModuleFile &F : ModuleMgr) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5590 | unsigned Idx = 0; |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5591 | auto &Record = F.PragmaDiagMappings; |
| 5592 | if (Record.empty()) |
| 5593 | continue; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5594 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5595 | DiagStates.clear(); |
| 5596 | |
| 5597 | auto ReadDiagState = |
| 5598 | [&](const DiagState &BasedOn, SourceLocation Loc, |
| 5599 | bool IncludeNonPragmaStates) -> DiagnosticsEngine::DiagState * { |
| 5600 | unsigned BackrefID = Record[Idx++]; |
| 5601 | if (BackrefID != 0) |
| 5602 | return DiagStates[BackrefID - 1]; |
| 5603 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5604 | // A new DiagState was created here. |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5605 | Diag.DiagStates.push_back(BasedOn); |
| 5606 | DiagState *NewState = &Diag.DiagStates.back(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5607 | DiagStates.push_back(NewState); |
Duncan P. N. Exon Smith | 3cb183b | 2017-03-14 19:31:27 +0000 | [diff] [blame] | 5608 | unsigned Size = Record[Idx++]; |
| 5609 | assert(Idx + Size * 2 <= Record.size() && |
| 5610 | "Invalid data, not enough diag/map pairs"); |
| 5611 | while (Size--) { |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5612 | unsigned DiagID = Record[Idx++]; |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5613 | DiagnosticMapping NewMapping = |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5614 | DiagnosticMapping::deserialize(Record[Idx++]); |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5615 | if (!NewMapping.isPragma() && !IncludeNonPragmaStates) |
| 5616 | continue; |
| 5617 | |
| 5618 | DiagnosticMapping &Mapping = NewState->getOrAddMapping(DiagID); |
| 5619 | |
| 5620 | // If this mapping was specified as a warning but the severity was |
| 5621 | // upgraded due to diagnostic settings, simulate the current diagnostic |
| 5622 | // settings (and use a warning). |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5623 | if (NewMapping.wasUpgradedFromWarning() && !Mapping.isErrorOrFatal()) { |
| 5624 | NewMapping.setSeverity(diag::Severity::Warning); |
| 5625 | NewMapping.setUpgradedFromWarning(false); |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5626 | } |
| 5627 | |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5628 | Mapping = NewMapping; |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5629 | } |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5630 | return NewState; |
| 5631 | }; |
| 5632 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5633 | // Read the first state. |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5634 | DiagState *FirstState; |
| 5635 | if (F.Kind == MK_ImplicitModule) { |
| 5636 | // Implicitly-built modules are reused with different diagnostic |
| 5637 | // settings. Use the initial diagnostic state from Diag to simulate this |
| 5638 | // compilation's diagnostic settings. |
| 5639 | FirstState = Diag.DiagStatesByLoc.FirstDiagState; |
| 5640 | DiagStates.push_back(FirstState); |
| 5641 | |
| 5642 | // Skip the initial diagnostic state from the serialized module. |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5643 | assert(Record[1] == 0 && |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5644 | "Invalid data, unexpected backref in initial state"); |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5645 | Idx = 3 + Record[2] * 2; |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5646 | assert(Idx < Record.size() && |
| 5647 | "Invalid data, not enough state change pairs in initial state"); |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5648 | } else if (F.isModule()) { |
| 5649 | // For an explicit module, preserve the flags from the module build |
| 5650 | // command line (-w, -Weverything, -Werror, ...) along with any explicit |
| 5651 | // -Wblah flags. |
| 5652 | unsigned Flags = Record[Idx++]; |
| 5653 | DiagState Initial; |
| 5654 | Initial.SuppressSystemWarnings = Flags & 1; Flags >>= 1; |
| 5655 | Initial.ErrorsAsFatal = Flags & 1; Flags >>= 1; |
| 5656 | Initial.WarningsAsErrors = Flags & 1; Flags >>= 1; |
| 5657 | Initial.EnableAllWarnings = Flags & 1; Flags >>= 1; |
| 5658 | Initial.IgnoreAllWarnings = Flags & 1; Flags >>= 1; |
| 5659 | Initial.ExtBehavior = (diag::Severity)Flags; |
| 5660 | FirstState = ReadDiagState(Initial, SourceLocation(), true); |
Richard Smith | ea74148 | 2017-05-01 22:10:47 +0000 | [diff] [blame] | 5661 | |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5662 | // Set up the root buffer of the module to start with the initial |
| 5663 | // diagnostic state of the module itself, to cover files that contain no |
| 5664 | // explicit transitions (for which we did not serialize anything). |
| 5665 | Diag.DiagStatesByLoc.Files[F.OriginalSourceFileID] |
| 5666 | .StateTransitions.push_back({FirstState, 0}); |
| 5667 | } else { |
| 5668 | // For prefix ASTs, start with whatever the user configured on the |
| 5669 | // command line. |
| 5670 | Idx++; // Skip flags. |
| 5671 | FirstState = ReadDiagState(*Diag.DiagStatesByLoc.CurDiagState, |
| 5672 | SourceLocation(), false); |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5673 | } |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5674 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5675 | // Read the state transitions. |
| 5676 | unsigned NumLocations = Record[Idx++]; |
| 5677 | while (NumLocations--) { |
| 5678 | assert(Idx < Record.size() && |
| 5679 | "Invalid data, missing pragma diagnostic states"); |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5680 | SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]); |
| 5681 | auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc); |
| 5682 | assert(IDAndOffset.second == 0 && "not a start location for a FileID"); |
| 5683 | unsigned Transitions = Record[Idx++]; |
| 5684 | |
| 5685 | // Note that we don't need to set up Parent/ParentOffset here, because |
| 5686 | // we won't be changing the diagnostic state within imported FileIDs |
| 5687 | // (other than perhaps appending to the main source file, which has no |
| 5688 | // parent). |
| 5689 | auto &F = Diag.DiagStatesByLoc.Files[IDAndOffset.first]; |
| 5690 | F.StateTransitions.reserve(F.StateTransitions.size() + Transitions); |
| 5691 | for (unsigned I = 0; I != Transitions; ++I) { |
| 5692 | unsigned Offset = Record[Idx++]; |
| 5693 | auto *State = |
| 5694 | ReadDiagState(*FirstState, Loc.getLocWithOffset(Offset), false); |
| 5695 | F.StateTransitions.push_back({State, Offset}); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5696 | } |
| 5697 | } |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5698 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5699 | // Read the final state. |
| 5700 | assert(Idx < Record.size() && |
| 5701 | "Invalid data, missing final pragma diagnostic state"); |
| 5702 | SourceLocation CurStateLoc = |
| 5703 | ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
| 5704 | auto *CurState = ReadDiagState(*FirstState, CurStateLoc, false); |
| 5705 | |
| 5706 | if (!F.isModule()) { |
| 5707 | Diag.DiagStatesByLoc.CurDiagState = CurState; |
| 5708 | Diag.DiagStatesByLoc.CurDiagStateLoc = CurStateLoc; |
| 5709 | |
| 5710 | // Preserve the property that the imaginary root file describes the |
| 5711 | // current state. |
| 5712 | auto &T = Diag.DiagStatesByLoc.Files[FileID()].StateTransitions; |
| 5713 | if (T.empty()) |
| 5714 | T.push_back({CurState, 0}); |
| 5715 | else |
| 5716 | T[0].State = CurState; |
| 5717 | } |
| 5718 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5719 | // Don't try to read these mappings again. |
| 5720 | Record.clear(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5721 | } |
| 5722 | } |
| 5723 | |
| 5724 | /// \brief Get the correct cursor and offset for loading a type. |
| 5725 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
| 5726 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
| 5727 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
| 5728 | ModuleFile *M = I->second; |
| 5729 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
| 5730 | } |
| 5731 | |
| 5732 | /// \brief Read and return the type with the given index.. |
| 5733 | /// |
| 5734 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 5735 | /// routine actually reads the record corresponding to the type at the given |
| 5736 | /// location. It is a helper routine for GetType, which deals with reading type |
| 5737 | /// IDs. |
| 5738 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5739 | assert(ContextObj && "reading type with no AST context"); |
| 5740 | ASTContext &Context = *ContextObj; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5741 | RecordLocation Loc = TypeCursorForIndex(Index); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5742 | BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5743 | |
| 5744 | // Keep track of where we are in the stream, then jump back there |
| 5745 | // after reading this type. |
| 5746 | SavedStreamPosition SavedPosition(DeclsCursor); |
| 5747 | |
| 5748 | ReadingKindTracker ReadingKind(Read_Type, *this); |
| 5749 | |
| 5750 | // Note that we are loading a type record. |
| 5751 | Deserializing AType(this); |
| 5752 | |
| 5753 | unsigned Idx = 0; |
| 5754 | DeclsCursor.JumpToBit(Loc.Offset); |
| 5755 | RecordData Record; |
| 5756 | unsigned Code = DeclsCursor.ReadCode(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5757 | switch ((TypeCode)DeclsCursor.readRecord(Code, Record)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5758 | case TYPE_EXT_QUAL: { |
| 5759 | if (Record.size() != 2) { |
| 5760 | Error("Incorrect encoding of extended qualifier type"); |
| 5761 | return QualType(); |
| 5762 | } |
| 5763 | QualType Base = readType(*Loc.F, Record, Idx); |
| 5764 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
| 5765 | return Context.getQualifiedType(Base, Quals); |
| 5766 | } |
| 5767 | |
| 5768 | case TYPE_COMPLEX: { |
| 5769 | if (Record.size() != 1) { |
| 5770 | Error("Incorrect encoding of complex type"); |
| 5771 | return QualType(); |
| 5772 | } |
| 5773 | QualType ElemType = readType(*Loc.F, Record, Idx); |
| 5774 | return Context.getComplexType(ElemType); |
| 5775 | } |
| 5776 | |
| 5777 | case TYPE_POINTER: { |
| 5778 | if (Record.size() != 1) { |
| 5779 | Error("Incorrect encoding of pointer type"); |
| 5780 | return QualType(); |
| 5781 | } |
| 5782 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5783 | return Context.getPointerType(PointeeType); |
| 5784 | } |
| 5785 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 5786 | case TYPE_DECAYED: { |
| 5787 | if (Record.size() != 1) { |
| 5788 | Error("Incorrect encoding of decayed type"); |
| 5789 | return QualType(); |
| 5790 | } |
| 5791 | QualType OriginalType = readType(*Loc.F, Record, Idx); |
| 5792 | QualType DT = Context.getAdjustedParameterType(OriginalType); |
| 5793 | if (!isa<DecayedType>(DT)) |
| 5794 | Error("Decayed type does not decay"); |
| 5795 | return DT; |
| 5796 | } |
| 5797 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 5798 | case TYPE_ADJUSTED: { |
| 5799 | if (Record.size() != 2) { |
| 5800 | Error("Incorrect encoding of adjusted type"); |
| 5801 | return QualType(); |
| 5802 | } |
| 5803 | QualType OriginalTy = readType(*Loc.F, Record, Idx); |
| 5804 | QualType AdjustedTy = readType(*Loc.F, Record, Idx); |
| 5805 | return Context.getAdjustedType(OriginalTy, AdjustedTy); |
| 5806 | } |
| 5807 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5808 | case TYPE_BLOCK_POINTER: { |
| 5809 | if (Record.size() != 1) { |
| 5810 | Error("Incorrect encoding of block pointer type"); |
| 5811 | return QualType(); |
| 5812 | } |
| 5813 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5814 | return Context.getBlockPointerType(PointeeType); |
| 5815 | } |
| 5816 | |
| 5817 | case TYPE_LVALUE_REFERENCE: { |
| 5818 | if (Record.size() != 2) { |
| 5819 | Error("Incorrect encoding of lvalue reference type"); |
| 5820 | return QualType(); |
| 5821 | } |
| 5822 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5823 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
| 5824 | } |
| 5825 | |
| 5826 | case TYPE_RVALUE_REFERENCE: { |
| 5827 | if (Record.size() != 1) { |
| 5828 | Error("Incorrect encoding of rvalue reference type"); |
| 5829 | return QualType(); |
| 5830 | } |
| 5831 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5832 | return Context.getRValueReferenceType(PointeeType); |
| 5833 | } |
| 5834 | |
| 5835 | case TYPE_MEMBER_POINTER: { |
| 5836 | if (Record.size() != 2) { |
| 5837 | Error("Incorrect encoding of member pointer type"); |
| 5838 | return QualType(); |
| 5839 | } |
| 5840 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5841 | QualType ClassType = readType(*Loc.F, Record, Idx); |
| 5842 | if (PointeeType.isNull() || ClassType.isNull()) |
| 5843 | return QualType(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5844 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5845 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
| 5846 | } |
| 5847 | |
| 5848 | case TYPE_CONSTANT_ARRAY: { |
| 5849 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5850 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 5851 | unsigned IndexTypeQuals = Record[2]; |
| 5852 | unsigned Idx = 3; |
| 5853 | llvm::APInt Size = ReadAPInt(Record, Idx); |
| 5854 | return Context.getConstantArrayType(ElementType, Size, |
| 5855 | ASM, IndexTypeQuals); |
| 5856 | } |
| 5857 | |
| 5858 | case TYPE_INCOMPLETE_ARRAY: { |
| 5859 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5860 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 5861 | unsigned IndexTypeQuals = Record[2]; |
| 5862 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
| 5863 | } |
| 5864 | |
| 5865 | case TYPE_VARIABLE_ARRAY: { |
| 5866 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5867 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 5868 | unsigned IndexTypeQuals = Record[2]; |
| 5869 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 5870 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 5871 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
| 5872 | ASM, IndexTypeQuals, |
| 5873 | SourceRange(LBLoc, RBLoc)); |
| 5874 | } |
| 5875 | |
| 5876 | case TYPE_VECTOR: { |
| 5877 | if (Record.size() != 3) { |
| 5878 | Error("incorrect encoding of vector type in AST file"); |
| 5879 | return QualType(); |
| 5880 | } |
| 5881 | |
| 5882 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5883 | unsigned NumElements = Record[1]; |
| 5884 | unsigned VecKind = Record[2]; |
| 5885 | return Context.getVectorType(ElementType, NumElements, |
| 5886 | (VectorType::VectorKind)VecKind); |
| 5887 | } |
| 5888 | |
| 5889 | case TYPE_EXT_VECTOR: { |
| 5890 | if (Record.size() != 3) { |
| 5891 | Error("incorrect encoding of extended vector type in AST file"); |
| 5892 | return QualType(); |
| 5893 | } |
| 5894 | |
| 5895 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5896 | unsigned NumElements = Record[1]; |
| 5897 | return Context.getExtVectorType(ElementType, NumElements); |
| 5898 | } |
| 5899 | |
| 5900 | case TYPE_FUNCTION_NO_PROTO: { |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5901 | if (Record.size() != 7) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5902 | Error("incorrect encoding of no-proto function type"); |
| 5903 | return QualType(); |
| 5904 | } |
| 5905 | QualType ResultType = readType(*Loc.F, Record, Idx); |
| 5906 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5907 | (CallingConv)Record[4], Record[5], Record[6]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5908 | return Context.getFunctionNoProtoType(ResultType, Info); |
| 5909 | } |
| 5910 | |
| 5911 | case TYPE_FUNCTION_PROTO: { |
| 5912 | QualType ResultType = readType(*Loc.F, Record, Idx); |
| 5913 | |
| 5914 | FunctionProtoType::ExtProtoInfo EPI; |
| 5915 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
| 5916 | /*hasregparm*/ Record[2], |
| 5917 | /*regparm*/ Record[3], |
| 5918 | static_cast<CallingConv>(Record[4]), |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5919 | /*produces*/ Record[5], |
| 5920 | /*nocallersavedregs*/ Record[6]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5921 | |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5922 | unsigned Idx = 7; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5923 | |
| 5924 | EPI.Variadic = Record[Idx++]; |
| 5925 | EPI.HasTrailingReturn = Record[Idx++]; |
| 5926 | EPI.TypeQuals = Record[Idx++]; |
| 5927 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5928 | SmallVector<QualType, 8> ExceptionStorage; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 5929 | readExceptionSpec(*Loc.F, ExceptionStorage, EPI.ExceptionSpec, Record, Idx); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 5930 | |
| 5931 | unsigned NumParams = Record[Idx++]; |
| 5932 | SmallVector<QualType, 16> ParamTypes; |
| 5933 | for (unsigned I = 0; I != NumParams; ++I) |
| 5934 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
| 5935 | |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 5936 | SmallVector<FunctionProtoType::ExtParameterInfo, 4> ExtParameterInfos; |
| 5937 | if (Idx != Record.size()) { |
| 5938 | for (unsigned I = 0; I != NumParams; ++I) |
| 5939 | ExtParameterInfos.push_back( |
| 5940 | FunctionProtoType::ExtParameterInfo |
| 5941 | ::getFromOpaqueValue(Record[Idx++])); |
| 5942 | EPI.ExtParameterInfos = ExtParameterInfos.data(); |
| 5943 | } |
| 5944 | |
| 5945 | assert(Idx == Record.size()); |
| 5946 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 5947 | return Context.getFunctionType(ResultType, ParamTypes, EPI); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5948 | } |
| 5949 | |
| 5950 | case TYPE_UNRESOLVED_USING: { |
| 5951 | unsigned Idx = 0; |
| 5952 | return Context.getTypeDeclType( |
| 5953 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 5954 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5955 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5956 | case TYPE_TYPEDEF: { |
| 5957 | if (Record.size() != 2) { |
| 5958 | Error("incorrect encoding of typedef type"); |
| 5959 | return QualType(); |
| 5960 | } |
| 5961 | unsigned Idx = 0; |
| 5962 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
| 5963 | QualType Canonical = readType(*Loc.F, Record, Idx); |
| 5964 | if (!Canonical.isNull()) |
| 5965 | Canonical = Context.getCanonicalType(Canonical); |
| 5966 | return Context.getTypedefType(Decl, Canonical); |
| 5967 | } |
| 5968 | |
| 5969 | case TYPE_TYPEOF_EXPR: |
| 5970 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
| 5971 | |
| 5972 | case TYPE_TYPEOF: { |
| 5973 | if (Record.size() != 1) { |
| 5974 | Error("incorrect encoding of typeof(type) in AST file"); |
| 5975 | return QualType(); |
| 5976 | } |
| 5977 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 5978 | return Context.getTypeOfType(UnderlyingType); |
| 5979 | } |
| 5980 | |
| 5981 | case TYPE_DECLTYPE: { |
| 5982 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 5983 | return Context.getDecltypeType(ReadExpr(*Loc.F), UnderlyingType); |
| 5984 | } |
| 5985 | |
| 5986 | case TYPE_UNARY_TRANSFORM: { |
| 5987 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 5988 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 5989 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
| 5990 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
| 5991 | } |
| 5992 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 5993 | case TYPE_AUTO: { |
| 5994 | QualType Deduced = readType(*Loc.F, Record, Idx); |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 5995 | AutoTypeKeyword Keyword = (AutoTypeKeyword)Record[Idx++]; |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 5996 | bool IsDependent = Deduced.isNull() ? Record[Idx++] : false; |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 5997 | return Context.getAutoType(Deduced, Keyword, IsDependent); |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 5998 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5999 | |
Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 6000 | case TYPE_DEDUCED_TEMPLATE_SPECIALIZATION: { |
| 6001 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
| 6002 | QualType Deduced = readType(*Loc.F, Record, Idx); |
| 6003 | bool IsDependent = Deduced.isNull() ? Record[Idx++] : false; |
| 6004 | return Context.getDeducedTemplateSpecializationType(Name, Deduced, |
| 6005 | IsDependent); |
| 6006 | } |
| 6007 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6008 | case TYPE_RECORD: { |
| 6009 | if (Record.size() != 2) { |
| 6010 | Error("incorrect encoding of record type"); |
| 6011 | return QualType(); |
| 6012 | } |
| 6013 | unsigned Idx = 0; |
| 6014 | bool IsDependent = Record[Idx++]; |
| 6015 | RecordDecl *RD = ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx); |
| 6016 | RD = cast_or_null<RecordDecl>(RD->getCanonicalDecl()); |
| 6017 | QualType T = Context.getRecordType(RD); |
| 6018 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 6019 | return T; |
| 6020 | } |
| 6021 | |
| 6022 | case TYPE_ENUM: { |
| 6023 | if (Record.size() != 2) { |
| 6024 | Error("incorrect encoding of enum type"); |
| 6025 | return QualType(); |
| 6026 | } |
| 6027 | unsigned Idx = 0; |
| 6028 | bool IsDependent = Record[Idx++]; |
| 6029 | QualType T |
| 6030 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
| 6031 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 6032 | return T; |
| 6033 | } |
| 6034 | |
| 6035 | case TYPE_ATTRIBUTED: { |
| 6036 | if (Record.size() != 3) { |
| 6037 | Error("incorrect encoding of attributed type"); |
| 6038 | return QualType(); |
| 6039 | } |
| 6040 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 6041 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
| 6042 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 6043 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
| 6044 | } |
| 6045 | |
| 6046 | case TYPE_PAREN: { |
| 6047 | if (Record.size() != 1) { |
| 6048 | Error("incorrect encoding of paren type"); |
| 6049 | return QualType(); |
| 6050 | } |
| 6051 | QualType InnerType = readType(*Loc.F, Record, Idx); |
| 6052 | return Context.getParenType(InnerType); |
| 6053 | } |
| 6054 | |
| 6055 | case TYPE_PACK_EXPANSION: { |
| 6056 | if (Record.size() != 2) { |
| 6057 | Error("incorrect encoding of pack expansion type"); |
| 6058 | return QualType(); |
| 6059 | } |
| 6060 | QualType Pattern = readType(*Loc.F, Record, Idx); |
| 6061 | if (Pattern.isNull()) |
| 6062 | return QualType(); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 6063 | Optional<unsigned> NumExpansions; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6064 | if (Record[1]) |
| 6065 | NumExpansions = Record[1] - 1; |
| 6066 | return Context.getPackExpansionType(Pattern, NumExpansions); |
| 6067 | } |
| 6068 | |
| 6069 | case TYPE_ELABORATED: { |
| 6070 | unsigned Idx = 0; |
| 6071 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 6072 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
| 6073 | QualType NamedType = readType(*Loc.F, Record, Idx); |
| 6074 | return Context.getElaboratedType(Keyword, NNS, NamedType); |
| 6075 | } |
| 6076 | |
| 6077 | case TYPE_OBJC_INTERFACE: { |
| 6078 | unsigned Idx = 0; |
| 6079 | ObjCInterfaceDecl *ItfD |
| 6080 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
| 6081 | return Context.getObjCInterfaceType(ItfD->getCanonicalDecl()); |
| 6082 | } |
| 6083 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6084 | case TYPE_OBJC_TYPE_PARAM: { |
| 6085 | unsigned Idx = 0; |
| 6086 | ObjCTypeParamDecl *Decl |
| 6087 | = ReadDeclAs<ObjCTypeParamDecl>(*Loc.F, Record, Idx); |
| 6088 | unsigned NumProtos = Record[Idx++]; |
| 6089 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 6090 | for (unsigned I = 0; I != NumProtos; ++I) |
| 6091 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
| 6092 | return Context.getObjCTypeParamType(Decl, Protos); |
| 6093 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6094 | case TYPE_OBJC_OBJECT: { |
| 6095 | unsigned Idx = 0; |
| 6096 | QualType Base = readType(*Loc.F, Record, Idx); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6097 | unsigned NumTypeArgs = Record[Idx++]; |
| 6098 | SmallVector<QualType, 4> TypeArgs; |
| 6099 | for (unsigned I = 0; I != NumTypeArgs; ++I) |
| 6100 | TypeArgs.push_back(readType(*Loc.F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6101 | unsigned NumProtos = Record[Idx++]; |
| 6102 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 6103 | for (unsigned I = 0; I != NumProtos; ++I) |
| 6104 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 6105 | bool IsKindOf = Record[Idx++]; |
| 6106 | return Context.getObjCObjectType(Base, TypeArgs, Protos, IsKindOf); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6107 | } |
| 6108 | |
| 6109 | case TYPE_OBJC_OBJECT_POINTER: { |
| 6110 | unsigned Idx = 0; |
| 6111 | QualType Pointee = readType(*Loc.F, Record, Idx); |
| 6112 | return Context.getObjCObjectPointerType(Pointee); |
| 6113 | } |
| 6114 | |
| 6115 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
| 6116 | unsigned Idx = 0; |
| 6117 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 6118 | QualType Replacement = readType(*Loc.F, Record, Idx); |
Stephan Tolksdorf | e96f8b3 | 2014-03-15 10:23:27 +0000 | [diff] [blame] | 6119 | return Context.getSubstTemplateTypeParmType( |
| 6120 | cast<TemplateTypeParmType>(Parm), |
| 6121 | Context.getCanonicalType(Replacement)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6122 | } |
| 6123 | |
| 6124 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 6125 | unsigned Idx = 0; |
| 6126 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 6127 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 6128 | return Context.getSubstTemplateTypeParmPackType( |
| 6129 | cast<TemplateTypeParmType>(Parm), |
| 6130 | ArgPack); |
| 6131 | } |
| 6132 | |
| 6133 | case TYPE_INJECTED_CLASS_NAME: { |
| 6134 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
| 6135 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
| 6136 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
| 6137 | // for AST reading, too much interdependencies. |
Richard Smith | 6377f8f | 2014-10-21 21:15:18 +0000 | [diff] [blame] | 6138 | const Type *T = nullptr; |
| 6139 | for (auto *DI = D; DI; DI = DI->getPreviousDecl()) { |
| 6140 | if (const Type *Existing = DI->getTypeForDecl()) { |
| 6141 | T = Existing; |
| 6142 | break; |
| 6143 | } |
| 6144 | } |
| 6145 | if (!T) { |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 6146 | T = new (Context, TypeAlignment) InjectedClassNameType(D, TST); |
Richard Smith | 6377f8f | 2014-10-21 21:15:18 +0000 | [diff] [blame] | 6147 | for (auto *DI = D; DI; DI = DI->getPreviousDecl()) |
| 6148 | DI->setTypeForDecl(T); |
| 6149 | } |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 6150 | return QualType(T, 0); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6151 | } |
| 6152 | |
| 6153 | case TYPE_TEMPLATE_TYPE_PARM: { |
| 6154 | unsigned Idx = 0; |
| 6155 | unsigned Depth = Record[Idx++]; |
| 6156 | unsigned Index = Record[Idx++]; |
| 6157 | bool Pack = Record[Idx++]; |
| 6158 | TemplateTypeParmDecl *D |
| 6159 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
| 6160 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
| 6161 | } |
| 6162 | |
| 6163 | case TYPE_DEPENDENT_NAME: { |
| 6164 | unsigned Idx = 0; |
| 6165 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 6166 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 6167 | const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6168 | QualType Canon = readType(*Loc.F, Record, Idx); |
| 6169 | if (!Canon.isNull()) |
| 6170 | Canon = Context.getCanonicalType(Canon); |
| 6171 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
| 6172 | } |
| 6173 | |
| 6174 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
| 6175 | unsigned Idx = 0; |
| 6176 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 6177 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 6178 | const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6179 | unsigned NumArgs = Record[Idx++]; |
| 6180 | SmallVector<TemplateArgument, 8> Args; |
| 6181 | Args.reserve(NumArgs); |
| 6182 | while (NumArgs--) |
| 6183 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
| 6184 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 6185 | Args); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6186 | } |
| 6187 | |
| 6188 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
| 6189 | unsigned Idx = 0; |
| 6190 | |
| 6191 | // ArrayType |
| 6192 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 6193 | ArrayType::ArraySizeModifier ASM |
| 6194 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 6195 | unsigned IndexTypeQuals = Record[Idx++]; |
| 6196 | |
| 6197 | // DependentSizedArrayType |
| 6198 | Expr *NumElts = ReadExpr(*Loc.F); |
| 6199 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
| 6200 | |
| 6201 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 6202 | IndexTypeQuals, Brackets); |
| 6203 | } |
| 6204 | |
| 6205 | case TYPE_TEMPLATE_SPECIALIZATION: { |
| 6206 | unsigned Idx = 0; |
| 6207 | bool IsDependent = Record[Idx++]; |
| 6208 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
| 6209 | SmallVector<TemplateArgument, 8> Args; |
| 6210 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
| 6211 | QualType Underlying = readType(*Loc.F, Record, Idx); |
| 6212 | QualType T; |
| 6213 | if (Underlying.isNull()) |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 6214 | T = Context.getCanonicalTemplateSpecializationType(Name, Args); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6215 | else |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 6216 | T = Context.getTemplateSpecializationType(Name, Args, Underlying); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6217 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 6218 | return T; |
| 6219 | } |
| 6220 | |
| 6221 | case TYPE_ATOMIC: { |
| 6222 | if (Record.size() != 1) { |
| 6223 | Error("Incorrect encoding of atomic type"); |
| 6224 | return QualType(); |
| 6225 | } |
| 6226 | QualType ValueType = readType(*Loc.F, Record, Idx); |
| 6227 | return Context.getAtomicType(ValueType); |
| 6228 | } |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6229 | |
Joey Gouly | e3c85de | 2016-12-01 11:30:49 +0000 | [diff] [blame] | 6230 | case TYPE_PIPE: { |
| 6231 | if (Record.size() != 2) { |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6232 | Error("Incorrect encoding of pipe type"); |
| 6233 | return QualType(); |
| 6234 | } |
| 6235 | |
| 6236 | // Reading the pipe element type. |
| 6237 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Joey Gouly | e3c85de | 2016-12-01 11:30:49 +0000 | [diff] [blame] | 6238 | unsigned ReadOnly = Record[1]; |
| 6239 | return Context.getPipeType(ElementType, ReadOnly); |
Joey Gouly | 5788b78 | 2016-11-18 14:10:54 +0000 | [diff] [blame] | 6240 | } |
| 6241 | |
Alex Lorenz | 00aee43 | 2017-03-22 10:04:48 +0000 | [diff] [blame] | 6242 | case TYPE_DEPENDENT_SIZED_EXT_VECTOR: { |
| 6243 | unsigned Idx = 0; |
| 6244 | |
| 6245 | // DependentSizedExtVectorType |
| 6246 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 6247 | Expr *SizeExpr = ReadExpr(*Loc.F); |
| 6248 | SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx); |
| 6249 | |
| 6250 | return Context.getDependentSizedExtVectorType(ElementType, SizeExpr, |
| 6251 | AttrLoc); |
| 6252 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6253 | } |
| 6254 | llvm_unreachable("Invalid TypeCode!"); |
| 6255 | } |
| 6256 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6257 | void ASTReader::readExceptionSpec(ModuleFile &ModuleFile, |
| 6258 | SmallVectorImpl<QualType> &Exceptions, |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6259 | FunctionProtoType::ExceptionSpecInfo &ESI, |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6260 | const RecordData &Record, unsigned &Idx) { |
| 6261 | ExceptionSpecificationType EST = |
| 6262 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6263 | ESI.Type = EST; |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6264 | if (EST == EST_Dynamic) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6265 | for (unsigned I = 0, N = Record[Idx++]; I != N; ++I) |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6266 | Exceptions.push_back(readType(ModuleFile, Record, Idx)); |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6267 | ESI.Exceptions = Exceptions; |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6268 | } else if (EST == EST_ComputedNoexcept) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6269 | ESI.NoexceptExpr = ReadExpr(ModuleFile); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6270 | } else if (EST == EST_Uninstantiated) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6271 | ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
| 6272 | ESI.SourceTemplate = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6273 | } else if (EST == EST_Unevaluated) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6274 | ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6275 | } |
| 6276 | } |
| 6277 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6278 | class clang::TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6279 | ModuleFile *F; |
| 6280 | ASTReader *Reader; |
| 6281 | const ASTReader::RecordData &Record; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6282 | unsigned &Idx; |
| 6283 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6284 | SourceLocation ReadSourceLocation() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6285 | return Reader->ReadSourceLocation(*F, Record, Idx); |
| 6286 | } |
| 6287 | |
| 6288 | TypeSourceInfo *GetTypeSourceInfo() { |
| 6289 | return Reader->GetTypeSourceInfo(*F, Record, Idx); |
| 6290 | } |
| 6291 | |
| 6292 | NestedNameSpecifierLoc ReadNestedNameSpecifierLoc() { |
| 6293 | return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6294 | } |
| 6295 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6296 | public: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6297 | TypeLocReader(ModuleFile &F, ASTReader &Reader, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6298 | const ASTReader::RecordData &Record, unsigned &Idx) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6299 | : F(&F), Reader(&Reader), Record(Record), Idx(Idx) {} |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6300 | |
| 6301 | // We want compile-time assurance that we've enumerated all of |
| 6302 | // these, so unfortunately we have to declare them first, then |
| 6303 | // define them out-of-line. |
| 6304 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 6305 | #define TYPELOC(CLASS, PARENT) \ |
| 6306 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
| 6307 | #include "clang/AST/TypeLocNodes.def" |
| 6308 | |
| 6309 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 6310 | void VisitArrayTypeLoc(ArrayTypeLoc); |
| 6311 | }; |
| 6312 | |
| 6313 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 6314 | // nothing to do |
| 6315 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6316 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6317 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6318 | TL.setBuiltinLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6319 | if (TL.needsExtraLocalData()) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6320 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 6321 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 6322 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 6323 | TL.setModeAttr(Record[Idx++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6324 | } |
| 6325 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6326 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6327 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6328 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6329 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6330 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6331 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6332 | TL.setStarLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6333 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6334 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 6335 | void TypeLocReader::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 6336 | // nothing to do |
| 6337 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6338 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 6339 | void TypeLocReader::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 6340 | // nothing to do |
| 6341 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6342 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6343 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6344 | TL.setCaretLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6345 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6346 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6347 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6348 | TL.setAmpLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6349 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6350 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6351 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6352 | TL.setAmpAmpLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6353 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6354 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6355 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6356 | TL.setStarLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6357 | TL.setClassTInfo(GetTypeSourceInfo()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6358 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6359 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6360 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6361 | TL.setLBracketLoc(ReadSourceLocation()); |
| 6362 | TL.setRBracketLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6363 | if (Record[Idx++]) |
| 6364 | TL.setSizeExpr(Reader->ReadExpr(*F)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6365 | else |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6366 | TL.setSizeExpr(nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6367 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6368 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6369 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 6370 | VisitArrayTypeLoc(TL); |
| 6371 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6372 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6373 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 6374 | VisitArrayTypeLoc(TL); |
| 6375 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6376 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6377 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 6378 | VisitArrayTypeLoc(TL); |
| 6379 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6380 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6381 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 6382 | DependentSizedArrayTypeLoc TL) { |
| 6383 | VisitArrayTypeLoc(TL); |
| 6384 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6385 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6386 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 6387 | DependentSizedExtVectorTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6388 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6389 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6390 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6391 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6392 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6393 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6394 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6395 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6396 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6397 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6398 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6399 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6400 | TL.setLocalRangeBegin(ReadSourceLocation()); |
| 6401 | TL.setLParenLoc(ReadSourceLocation()); |
| 6402 | TL.setRParenLoc(ReadSourceLocation()); |
Malcolm Parsons | a3220ce | 2017-01-12 16:11:28 +0000 | [diff] [blame] | 6403 | TL.setExceptionSpecRange(SourceRange(Reader->ReadSourceLocation(*F, Record, Idx), |
| 6404 | Reader->ReadSourceLocation(*F, Record, Idx))); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6405 | TL.setLocalRangeEnd(ReadSourceLocation()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 6406 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6407 | TL.setParam(i, Reader->ReadDeclAs<ParmVarDecl>(*F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6408 | } |
| 6409 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6410 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6411 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 6412 | VisitFunctionTypeLoc(TL); |
| 6413 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6414 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6415 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 6416 | VisitFunctionTypeLoc(TL); |
| 6417 | } |
| 6418 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6419 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6420 | } |
| 6421 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6422 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6423 | } |
| 6424 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6425 | TL.setTypeofLoc(ReadSourceLocation()); |
| 6426 | TL.setLParenLoc(ReadSourceLocation()); |
| 6427 | TL.setRParenLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6428 | } |
| 6429 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6430 | TL.setTypeofLoc(ReadSourceLocation()); |
| 6431 | TL.setLParenLoc(ReadSourceLocation()); |
| 6432 | TL.setRParenLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6433 | TL.setUnderlyingTInfo(GetTypeSourceInfo()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6434 | } |
| 6435 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6436 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6437 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6438 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6439 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6440 | TL.setKWLoc(ReadSourceLocation()); |
| 6441 | TL.setLParenLoc(ReadSourceLocation()); |
| 6442 | TL.setRParenLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6443 | TL.setUnderlyingTInfo(GetTypeSourceInfo()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6444 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6445 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6446 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6447 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6448 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6449 | |
Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 6450 | void TypeLocReader::VisitDeducedTemplateSpecializationTypeLoc( |
| 6451 | DeducedTemplateSpecializationTypeLoc TL) { |
| 6452 | TL.setTemplateNameLoc(ReadSourceLocation()); |
| 6453 | } |
| 6454 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6455 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6456 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6457 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6458 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6459 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6460 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6461 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6462 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6463 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6464 | TL.setAttrNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6465 | if (TL.hasAttrOperand()) { |
| 6466 | SourceRange range; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6467 | range.setBegin(ReadSourceLocation()); |
| 6468 | range.setEnd(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6469 | TL.setAttrOperandParensRange(range); |
| 6470 | } |
| 6471 | if (TL.hasAttrExprOperand()) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6472 | if (Record[Idx++]) |
| 6473 | TL.setAttrExprOperand(Reader->ReadExpr(*F)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6474 | else |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6475 | TL.setAttrExprOperand(nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6476 | } else if (TL.hasAttrEnumOperand()) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6477 | TL.setAttrEnumOperandLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6478 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6479 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6480 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6481 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6482 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6483 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6484 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 6485 | SubstTemplateTypeParmTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6486 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6487 | } |
| 6488 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 6489 | SubstTemplateTypeParmPackTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6490 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6491 | } |
| 6492 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 6493 | TemplateSpecializationTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6494 | TL.setTemplateKeywordLoc(ReadSourceLocation()); |
| 6495 | TL.setTemplateNameLoc(ReadSourceLocation()); |
| 6496 | TL.setLAngleLoc(ReadSourceLocation()); |
| 6497 | TL.setRAngleLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6498 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6499 | TL.setArgLocInfo( |
| 6500 | i, |
| 6501 | Reader->GetTemplateArgumentLocInfo( |
| 6502 | *F, TL.getTypePtr()->getArg(i).getKind(), Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6503 | } |
| 6504 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6505 | TL.setLParenLoc(ReadSourceLocation()); |
| 6506 | TL.setRParenLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6507 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6508 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6509 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6510 | TL.setElaboratedKeywordLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6511 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6512 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6513 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6514 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6515 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6516 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6517 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6518 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6519 | TL.setElaboratedKeywordLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6520 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6521 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6522 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6523 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6524 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 6525 | DependentTemplateSpecializationTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6526 | TL.setElaboratedKeywordLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6527 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6528 | TL.setTemplateKeywordLoc(ReadSourceLocation()); |
| 6529 | TL.setTemplateNameLoc(ReadSourceLocation()); |
| 6530 | TL.setLAngleLoc(ReadSourceLocation()); |
| 6531 | TL.setRAngleLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6532 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6533 | TL.setArgLocInfo( |
| 6534 | I, |
| 6535 | Reader->GetTemplateArgumentLocInfo( |
| 6536 | *F, TL.getTypePtr()->getArg(I).getKind(), Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6537 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6538 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6539 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6540 | TL.setEllipsisLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6541 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6542 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6543 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6544 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6545 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6546 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6547 | void TypeLocReader::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { |
| 6548 | if (TL.getNumProtocols()) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6549 | TL.setProtocolLAngleLoc(ReadSourceLocation()); |
| 6550 | TL.setProtocolRAngleLoc(ReadSourceLocation()); |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6551 | } |
| 6552 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6553 | TL.setProtocolLoc(i, ReadSourceLocation()); |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6554 | } |
| 6555 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6556 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6557 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6558 | TL.setTypeArgsLAngleLoc(ReadSourceLocation()); |
| 6559 | TL.setTypeArgsRAngleLoc(ReadSourceLocation()); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6560 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6561 | TL.setTypeArgTInfo(i, GetTypeSourceInfo()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6562 | TL.setProtocolLAngleLoc(ReadSourceLocation()); |
| 6563 | TL.setProtocolRAngleLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6564 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6565 | TL.setProtocolLoc(i, ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6566 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6567 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6568 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6569 | TL.setStarLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6570 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6571 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6572 | void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6573 | TL.setKWLoc(ReadSourceLocation()); |
| 6574 | TL.setLParenLoc(ReadSourceLocation()); |
| 6575 | TL.setRParenLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6576 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6577 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6578 | void TypeLocReader::VisitPipeTypeLoc(PipeTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6579 | TL.setKWLoc(ReadSourceLocation()); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6580 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6581 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6582 | TypeSourceInfo * |
| 6583 | ASTReader::GetTypeSourceInfo(ModuleFile &F, const ASTReader::RecordData &Record, |
| 6584 | unsigned &Idx) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6585 | QualType InfoTy = readType(F, Record, Idx); |
| 6586 | if (InfoTy.isNull()) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6587 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6588 | |
| 6589 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6590 | TypeLocReader TLR(F, *this, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6591 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
| 6592 | TLR.Visit(TL); |
| 6593 | return TInfo; |
| 6594 | } |
| 6595 | |
| 6596 | QualType ASTReader::GetType(TypeID ID) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 6597 | assert(ContextObj && "reading type with no AST context"); |
| 6598 | ASTContext &Context = *ContextObj; |
| 6599 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6600 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 6601 | unsigned Index = ID >> Qualifiers::FastWidth; |
| 6602 | |
| 6603 | if (Index < NUM_PREDEF_TYPE_IDS) { |
| 6604 | QualType T; |
| 6605 | switch ((PredefinedTypeIDs)Index) { |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6606 | case PREDEF_TYPE_NULL_ID: |
| 6607 | return QualType(); |
| 6608 | case PREDEF_TYPE_VOID_ID: |
| 6609 | T = Context.VoidTy; |
| 6610 | break; |
| 6611 | case PREDEF_TYPE_BOOL_ID: |
| 6612 | T = Context.BoolTy; |
| 6613 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6614 | |
| 6615 | case PREDEF_TYPE_CHAR_U_ID: |
| 6616 | case PREDEF_TYPE_CHAR_S_ID: |
| 6617 | // FIXME: Check that the signedness of CharTy is correct! |
| 6618 | T = Context.CharTy; |
| 6619 | break; |
| 6620 | |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6621 | case PREDEF_TYPE_UCHAR_ID: |
| 6622 | T = Context.UnsignedCharTy; |
| 6623 | break; |
| 6624 | case PREDEF_TYPE_USHORT_ID: |
| 6625 | T = Context.UnsignedShortTy; |
| 6626 | break; |
| 6627 | case PREDEF_TYPE_UINT_ID: |
| 6628 | T = Context.UnsignedIntTy; |
| 6629 | break; |
| 6630 | case PREDEF_TYPE_ULONG_ID: |
| 6631 | T = Context.UnsignedLongTy; |
| 6632 | break; |
| 6633 | case PREDEF_TYPE_ULONGLONG_ID: |
| 6634 | T = Context.UnsignedLongLongTy; |
| 6635 | break; |
| 6636 | case PREDEF_TYPE_UINT128_ID: |
| 6637 | T = Context.UnsignedInt128Ty; |
| 6638 | break; |
| 6639 | case PREDEF_TYPE_SCHAR_ID: |
| 6640 | T = Context.SignedCharTy; |
| 6641 | break; |
| 6642 | case PREDEF_TYPE_WCHAR_ID: |
| 6643 | T = Context.WCharTy; |
| 6644 | break; |
| 6645 | case PREDEF_TYPE_SHORT_ID: |
| 6646 | T = Context.ShortTy; |
| 6647 | break; |
| 6648 | case PREDEF_TYPE_INT_ID: |
| 6649 | T = Context.IntTy; |
| 6650 | break; |
| 6651 | case PREDEF_TYPE_LONG_ID: |
| 6652 | T = Context.LongTy; |
| 6653 | break; |
| 6654 | case PREDEF_TYPE_LONGLONG_ID: |
| 6655 | T = Context.LongLongTy; |
| 6656 | break; |
| 6657 | case PREDEF_TYPE_INT128_ID: |
| 6658 | T = Context.Int128Ty; |
| 6659 | break; |
| 6660 | case PREDEF_TYPE_HALF_ID: |
| 6661 | T = Context.HalfTy; |
| 6662 | break; |
| 6663 | case PREDEF_TYPE_FLOAT_ID: |
| 6664 | T = Context.FloatTy; |
| 6665 | break; |
| 6666 | case PREDEF_TYPE_DOUBLE_ID: |
| 6667 | T = Context.DoubleTy; |
| 6668 | break; |
| 6669 | case PREDEF_TYPE_LONGDOUBLE_ID: |
| 6670 | T = Context.LongDoubleTy; |
| 6671 | break; |
Nemanja Ivanovic | bb1ea2d | 2016-05-09 08:52:33 +0000 | [diff] [blame] | 6672 | case PREDEF_TYPE_FLOAT128_ID: |
| 6673 | T = Context.Float128Ty; |
| 6674 | break; |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6675 | case PREDEF_TYPE_OVERLOAD_ID: |
| 6676 | T = Context.OverloadTy; |
| 6677 | break; |
| 6678 | case PREDEF_TYPE_BOUND_MEMBER: |
| 6679 | T = Context.BoundMemberTy; |
| 6680 | break; |
| 6681 | case PREDEF_TYPE_PSEUDO_OBJECT: |
| 6682 | T = Context.PseudoObjectTy; |
| 6683 | break; |
| 6684 | case PREDEF_TYPE_DEPENDENT_ID: |
| 6685 | T = Context.DependentTy; |
| 6686 | break; |
| 6687 | case PREDEF_TYPE_UNKNOWN_ANY: |
| 6688 | T = Context.UnknownAnyTy; |
| 6689 | break; |
| 6690 | case PREDEF_TYPE_NULLPTR_ID: |
| 6691 | T = Context.NullPtrTy; |
| 6692 | break; |
| 6693 | case PREDEF_TYPE_CHAR16_ID: |
| 6694 | T = Context.Char16Ty; |
| 6695 | break; |
| 6696 | case PREDEF_TYPE_CHAR32_ID: |
| 6697 | T = Context.Char32Ty; |
| 6698 | break; |
| 6699 | case PREDEF_TYPE_OBJC_ID: |
| 6700 | T = Context.ObjCBuiltinIdTy; |
| 6701 | break; |
| 6702 | case PREDEF_TYPE_OBJC_CLASS: |
| 6703 | T = Context.ObjCBuiltinClassTy; |
| 6704 | break; |
| 6705 | case PREDEF_TYPE_OBJC_SEL: |
| 6706 | T = Context.ObjCBuiltinSelTy; |
| 6707 | break; |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 6708 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 6709 | case PREDEF_TYPE_##Id##_ID: \ |
| 6710 | T = Context.SingletonId; \ |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6711 | break; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 6712 | #include "clang/Basic/OpenCLImageTypes.def" |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6713 | case PREDEF_TYPE_SAMPLER_ID: |
| 6714 | T = Context.OCLSamplerTy; |
| 6715 | break; |
| 6716 | case PREDEF_TYPE_EVENT_ID: |
| 6717 | T = Context.OCLEventTy; |
| 6718 | break; |
Alexey Bader | 9c8453f | 2015-09-15 11:18:52 +0000 | [diff] [blame] | 6719 | case PREDEF_TYPE_CLK_EVENT_ID: |
| 6720 | T = Context.OCLClkEventTy; |
| 6721 | break; |
| 6722 | case PREDEF_TYPE_QUEUE_ID: |
| 6723 | T = Context.OCLQueueTy; |
| 6724 | break; |
Alexey Bader | 9c8453f | 2015-09-15 11:18:52 +0000 | [diff] [blame] | 6725 | case PREDEF_TYPE_RESERVE_ID_ID: |
| 6726 | T = Context.OCLReserveIDTy; |
| 6727 | break; |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6728 | case PREDEF_TYPE_AUTO_DEDUCT: |
| 6729 | T = Context.getAutoDeductType(); |
| 6730 | break; |
| 6731 | |
| 6732 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
| 6733 | T = Context.getAutoRRefDeductType(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6734 | break; |
| 6735 | |
| 6736 | case PREDEF_TYPE_ARC_UNBRIDGED_CAST: |
| 6737 | T = Context.ARCUnbridgedCastTy; |
| 6738 | break; |
| 6739 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6740 | case PREDEF_TYPE_BUILTIN_FN: |
| 6741 | T = Context.BuiltinFnTy; |
| 6742 | break; |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 6743 | |
| 6744 | case PREDEF_TYPE_OMP_ARRAY_SECTION: |
| 6745 | T = Context.OMPArraySectionTy; |
| 6746 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6747 | } |
| 6748 | |
| 6749 | assert(!T.isNull() && "Unknown predefined type"); |
| 6750 | return T.withFastQualifiers(FastQuals); |
| 6751 | } |
| 6752 | |
| 6753 | Index -= NUM_PREDEF_TYPE_IDS; |
| 6754 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
| 6755 | if (TypesLoaded[Index].isNull()) { |
| 6756 | TypesLoaded[Index] = readTypeRecord(Index); |
| 6757 | if (TypesLoaded[Index].isNull()) |
| 6758 | return QualType(); |
| 6759 | |
| 6760 | TypesLoaded[Index]->setFromAST(); |
| 6761 | if (DeserializationListener) |
| 6762 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
| 6763 | TypesLoaded[Index]); |
| 6764 | } |
| 6765 | |
| 6766 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
| 6767 | } |
| 6768 | |
| 6769 | QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) { |
| 6770 | return GetType(getGlobalTypeID(F, LocalID)); |
| 6771 | } |
| 6772 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6773 | serialization::TypeID |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6774 | ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const { |
| 6775 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 6776 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6777 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6778 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 6779 | return LocalID; |
| 6780 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 6781 | if (!F.ModuleOffsetMap.empty()) |
| 6782 | ReadModuleOffsetMap(F); |
| 6783 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6784 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6785 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 6786 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6787 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6788 | unsigned GlobalIndex = LocalIndex + I->second; |
| 6789 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 6790 | } |
| 6791 | |
| 6792 | TemplateArgumentLocInfo |
| 6793 | ASTReader::GetTemplateArgumentLocInfo(ModuleFile &F, |
| 6794 | TemplateArgument::ArgKind Kind, |
| 6795 | const RecordData &Record, |
| 6796 | unsigned &Index) { |
| 6797 | switch (Kind) { |
| 6798 | case TemplateArgument::Expression: |
| 6799 | return ReadExpr(F); |
| 6800 | case TemplateArgument::Type: |
| 6801 | return GetTypeSourceInfo(F, Record, Index); |
| 6802 | case TemplateArgument::Template: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6803 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6804 | Index); |
| 6805 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
| 6806 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
| 6807 | SourceLocation()); |
| 6808 | } |
| 6809 | case TemplateArgument::TemplateExpansion: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6810 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6811 | Index); |
| 6812 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
| 6813 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6814 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6815 | EllipsisLoc); |
| 6816 | } |
| 6817 | case TemplateArgument::Null: |
| 6818 | case TemplateArgument::Integral: |
| 6819 | case TemplateArgument::Declaration: |
| 6820 | case TemplateArgument::NullPtr: |
| 6821 | case TemplateArgument::Pack: |
| 6822 | // FIXME: Is this right? |
| 6823 | return TemplateArgumentLocInfo(); |
| 6824 | } |
| 6825 | llvm_unreachable("unexpected template argument loc"); |
| 6826 | } |
| 6827 | |
| 6828 | TemplateArgumentLoc |
| 6829 | ASTReader::ReadTemplateArgumentLoc(ModuleFile &F, |
| 6830 | const RecordData &Record, unsigned &Index) { |
| 6831 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
| 6832 | |
| 6833 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 6834 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 6835 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 6836 | } |
| 6837 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
| 6838 | Record, Index)); |
| 6839 | } |
| 6840 | |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 6841 | const ASTTemplateArgumentListInfo* |
| 6842 | ASTReader::ReadASTTemplateArgumentListInfo(ModuleFile &F, |
| 6843 | const RecordData &Record, |
| 6844 | unsigned &Index) { |
| 6845 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Index); |
| 6846 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Index); |
| 6847 | unsigned NumArgsAsWritten = Record[Index++]; |
| 6848 | TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); |
| 6849 | for (unsigned i = 0; i != NumArgsAsWritten; ++i) |
| 6850 | TemplArgsInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Index)); |
| 6851 | return ASTTemplateArgumentListInfo::Create(getContext(), TemplArgsInfo); |
| 6852 | } |
| 6853 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6854 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
| 6855 | return GetDecl(ID); |
| 6856 | } |
| 6857 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6858 | void ASTReader::CompleteRedeclChain(const Decl *D) { |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 6859 | if (NumCurrentElementsDeserializing) { |
| 6860 | // We arrange to not care about the complete redeclaration chain while we're |
| 6861 | // deserializing. Just remember that the AST has marked this one as complete |
| 6862 | // but that it's not actually complete yet, so we know we still need to |
| 6863 | // complete it later. |
| 6864 | PendingIncompleteDeclChains.push_back(const_cast<Decl*>(D)); |
| 6865 | return; |
| 6866 | } |
| 6867 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6868 | const DeclContext *DC = D->getDeclContext()->getRedeclContext(); |
| 6869 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6870 | // If this is a named declaration, complete it by looking it up |
| 6871 | // within its context. |
| 6872 | // |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 6873 | // FIXME: Merging a function definition should merge |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6874 | // all mergeable entities within it. |
| 6875 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC) || |
| 6876 | isa<CXXRecordDecl>(DC) || isa<EnumDecl>(DC)) { |
| 6877 | if (DeclarationName Name = cast<NamedDecl>(D)->getDeclName()) { |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 6878 | if (!getContext().getLangOpts().CPlusPlus && |
| 6879 | isa<TranslationUnitDecl>(DC)) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6880 | // 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] | 6881 | // the identifier instead. (For C++ modules, we don't store decls |
| 6882 | // in the serialized identifier table, so we do the lookup in the TU.) |
| 6883 | auto *II = Name.getAsIdentifierInfo(); |
| 6884 | assert(II && "non-identifier name in C?"); |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6885 | if (II->isOutOfDate()) |
| 6886 | updateOutOfDateIdentifier(*II); |
| 6887 | } else |
| 6888 | DC->lookup(Name); |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 6889 | } else if (needsAnonymousDeclarationNumber(cast<NamedDecl>(D))) { |
Richard Smith | 3cb1572 | 2015-08-05 22:41:45 +0000 | [diff] [blame] | 6890 | // Find all declarations of this kind from the relevant context. |
| 6891 | for (auto *DCDecl : cast<Decl>(D->getLexicalDeclContext())->redecls()) { |
| 6892 | auto *DC = cast<DeclContext>(DCDecl); |
| 6893 | SmallVector<Decl*, 8> Decls; |
| 6894 | FindExternalLexicalDecls( |
| 6895 | DC, [&](Decl::Kind K) { return K == D->getKind(); }, Decls); |
| 6896 | } |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6897 | } |
| 6898 | } |
Richard Smith | 5089542 | 2015-01-31 03:04:55 +0000 | [diff] [blame] | 6899 | |
| 6900 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D)) |
| 6901 | CTSD->getSpecializedTemplate()->LoadLazySpecializations(); |
| 6902 | if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) |
| 6903 | VTSD->getSpecializedTemplate()->LoadLazySpecializations(); |
| 6904 | if (auto *FD = dyn_cast<FunctionDecl>(D)) { |
| 6905 | if (auto *Template = FD->getPrimaryTemplate()) |
| 6906 | Template->LoadLazySpecializations(); |
| 6907 | } |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6908 | } |
| 6909 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 6910 | CXXCtorInitializer ** |
| 6911 | ASTReader::GetExternalCXXCtorInitializers(uint64_t Offset) { |
| 6912 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 6913 | BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
| 6914 | SavedStreamPosition SavedPosition(Cursor); |
| 6915 | Cursor.JumpToBit(Loc.Offset); |
| 6916 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 6917 | |
| 6918 | RecordData Record; |
| 6919 | unsigned Code = Cursor.ReadCode(); |
| 6920 | unsigned RecCode = Cursor.readRecord(Code, Record); |
| 6921 | if (RecCode != DECL_CXX_CTOR_INITIALIZERS) { |
| 6922 | Error("malformed AST file: missing C++ ctor initializers"); |
| 6923 | return nullptr; |
| 6924 | } |
| 6925 | |
| 6926 | unsigned Idx = 0; |
| 6927 | return ReadCXXCtorInitializers(*Loc.F, Record, Idx); |
| 6928 | } |
| 6929 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6930 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 6931 | assert(ContextObj && "reading base specifiers with no AST context"); |
| 6932 | ASTContext &Context = *ContextObj; |
| 6933 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6934 | RecordLocation Loc = getLocalBitOffset(Offset); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 6935 | BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6936 | SavedStreamPosition SavedPosition(Cursor); |
| 6937 | Cursor.JumpToBit(Loc.Offset); |
| 6938 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 6939 | RecordData Record; |
| 6940 | unsigned Code = Cursor.ReadCode(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 6941 | unsigned RecCode = Cursor.readRecord(Code, Record); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6942 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6943 | Error("malformed AST file: missing C++ base specifiers"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6944 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6945 | } |
| 6946 | |
| 6947 | unsigned Idx = 0; |
| 6948 | unsigned NumBases = Record[Idx++]; |
| 6949 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 6950 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 6951 | for (unsigned I = 0; I != NumBases; ++I) |
| 6952 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
| 6953 | return Bases; |
| 6954 | } |
| 6955 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6956 | serialization::DeclID |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6957 | ASTReader::getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const { |
| 6958 | if (LocalID < NUM_PREDEF_DECL_IDS) |
| 6959 | return LocalID; |
| 6960 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 6961 | if (!F.ModuleOffsetMap.empty()) |
| 6962 | ReadModuleOffsetMap(F); |
| 6963 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6964 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6965 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
| 6966 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6967 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6968 | return LocalID + I->second; |
| 6969 | } |
| 6970 | |
| 6971 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
| 6972 | ModuleFile &M) const { |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 6973 | // Predefined decls aren't from any module. |
| 6974 | if (ID < NUM_PREDEF_DECL_IDS) |
| 6975 | return false; |
| 6976 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6977 | return ID - NUM_PREDEF_DECL_IDS >= M.BaseDeclID && |
Richard Smith | bcda1a9 | 2015-07-12 23:51:20 +0000 | [diff] [blame] | 6978 | ID - NUM_PREDEF_DECL_IDS < M.BaseDeclID + M.LocalNumDecls; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6979 | } |
| 6980 | |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 6981 | ModuleFile *ASTReader::getOwningModuleFile(const Decl *D) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6982 | if (!D->isFromASTFile()) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6983 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6984 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID()); |
| 6985 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 6986 | return I->second; |
| 6987 | } |
| 6988 | |
| 6989 | SourceLocation ASTReader::getSourceLocationForDeclID(GlobalDeclID ID) { |
| 6990 | if (ID < NUM_PREDEF_DECL_IDS) |
| 6991 | return SourceLocation(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6992 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6993 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 6994 | |
| 6995 | if (Index > DeclsLoaded.size()) { |
| 6996 | Error("declaration ID out-of-range for AST file"); |
| 6997 | return SourceLocation(); |
| 6998 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 6999 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7000 | if (Decl *D = DeclsLoaded[Index]) |
| 7001 | return D->getLocation(); |
| 7002 | |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 7003 | SourceLocation Loc; |
| 7004 | DeclCursorForID(ID, Loc); |
| 7005 | return Loc; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7006 | } |
| 7007 | |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7008 | static Decl *getPredefinedDecl(ASTContext &Context, PredefinedDeclIDs ID) { |
| 7009 | switch (ID) { |
| 7010 | case PREDEF_DECL_NULL_ID: |
| 7011 | return nullptr; |
| 7012 | |
| 7013 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
| 7014 | return Context.getTranslationUnitDecl(); |
| 7015 | |
| 7016 | case PREDEF_DECL_OBJC_ID_ID: |
| 7017 | return Context.getObjCIdDecl(); |
| 7018 | |
| 7019 | case PREDEF_DECL_OBJC_SEL_ID: |
| 7020 | return Context.getObjCSelDecl(); |
| 7021 | |
| 7022 | case PREDEF_DECL_OBJC_CLASS_ID: |
| 7023 | return Context.getObjCClassDecl(); |
| 7024 | |
| 7025 | case PREDEF_DECL_OBJC_PROTOCOL_ID: |
| 7026 | return Context.getObjCProtocolDecl(); |
| 7027 | |
| 7028 | case PREDEF_DECL_INT_128_ID: |
| 7029 | return Context.getInt128Decl(); |
| 7030 | |
| 7031 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
| 7032 | return Context.getUInt128Decl(); |
| 7033 | |
| 7034 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
| 7035 | return Context.getObjCInstanceTypeDecl(); |
| 7036 | |
| 7037 | case PREDEF_DECL_BUILTIN_VA_LIST_ID: |
| 7038 | return Context.getBuiltinVaListDecl(); |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 7039 | |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 7040 | case PREDEF_DECL_VA_LIST_TAG: |
| 7041 | return Context.getVaListTagDecl(); |
| 7042 | |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 7043 | case PREDEF_DECL_BUILTIN_MS_VA_LIST_ID: |
| 7044 | return Context.getBuiltinMSVaListDecl(); |
| 7045 | |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 7046 | case PREDEF_DECL_EXTERN_C_CONTEXT_ID: |
| 7047 | return Context.getExternCContextDecl(); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 7048 | |
| 7049 | case PREDEF_DECL_MAKE_INTEGER_SEQ_ID: |
| 7050 | return Context.getMakeIntegerSeqDecl(); |
Quentin Colombet | 043406b | 2016-02-03 22:41:00 +0000 | [diff] [blame] | 7051 | |
| 7052 | case PREDEF_DECL_CF_CONSTANT_STRING_ID: |
| 7053 | return Context.getCFConstantStringDecl(); |
Ben Langmuir | f541674 | 2016-02-04 00:55:24 +0000 | [diff] [blame] | 7054 | |
| 7055 | case PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID: |
| 7056 | return Context.getCFConstantStringTagDecl(); |
Eric Fiselier | 6ad6855 | 2016-07-01 01:24:09 +0000 | [diff] [blame] | 7057 | |
| 7058 | case PREDEF_DECL_TYPE_PACK_ELEMENT_ID: |
| 7059 | return Context.getTypePackElementDecl(); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7060 | } |
Yaron Keren | 322bdad | 2015-03-06 07:49:14 +0000 | [diff] [blame] | 7061 | llvm_unreachable("PredefinedDeclIDs unknown enum value"); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7062 | } |
| 7063 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7064 | Decl *ASTReader::GetExistingDecl(DeclID ID) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 7065 | assert(ContextObj && "reading decl with no AST context"); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7066 | if (ID < NUM_PREDEF_DECL_IDS) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 7067 | Decl *D = getPredefinedDecl(*ContextObj, (PredefinedDeclIDs)ID); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7068 | if (D) { |
| 7069 | // Track that we have merged the declaration with ID \p ID into the |
| 7070 | // pre-existing predefined declaration \p D. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 7071 | auto &Merged = KeyDecls[D->getCanonicalDecl()]; |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7072 | if (Merged.empty()) |
| 7073 | Merged.push_back(ID); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7074 | } |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7075 | return D; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7076 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7077 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7078 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 7079 | |
| 7080 | if (Index >= DeclsLoaded.size()) { |
| 7081 | assert(0 && "declaration ID out-of-range for AST file"); |
| 7082 | Error("declaration ID out-of-range for AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7083 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7084 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7085 | |
| 7086 | return DeclsLoaded[Index]; |
| 7087 | } |
| 7088 | |
| 7089 | Decl *ASTReader::GetDecl(DeclID ID) { |
| 7090 | if (ID < NUM_PREDEF_DECL_IDS) |
| 7091 | return GetExistingDecl(ID); |
| 7092 | |
| 7093 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 7094 | |
| 7095 | if (Index >= DeclsLoaded.size()) { |
| 7096 | assert(0 && "declaration ID out-of-range for AST file"); |
| 7097 | Error("declaration ID out-of-range for AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7098 | return nullptr; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7099 | } |
| 7100 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7101 | if (!DeclsLoaded[Index]) { |
| 7102 | ReadDeclRecord(ID); |
| 7103 | if (DeserializationListener) |
| 7104 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 7105 | } |
| 7106 | |
| 7107 | return DeclsLoaded[Index]; |
| 7108 | } |
| 7109 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7110 | DeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile &M, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7111 | DeclID GlobalID) { |
| 7112 | if (GlobalID < NUM_PREDEF_DECL_IDS) |
| 7113 | return GlobalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7114 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7115 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID); |
| 7116 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 7117 | ModuleFile *Owner = I->second; |
| 7118 | |
| 7119 | llvm::DenseMap<ModuleFile *, serialization::DeclID>::iterator Pos |
| 7120 | = M.GlobalToLocalDeclIDs.find(Owner); |
| 7121 | if (Pos == M.GlobalToLocalDeclIDs.end()) |
| 7122 | return 0; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7123 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7124 | return GlobalID - Owner->BaseDeclID + Pos->second; |
| 7125 | } |
| 7126 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7127 | serialization::DeclID ASTReader::ReadDeclID(ModuleFile &F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7128 | const RecordData &Record, |
| 7129 | unsigned &Idx) { |
| 7130 | if (Idx >= Record.size()) { |
| 7131 | Error("Corrupted AST file"); |
| 7132 | return 0; |
| 7133 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7134 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7135 | return getGlobalDeclID(F, Record[Idx++]); |
| 7136 | } |
| 7137 | |
| 7138 | /// \brief Resolve the offset of a statement into a statement. |
| 7139 | /// |
| 7140 | /// This operation will read a new statement from the external |
| 7141 | /// source each time it is called, and is meant to be used via a |
| 7142 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
| 7143 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
| 7144 | // Switch case IDs are per Decl. |
| 7145 | ClearSwitchCaseIDs(); |
| 7146 | |
| 7147 | // Offset here is a global offset across the entire chain. |
| 7148 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 7149 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
David Blaikie | 9fd16f8 | 2017-03-08 23:57:08 +0000 | [diff] [blame] | 7150 | assert(NumCurrentElementsDeserializing == 0 && |
| 7151 | "should not be called while already deserializing"); |
| 7152 | Deserializing D(this); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7153 | return ReadStmtFromStream(*Loc.F); |
| 7154 | } |
| 7155 | |
Richard Smith | 3cb1572 | 2015-08-05 22:41:45 +0000 | [diff] [blame] | 7156 | void ASTReader::FindExternalLexicalDecls( |
| 7157 | const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, |
| 7158 | SmallVectorImpl<Decl *> &Decls) { |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7159 | bool PredefsVisited[NUM_PREDEF_DECL_IDS] = {}; |
| 7160 | |
Richard Smith | 9ccdd93 | 2015-08-06 22:14:12 +0000 | [diff] [blame] | 7161 | auto Visit = [&] (ModuleFile *M, LexicalContents LexicalDecls) { |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7162 | assert(LexicalDecls.size() % 2 == 0 && "expected an even number of entries"); |
| 7163 | for (int I = 0, N = LexicalDecls.size(); I != N; I += 2) { |
| 7164 | auto K = (Decl::Kind)+LexicalDecls[I]; |
| 7165 | if (!IsKindWeWant(K)) |
| 7166 | continue; |
| 7167 | |
| 7168 | auto ID = (serialization::DeclID)+LexicalDecls[I + 1]; |
| 7169 | |
| 7170 | // Don't add predefined declarations to the lexical context more |
| 7171 | // than once. |
| 7172 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 7173 | if (PredefsVisited[ID]) |
| 7174 | continue; |
| 7175 | |
| 7176 | PredefsVisited[ID] = true; |
| 7177 | } |
| 7178 | |
| 7179 | if (Decl *D = GetLocalDecl(*M, ID)) { |
Richard Smith | 2317a3e | 2015-08-11 21:21:20 +0000 | [diff] [blame] | 7180 | assert(D->getKind() == K && "wrong kind for lexical decl"); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7181 | if (!DC->isDeclInLexicalTraversal(D)) |
| 7182 | Decls.push_back(D); |
| 7183 | } |
| 7184 | } |
| 7185 | }; |
| 7186 | |
| 7187 | if (isa<TranslationUnitDecl>(DC)) { |
| 7188 | for (auto Lexical : TULexicalDecls) |
| 7189 | Visit(Lexical.first, Lexical.second); |
| 7190 | } else { |
| 7191 | auto I = LexicalDecls.find(DC); |
| 7192 | if (I != LexicalDecls.end()) |
Richard Smith | 9c9173d | 2015-08-11 22:00:24 +0000 | [diff] [blame] | 7193 | Visit(I->second.first, I->second.second); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7194 | } |
| 7195 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7196 | ++NumLexicalDeclContextsRead; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7197 | } |
| 7198 | |
| 7199 | namespace { |
| 7200 | |
| 7201 | class DeclIDComp { |
| 7202 | ASTReader &Reader; |
| 7203 | ModuleFile &Mod; |
| 7204 | |
| 7205 | public: |
| 7206 | DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {} |
| 7207 | |
| 7208 | bool operator()(LocalDeclID L, LocalDeclID R) const { |
| 7209 | SourceLocation LHS = getLocation(L); |
| 7210 | SourceLocation RHS = getLocation(R); |
| 7211 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7212 | } |
| 7213 | |
| 7214 | bool operator()(SourceLocation LHS, LocalDeclID R) const { |
| 7215 | SourceLocation RHS = getLocation(R); |
| 7216 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7217 | } |
| 7218 | |
| 7219 | bool operator()(LocalDeclID L, SourceLocation RHS) const { |
| 7220 | SourceLocation LHS = getLocation(L); |
| 7221 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7222 | } |
| 7223 | |
| 7224 | SourceLocation getLocation(LocalDeclID ID) const { |
| 7225 | return Reader.getSourceManager().getFileLoc( |
| 7226 | Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID))); |
| 7227 | } |
| 7228 | }; |
| 7229 | |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7230 | } // end anonymous namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7231 | |
| 7232 | void ASTReader::FindFileRegionDecls(FileID File, |
| 7233 | unsigned Offset, unsigned Length, |
| 7234 | SmallVectorImpl<Decl *> &Decls) { |
| 7235 | SourceManager &SM = getSourceManager(); |
| 7236 | |
| 7237 | llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File); |
| 7238 | if (I == FileDeclIDs.end()) |
| 7239 | return; |
| 7240 | |
| 7241 | FileDeclsInfo &DInfo = I->second; |
| 7242 | if (DInfo.Decls.empty()) |
| 7243 | return; |
| 7244 | |
| 7245 | SourceLocation |
| 7246 | BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset); |
| 7247 | SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length); |
| 7248 | |
| 7249 | DeclIDComp DIDComp(*this, *DInfo.Mod); |
| 7250 | ArrayRef<serialization::LocalDeclID>::iterator |
| 7251 | BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 7252 | BeginLoc, DIDComp); |
| 7253 | if (BeginIt != DInfo.Decls.begin()) |
| 7254 | --BeginIt; |
| 7255 | |
| 7256 | // If we are pointing at a top-level decl inside an objc container, we need |
| 7257 | // to backtrack until we find it otherwise we will fail to report that the |
| 7258 | // region overlaps with an objc container. |
| 7259 | while (BeginIt != DInfo.Decls.begin() && |
| 7260 | GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt)) |
| 7261 | ->isTopLevelDeclInObjCContainer()) |
| 7262 | --BeginIt; |
| 7263 | |
| 7264 | ArrayRef<serialization::LocalDeclID>::iterator |
| 7265 | EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 7266 | EndLoc, DIDComp); |
| 7267 | if (EndIt != DInfo.Decls.end()) |
| 7268 | ++EndIt; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7269 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7270 | for (ArrayRef<serialization::LocalDeclID>::iterator |
| 7271 | DIt = BeginIt; DIt != EndIt; ++DIt) |
| 7272 | Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt))); |
| 7273 | } |
| 7274 | |
Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 7275 | bool |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7276 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
| 7277 | DeclarationName Name) { |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7278 | assert(DC->hasExternalVisibleStorage() && DC == DC->getPrimaryContext() && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7279 | "DeclContext has no visible decls in storage"); |
| 7280 | if (!Name) |
Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 7281 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7282 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7283 | auto It = Lookups.find(DC); |
| 7284 | if (It == Lookups.end()) |
| 7285 | return false; |
| 7286 | |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 7287 | Deserializing LookupResults(this); |
| 7288 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7289 | // Load the list of declarations. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7290 | SmallVector<NamedDecl *, 64> Decls; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7291 | for (DeclID ID : It->second.Table.find(Name)) { |
| 7292 | NamedDecl *ND = cast<NamedDecl>(GetDecl(ID)); |
| 7293 | if (ND->getDeclName() == Name) |
| 7294 | Decls.push_back(ND); |
| 7295 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7296 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7297 | ++NumVisibleDeclContextsRead; |
| 7298 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 7299 | return !Decls.empty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7300 | } |
| 7301 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7302 | void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) { |
| 7303 | if (!DC->hasExternalVisibleStorage()) |
| 7304 | return; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7305 | |
| 7306 | auto It = Lookups.find(DC); |
| 7307 | assert(It != Lookups.end() && |
| 7308 | "have external visible storage but no lookup tables"); |
| 7309 | |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 7310 | DeclsMap Decls; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7311 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7312 | for (DeclID ID : It->second.Table.findAll()) { |
| 7313 | NamedDecl *ND = cast<NamedDecl>(GetDecl(ID)); |
| 7314 | Decls[ND->getDeclName()].push_back(ND); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7315 | } |
| 7316 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7317 | ++NumVisibleDeclContextsRead; |
| 7318 | |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 7319 | for (DeclsMap::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7320 | SetExternalVisibleDeclsForName(DC, I->first, I->second); |
| 7321 | } |
| 7322 | const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false); |
| 7323 | } |
| 7324 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7325 | const serialization::reader::DeclContextLookupTable * |
| 7326 | ASTReader::getLoadedLookupTables(DeclContext *Primary) const { |
| 7327 | auto I = Lookups.find(Primary); |
| 7328 | return I == Lookups.end() ? nullptr : &I->second; |
| 7329 | } |
| 7330 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7331 | /// \brief Under non-PCH compilation the consumer receives the objc methods |
| 7332 | /// before receiving the implementation, and codegen depends on this. |
| 7333 | /// We simulate this by deserializing and passing to consumer the methods of the |
| 7334 | /// implementation before passing the deserialized implementation decl. |
| 7335 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 7336 | ASTConsumer *Consumer) { |
| 7337 | assert(ImplD && Consumer); |
| 7338 | |
Aaron Ballman | aff18c0 | 2014-03-13 19:03:34 +0000 | [diff] [blame] | 7339 | for (auto *I : ImplD->methods()) |
| 7340 | Consumer->HandleInterestingDecl(DeclGroupRef(I)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7341 | |
| 7342 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 7343 | } |
| 7344 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7345 | void ASTReader::PassInterestingDeclToConsumer(Decl *D) { |
| 7346 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 7347 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 7348 | else |
| 7349 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
| 7350 | } |
| 7351 | |
| 7352 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
| 7353 | this->Consumer = Consumer; |
| 7354 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 7355 | if (Consumer) |
| 7356 | PassInterestingDeclsToConsumer(); |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 7357 | |
| 7358 | if (DeserializationListener) |
| 7359 | DeserializationListener->ReaderInitialized(this); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7360 | } |
| 7361 | |
| 7362 | void ASTReader::PrintStats() { |
| 7363 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
| 7364 | |
| 7365 | unsigned NumTypesLoaded |
| 7366 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
| 7367 | QualType()); |
| 7368 | unsigned NumDeclsLoaded |
| 7369 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7370 | (Decl *)nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7371 | unsigned NumIdentifiersLoaded |
| 7372 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 7373 | IdentifiersLoaded.end(), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7374 | (IdentifierInfo *)nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7375 | unsigned NumMacrosLoaded |
| 7376 | = MacrosLoaded.size() - std::count(MacrosLoaded.begin(), |
| 7377 | MacrosLoaded.end(), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7378 | (MacroInfo *)nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7379 | unsigned NumSelectorsLoaded |
| 7380 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 7381 | SelectorsLoaded.end(), |
| 7382 | Selector()); |
| 7383 | |
| 7384 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
| 7385 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 7386 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 7387 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
| 7388 | if (!TypesLoaded.empty()) |
| 7389 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
| 7390 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 7391 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 7392 | if (!DeclsLoaded.empty()) |
| 7393 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
| 7394 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 7395 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
| 7396 | if (!IdentifiersLoaded.empty()) |
| 7397 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
| 7398 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 7399 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
| 7400 | if (!MacrosLoaded.empty()) |
| 7401 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 7402 | NumMacrosLoaded, (unsigned)MacrosLoaded.size(), |
| 7403 | ((float)NumMacrosLoaded/MacrosLoaded.size() * 100)); |
| 7404 | if (!SelectorsLoaded.empty()) |
| 7405 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
| 7406 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 7407 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
| 7408 | if (TotalNumStatements) |
| 7409 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 7410 | NumStatementsRead, TotalNumStatements, |
| 7411 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 7412 | if (TotalNumMacros) |
| 7413 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 7414 | NumMacrosRead, TotalNumMacros, |
| 7415 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 7416 | if (TotalLexicalDeclContexts) |
| 7417 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 7418 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 7419 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 7420 | * 100)); |
| 7421 | if (TotalVisibleDeclContexts) |
| 7422 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 7423 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 7424 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 7425 | * 100)); |
| 7426 | if (TotalNumMethodPoolEntries) { |
| 7427 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
| 7428 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 7429 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
| 7430 | * 100)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7431 | } |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7432 | if (NumMethodPoolLookups) { |
| 7433 | std::fprintf(stderr, " %u/%u method pool lookups succeeded (%f%%)\n", |
| 7434 | NumMethodPoolHits, NumMethodPoolLookups, |
| 7435 | ((float)NumMethodPoolHits/NumMethodPoolLookups * 100.0)); |
| 7436 | } |
| 7437 | if (NumMethodPoolTableLookups) { |
| 7438 | std::fprintf(stderr, " %u/%u method pool table lookups succeeded (%f%%)\n", |
| 7439 | NumMethodPoolTableHits, NumMethodPoolTableLookups, |
| 7440 | ((float)NumMethodPoolTableHits/NumMethodPoolTableLookups |
| 7441 | * 100.0)); |
| 7442 | } |
| 7443 | |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 7444 | if (NumIdentifierLookupHits) { |
| 7445 | std::fprintf(stderr, |
| 7446 | " %u / %u identifier table lookups succeeded (%f%%)\n", |
| 7447 | NumIdentifierLookupHits, NumIdentifierLookups, |
| 7448 | (double)NumIdentifierLookupHits*100.0/NumIdentifierLookups); |
| 7449 | } |
| 7450 | |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 7451 | if (GlobalIndex) { |
| 7452 | std::fprintf(stderr, "\n"); |
| 7453 | GlobalIndex->printStats(); |
| 7454 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7455 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7456 | std::fprintf(stderr, "\n"); |
| 7457 | dump(); |
| 7458 | std::fprintf(stderr, "\n"); |
| 7459 | } |
| 7460 | |
| 7461 | template<typename Key, typename ModuleFile, unsigned InitialCapacity> |
Vassil Vassilev | b271068 | 2017-03-02 18:13:19 +0000 | [diff] [blame] | 7462 | LLVM_DUMP_METHOD static void |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7463 | dumpModuleIDMap(StringRef Name, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7464 | const ContinuousRangeMap<Key, ModuleFile *, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7465 | InitialCapacity> &Map) { |
| 7466 | if (Map.begin() == Map.end()) |
| 7467 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7468 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7469 | typedef ContinuousRangeMap<Key, ModuleFile *, InitialCapacity> MapType; |
| 7470 | llvm::errs() << Name << ":\n"; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7471 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7472 | I != IEnd; ++I) { |
| 7473 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 7474 | << "\n"; |
| 7475 | } |
| 7476 | } |
| 7477 | |
Yaron Keren | cdae941 | 2016-01-29 19:38:18 +0000 | [diff] [blame] | 7478 | LLVM_DUMP_METHOD void ASTReader::dump() { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7479 | llvm::errs() << "*** PCH/ModuleFile Remappings:\n"; |
| 7480 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
| 7481 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
| 7482 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
| 7483 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
| 7484 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
| 7485 | dumpModuleIDMap("Global macro map", GlobalMacroMap); |
| 7486 | dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap); |
| 7487 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7488 | dumpModuleIDMap("Global preprocessed entity map", |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7489 | GlobalPreprocessedEntityMap); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7490 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7491 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 7492 | for (ModuleFile &M : ModuleMgr) |
| 7493 | M.dump(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7494 | } |
| 7495 | |
| 7496 | /// Return the amount of memory used by memory buffers, breaking down |
| 7497 | /// by heap-backed versus mmap'ed memory. |
| 7498 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 7499 | for (ModuleFile &I : ModuleMgr) { |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 7500 | if (llvm::MemoryBuffer *buf = I.Buffer) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7501 | size_t bytes = buf->getBufferSize(); |
| 7502 | switch (buf->getBufferKind()) { |
| 7503 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 7504 | sizes.malloc_bytes += bytes; |
| 7505 | break; |
| 7506 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 7507 | sizes.mmap_bytes += bytes; |
| 7508 | break; |
| 7509 | } |
| 7510 | } |
| 7511 | } |
| 7512 | } |
| 7513 | |
| 7514 | void ASTReader::InitializeSema(Sema &S) { |
| 7515 | SemaObj = &S; |
| 7516 | S.addExternalSource(this); |
| 7517 | |
| 7518 | // Makes sure any declarations that were deserialized "too early" |
| 7519 | // still get added to the identifier's declaration chains. |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7520 | for (uint64_t ID : PreloadedDeclIDs) { |
| 7521 | NamedDecl *D = cast<NamedDecl>(GetDecl(ID)); |
| 7522 | pushExternalDeclIntoScope(D, D->getDeclName()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7523 | } |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7524 | PreloadedDeclIDs.clear(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7525 | |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7526 | // FIXME: What happens if these are changed by a module import? |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7527 | if (!FPPragmaOptions.empty()) { |
| 7528 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 7529 | SemaObj->FPFeatures = FPOptions(FPPragmaOptions[0]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7530 | } |
| 7531 | |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 7532 | SemaObj->OpenCLFeatures.copy(OpenCLExtensions); |
| 7533 | SemaObj->OpenCLTypeExtMap = OpenCLTypeExtMap; |
| 7534 | SemaObj->OpenCLDeclExtMap = OpenCLDeclExtMap; |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7535 | |
| 7536 | UpdateSema(); |
| 7537 | } |
| 7538 | |
| 7539 | void ASTReader::UpdateSema() { |
| 7540 | assert(SemaObj && "no Sema to update"); |
| 7541 | |
| 7542 | // Load the offsets of the declarations that Sema references. |
| 7543 | // They will be lazily deserialized when needed. |
| 7544 | if (!SemaDeclRefs.empty()) { |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 7545 | assert(SemaDeclRefs.size() % 3 == 0); |
| 7546 | for (unsigned I = 0; I != SemaDeclRefs.size(); I += 3) { |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7547 | if (!SemaObj->StdNamespace) |
| 7548 | SemaObj->StdNamespace = SemaDeclRefs[I]; |
| 7549 | if (!SemaObj->StdBadAlloc) |
| 7550 | SemaObj->StdBadAlloc = SemaDeclRefs[I+1]; |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 7551 | if (!SemaObj->StdAlignValT) |
| 7552 | SemaObj->StdAlignValT = SemaDeclRefs[I+2]; |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7553 | } |
| 7554 | SemaDeclRefs.clear(); |
| 7555 | } |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 7556 | |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 7557 | // Update the state of pragmas. Use the same API as if we had encountered the |
| 7558 | // pragma in the source. |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 7559 | if(OptimizeOffPragmaLocation.isValid()) |
| 7560 | SemaObj->ActOnPragmaOptimize(/* IsOn = */ false, OptimizeOffPragmaLocation); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 7561 | if (PragmaMSStructState != -1) |
| 7562 | SemaObj->ActOnPragmaMSStruct((PragmaMSStructKind)PragmaMSStructState); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 7563 | if (PointersToMembersPragmaLocation.isValid()) { |
| 7564 | SemaObj->ActOnPragmaMSPointersToMembers( |
| 7565 | (LangOptions::PragmaMSPointersToMembersKind) |
| 7566 | PragmaMSPointersToMembersState, |
| 7567 | PointersToMembersPragmaLocation); |
| 7568 | } |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 7569 | SemaObj->ForceCUDAHostDeviceDepth = ForceCUDAHostDeviceDepth; |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 7570 | |
| 7571 | if (PragmaPackCurrentValue) { |
| 7572 | // The bottom of the stack might have a default value. It must be adjusted |
| 7573 | // to the current value to ensure that the packing state is preserved after |
| 7574 | // popping entries that were included/imported from a PCH/module. |
| 7575 | bool DropFirst = false; |
| 7576 | if (!PragmaPackStack.empty() && |
| 7577 | PragmaPackStack.front().Location.isInvalid()) { |
| 7578 | assert(PragmaPackStack.front().Value == SemaObj->PackStack.DefaultValue && |
| 7579 | "Expected a default alignment value"); |
| 7580 | SemaObj->PackStack.Stack.emplace_back( |
| 7581 | PragmaPackStack.front().SlotLabel, SemaObj->PackStack.CurrentValue, |
| 7582 | SemaObj->PackStack.CurrentPragmaLocation); |
| 7583 | DropFirst = true; |
| 7584 | } |
| 7585 | for (const auto &Entry : |
| 7586 | llvm::makeArrayRef(PragmaPackStack).drop_front(DropFirst ? 1 : 0)) |
| 7587 | SemaObj->PackStack.Stack.emplace_back(Entry.SlotLabel, Entry.Value, |
| 7588 | Entry.Location); |
| 7589 | if (PragmaPackCurrentLocation.isInvalid()) { |
| 7590 | assert(*PragmaPackCurrentValue == SemaObj->PackStack.DefaultValue && |
| 7591 | "Expected a default alignment value"); |
| 7592 | // Keep the current values. |
| 7593 | } else { |
| 7594 | SemaObj->PackStack.CurrentValue = *PragmaPackCurrentValue; |
| 7595 | SemaObj->PackStack.CurrentPragmaLocation = PragmaPackCurrentLocation; |
| 7596 | } |
| 7597 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7598 | } |
| 7599 | |
Richard Smith | a8d5b6a | 2015-07-17 19:51:03 +0000 | [diff] [blame] | 7600 | IdentifierInfo *ASTReader::get(StringRef Name) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7601 | // Note that we are loading an identifier. |
| 7602 | Deserializing AnIdentifier(this); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 7603 | |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 7604 | IdentifierLookupVisitor Visitor(Name, /*PriorGeneration=*/0, |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 7605 | NumIdentifierLookups, |
| 7606 | NumIdentifierLookupHits); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7607 | |
| 7608 | // We don't need to do identifier table lookups in C++ modules (we preload |
| 7609 | // all interesting declarations, and don't need to use the scope for name |
| 7610 | // lookups). Perform the lookup in PCH files, though, since we don't build |
| 7611 | // a complete initial identifier table if we're carrying on from a PCH. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 7612 | if (PP.getLangOpts().CPlusPlus) { |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7613 | for (auto F : ModuleMgr.pch_modules()) |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7614 | if (Visitor(*F)) |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7615 | break; |
| 7616 | } else { |
| 7617 | // If there is a global index, look there first to determine which modules |
| 7618 | // provably do not have any results for this identifier. |
| 7619 | GlobalModuleIndex::HitSet Hits; |
| 7620 | GlobalModuleIndex::HitSet *HitsPtr = nullptr; |
| 7621 | if (!loadGlobalIndex()) { |
| 7622 | if (GlobalIndex->lookupIdentifier(Name, Hits)) { |
| 7623 | HitsPtr = &Hits; |
| 7624 | } |
| 7625 | } |
| 7626 | |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7627 | ModuleMgr.visit(Visitor, HitsPtr); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7628 | } |
| 7629 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7630 | IdentifierInfo *II = Visitor.getIdentifierInfo(); |
| 7631 | markIdentifierUpToDate(II); |
| 7632 | return II; |
| 7633 | } |
| 7634 | |
| 7635 | namespace clang { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7636 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7637 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 7638 | /// identifiers stored within a set of AST files. |
| 7639 | class ASTIdentifierIterator : public IdentifierIterator { |
| 7640 | /// \brief The AST reader whose identifiers are being enumerated. |
| 7641 | const ASTReader &Reader; |
| 7642 | |
| 7643 | /// \brief The current index into the chain of AST files stored in |
| 7644 | /// the AST reader. |
| 7645 | unsigned Index; |
| 7646 | |
| 7647 | /// \brief The current position within the identifier lookup table |
| 7648 | /// of the current AST file. |
| 7649 | ASTIdentifierLookupTable::key_iterator Current; |
| 7650 | |
| 7651 | /// \brief The end position within the identifier lookup table of |
| 7652 | /// the current AST file. |
| 7653 | ASTIdentifierLookupTable::key_iterator End; |
| 7654 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7655 | /// \brief Whether to skip any modules in the ASTReader. |
| 7656 | bool SkipModules; |
| 7657 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7658 | public: |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7659 | explicit ASTIdentifierIterator(const ASTReader &Reader, |
| 7660 | bool SkipModules = false); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7661 | |
Craig Topper | 3e89dfe | 2014-03-13 02:13:41 +0000 | [diff] [blame] | 7662 | StringRef Next() override; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7663 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7664 | |
| 7665 | } // end namespace clang |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7666 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7667 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader, |
| 7668 | bool SkipModules) |
| 7669 | : Reader(Reader), Index(Reader.ModuleMgr.size()), SkipModules(SkipModules) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7670 | } |
| 7671 | |
| 7672 | StringRef ASTIdentifierIterator::Next() { |
| 7673 | while (Current == End) { |
| 7674 | // If we have exhausted all of our AST files, we're done. |
| 7675 | if (Index == 0) |
| 7676 | return StringRef(); |
| 7677 | |
| 7678 | --Index; |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7679 | ModuleFile &F = Reader.ModuleMgr[Index]; |
| 7680 | if (SkipModules && F.isModule()) |
| 7681 | continue; |
| 7682 | |
| 7683 | ASTIdentifierLookupTable *IdTable = |
| 7684 | (ASTIdentifierLookupTable *)F.IdentifierLookupTable; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7685 | Current = IdTable->key_begin(); |
| 7686 | End = IdTable->key_end(); |
| 7687 | } |
| 7688 | |
| 7689 | // We have any identifiers remaining in the current AST file; return |
| 7690 | // the next one. |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 7691 | StringRef Result = *Current; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7692 | ++Current; |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 7693 | return Result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7694 | } |
| 7695 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7696 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7697 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7698 | /// A utility for appending two IdentifierIterators. |
| 7699 | class ChainedIdentifierIterator : public IdentifierIterator { |
| 7700 | std::unique_ptr<IdentifierIterator> Current; |
| 7701 | std::unique_ptr<IdentifierIterator> Queued; |
| 7702 | |
| 7703 | public: |
| 7704 | ChainedIdentifierIterator(std::unique_ptr<IdentifierIterator> First, |
| 7705 | std::unique_ptr<IdentifierIterator> Second) |
| 7706 | : Current(std::move(First)), Queued(std::move(Second)) {} |
| 7707 | |
| 7708 | StringRef Next() override { |
| 7709 | if (!Current) |
| 7710 | return StringRef(); |
| 7711 | |
| 7712 | StringRef result = Current->Next(); |
| 7713 | if (!result.empty()) |
| 7714 | return result; |
| 7715 | |
| 7716 | // Try the queued iterator, which may itself be empty. |
| 7717 | Current.reset(); |
| 7718 | std::swap(Current, Queued); |
| 7719 | return Next(); |
| 7720 | } |
| 7721 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7722 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7723 | } // end anonymous namespace. |
| 7724 | |
Argyrios Kyrtzidis | 9aca3c6 | 2013-04-17 22:10:55 +0000 | [diff] [blame] | 7725 | IdentifierIterator *ASTReader::getIdentifiers() { |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7726 | if (!loadGlobalIndex()) { |
| 7727 | std::unique_ptr<IdentifierIterator> ReaderIter( |
| 7728 | new ASTIdentifierIterator(*this, /*SkipModules=*/true)); |
| 7729 | std::unique_ptr<IdentifierIterator> ModulesIter( |
| 7730 | GlobalIndex->createIdentifierIterator()); |
| 7731 | return new ChainedIdentifierIterator(std::move(ReaderIter), |
| 7732 | std::move(ModulesIter)); |
| 7733 | } |
Argyrios Kyrtzidis | 9aca3c6 | 2013-04-17 22:10:55 +0000 | [diff] [blame] | 7734 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7735 | return new ASTIdentifierIterator(*this); |
| 7736 | } |
| 7737 | |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7738 | namespace clang { |
| 7739 | namespace serialization { |
| 7740 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7741 | class ReadMethodPoolVisitor { |
| 7742 | ASTReader &Reader; |
| 7743 | Selector Sel; |
| 7744 | unsigned PriorGeneration; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7745 | unsigned InstanceBits; |
| 7746 | unsigned FactoryBits; |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7747 | bool InstanceHasMoreThanOneDecl; |
| 7748 | bool FactoryHasMoreThanOneDecl; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 7749 | SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 7750 | SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7751 | |
| 7752 | public: |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 7753 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7754 | unsigned PriorGeneration) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 7755 | : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration), |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7756 | InstanceBits(0), FactoryBits(0), InstanceHasMoreThanOneDecl(false), |
| 7757 | FactoryHasMoreThanOneDecl(false) {} |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 7758 | |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7759 | bool operator()(ModuleFile &M) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7760 | if (!M.SelectorLookupTable) |
| 7761 | return false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7762 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7763 | // If we've already searched this module file, skip it now. |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7764 | if (M.Generation <= PriorGeneration) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7765 | return true; |
| 7766 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7767 | ++Reader.NumMethodPoolTableLookups; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7768 | ASTSelectorLookupTable *PoolTable |
| 7769 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7770 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7771 | if (Pos == PoolTable->end()) |
| 7772 | return false; |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7773 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7774 | ++Reader.NumMethodPoolTableHits; |
| 7775 | ++Reader.NumSelectorsRead; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7776 | // FIXME: Not quite happy with the statistics here. We probably should |
| 7777 | // disable this tracking when called via LoadSelector. |
| 7778 | // Also, should entries without methods count as misses? |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7779 | ++Reader.NumMethodPoolEntriesRead; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7780 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7781 | if (Reader.DeserializationListener) |
| 7782 | Reader.DeserializationListener->SelectorRead(Data.ID, Sel); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7783 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7784 | InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 7785 | FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 7786 | InstanceBits = Data.InstanceBits; |
| 7787 | FactoryBits = Data.FactoryBits; |
| 7788 | InstanceHasMoreThanOneDecl = Data.InstanceHasMoreThanOneDecl; |
| 7789 | FactoryHasMoreThanOneDecl = Data.FactoryHasMoreThanOneDecl; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7790 | return true; |
| 7791 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7792 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7793 | /// \brief Retrieve the instance methods found by this visitor. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7794 | ArrayRef<ObjCMethodDecl *> getInstanceMethods() const { |
| 7795 | return InstanceMethods; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7796 | } |
| 7797 | |
| 7798 | /// \brief Retrieve the instance methods found by this visitor. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7799 | ArrayRef<ObjCMethodDecl *> getFactoryMethods() const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7800 | return FactoryMethods; |
| 7801 | } |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7802 | |
| 7803 | unsigned getInstanceBits() const { return InstanceBits; } |
| 7804 | unsigned getFactoryBits() const { return FactoryBits; } |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7805 | bool instanceHasMoreThanOneDecl() const { |
| 7806 | return InstanceHasMoreThanOneDecl; |
| 7807 | } |
| 7808 | bool factoryHasMoreThanOneDecl() const { return FactoryHasMoreThanOneDecl; } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7809 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7810 | |
| 7811 | } // end namespace serialization |
| 7812 | } // end namespace clang |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7813 | |
| 7814 | /// \brief Add the given set of methods to the method list. |
| 7815 | static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods, |
| 7816 | ObjCMethodList &List) { |
| 7817 | for (unsigned I = 0, N = Methods.size(); I != N; ++I) { |
| 7818 | S.addMethodToGlobalList(&List, Methods[I]); |
| 7819 | } |
| 7820 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7821 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7822 | void ASTReader::ReadMethodPool(Selector Sel) { |
| 7823 | // Get the selector generation and update it to the current generation. |
| 7824 | unsigned &Generation = SelectorGeneration[Sel]; |
| 7825 | unsigned PriorGeneration = Generation; |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 7826 | Generation = getGeneration(); |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 7827 | SelectorOutOfDate[Sel] = false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7828 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7829 | // Search for methods defined with this selector. |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7830 | ++NumMethodPoolLookups; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7831 | ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7832 | ModuleMgr.visit(Visitor); |
| 7833 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7834 | if (Visitor.getInstanceMethods().empty() && |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7835 | Visitor.getFactoryMethods().empty()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7836 | return; |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7837 | |
| 7838 | ++NumMethodPoolHits; |
| 7839 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7840 | if (!getSema()) |
| 7841 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7842 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7843 | Sema &S = *getSema(); |
| 7844 | Sema::GlobalMethodPool::iterator Pos |
| 7845 | = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first; |
Ben Langmuir | a0c32e9 | 2015-01-12 19:27:00 +0000 | [diff] [blame] | 7846 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7847 | Pos->second.first.setBits(Visitor.getInstanceBits()); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7848 | Pos->second.first.setHasMoreThanOneDecl(Visitor.instanceHasMoreThanOneDecl()); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7849 | Pos->second.second.setBits(Visitor.getFactoryBits()); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7850 | Pos->second.second.setHasMoreThanOneDecl(Visitor.factoryHasMoreThanOneDecl()); |
Ben Langmuir | a0c32e9 | 2015-01-12 19:27:00 +0000 | [diff] [blame] | 7851 | |
| 7852 | // Add methods to the global pool *after* setting hasMoreThanOneDecl, since |
| 7853 | // when building a module we keep every method individually and may need to |
| 7854 | // update hasMoreThanOneDecl as we add the methods. |
| 7855 | addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first); |
| 7856 | addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7857 | } |
| 7858 | |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 7859 | void ASTReader::updateOutOfDateSelector(Selector Sel) { |
| 7860 | if (SelectorOutOfDate[Sel]) |
| 7861 | ReadMethodPool(Sel); |
| 7862 | } |
| 7863 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7864 | void ASTReader::ReadKnownNamespaces( |
| 7865 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
| 7866 | Namespaces.clear(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7867 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7868 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7869 | if (NamespaceDecl *Namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7870 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 7871 | Namespaces.push_back(Namespace); |
| 7872 | } |
| 7873 | } |
| 7874 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 7875 | void ASTReader::ReadUndefinedButUsed( |
Richard Smith | d6a04d7 | 2016-03-25 21:49:43 +0000 | [diff] [blame] | 7876 | llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 7877 | for (unsigned Idx = 0, N = UndefinedButUsed.size(); Idx != N;) { |
| 7878 | NamedDecl *D = cast<NamedDecl>(GetDecl(UndefinedButUsed[Idx++])); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 7879 | SourceLocation Loc = |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 7880 | SourceLocation::getFromRawEncoding(UndefinedButUsed[Idx++]); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 7881 | Undefined.insert(std::make_pair(D, Loc)); |
| 7882 | } |
| 7883 | } |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 7884 | |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 7885 | void ASTReader::ReadMismatchingDeleteExpressions(llvm::MapVector< |
| 7886 | FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> & |
| 7887 | Exprs) { |
| 7888 | for (unsigned Idx = 0, N = DelayedDeleteExprs.size(); Idx != N;) { |
| 7889 | FieldDecl *FD = cast<FieldDecl>(GetDecl(DelayedDeleteExprs[Idx++])); |
| 7890 | uint64_t Count = DelayedDeleteExprs[Idx++]; |
| 7891 | for (uint64_t C = 0; C < Count; ++C) { |
| 7892 | SourceLocation DeleteLoc = |
| 7893 | SourceLocation::getFromRawEncoding(DelayedDeleteExprs[Idx++]); |
| 7894 | const bool IsArrayForm = DelayedDeleteExprs[Idx++]; |
| 7895 | Exprs[FD].push_back(std::make_pair(DeleteLoc, IsArrayForm)); |
| 7896 | } |
| 7897 | } |
| 7898 | } |
| 7899 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7900 | void ASTReader::ReadTentativeDefinitions( |
| 7901 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 7902 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 7903 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 7904 | if (Var) |
| 7905 | TentativeDefs.push_back(Var); |
| 7906 | } |
| 7907 | TentativeDefinitions.clear(); |
| 7908 | } |
| 7909 | |
| 7910 | void ASTReader::ReadUnusedFileScopedDecls( |
| 7911 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 7912 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 7913 | DeclaratorDecl *D |
| 7914 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 7915 | if (D) |
| 7916 | Decls.push_back(D); |
| 7917 | } |
| 7918 | UnusedFileScopedDecls.clear(); |
| 7919 | } |
| 7920 | |
| 7921 | void ASTReader::ReadDelegatingConstructors( |
| 7922 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 7923 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 7924 | CXXConstructorDecl *D |
| 7925 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 7926 | if (D) |
| 7927 | Decls.push_back(D); |
| 7928 | } |
| 7929 | DelegatingCtorDecls.clear(); |
| 7930 | } |
| 7931 | |
| 7932 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 7933 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 7934 | TypedefNameDecl *D |
| 7935 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 7936 | if (D) |
| 7937 | Decls.push_back(D); |
| 7938 | } |
| 7939 | ExtVectorDecls.clear(); |
| 7940 | } |
| 7941 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 7942 | void ASTReader::ReadUnusedLocalTypedefNameCandidates( |
| 7943 | llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) { |
| 7944 | for (unsigned I = 0, N = UnusedLocalTypedefNameCandidates.size(); I != N; |
| 7945 | ++I) { |
| 7946 | TypedefNameDecl *D = dyn_cast_or_null<TypedefNameDecl>( |
| 7947 | GetDecl(UnusedLocalTypedefNameCandidates[I])); |
| 7948 | if (D) |
| 7949 | Decls.insert(D); |
| 7950 | } |
| 7951 | UnusedLocalTypedefNameCandidates.clear(); |
| 7952 | } |
| 7953 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7954 | void ASTReader::ReadReferencedSelectors( |
| 7955 | SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) { |
| 7956 | if (ReferencedSelectorsData.empty()) |
| 7957 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7958 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7959 | // If there are @selector references added them to its pool. This is for |
| 7960 | // implementation of -Wselector. |
| 7961 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 7962 | unsigned I = 0; |
| 7963 | while (I < DataSize) { |
| 7964 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 7965 | SourceLocation SelLoc |
| 7966 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 7967 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 7968 | } |
| 7969 | ReferencedSelectorsData.clear(); |
| 7970 | } |
| 7971 | |
| 7972 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 7973 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WeakIDs) { |
| 7974 | if (WeakUndeclaredIdentifiers.empty()) |
| 7975 | return; |
| 7976 | |
| 7977 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7978 | IdentifierInfo *WeakId |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7979 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7980 | IdentifierInfo *AliasId |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7981 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 7982 | SourceLocation Loc |
| 7983 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 7984 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 7985 | WeakInfo WI(AliasId, Loc); |
| 7986 | WI.setUsed(Used); |
| 7987 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 7988 | } |
| 7989 | WeakUndeclaredIdentifiers.clear(); |
| 7990 | } |
| 7991 | |
| 7992 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 7993 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 7994 | ExternalVTableUse VT; |
| 7995 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 7996 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 7997 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 7998 | VTables.push_back(VT); |
| 7999 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8000 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8001 | VTableUses.clear(); |
| 8002 | } |
| 8003 | |
| 8004 | void ASTReader::ReadPendingInstantiations( |
| 8005 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) { |
| 8006 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 8007 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 8008 | SourceLocation Loc |
| 8009 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 8010 | |
| 8011 | Pending.push_back(std::make_pair(D, Loc)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8012 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8013 | PendingInstantiations.clear(); |
| 8014 | } |
| 8015 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8016 | void ASTReader::ReadLateParsedTemplates( |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 8017 | llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> |
| 8018 | &LPTMap) { |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8019 | for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N; |
| 8020 | /* In loop */) { |
| 8021 | FunctionDecl *FD = cast<FunctionDecl>(GetDecl(LateParsedTemplates[Idx++])); |
| 8022 | |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 8023 | auto LT = llvm::make_unique<LateParsedTemplate>(); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8024 | LT->D = GetDecl(LateParsedTemplates[Idx++]); |
| 8025 | |
| 8026 | ModuleFile *F = getOwningModuleFile(LT->D); |
| 8027 | assert(F && "No module"); |
| 8028 | |
| 8029 | unsigned TokN = LateParsedTemplates[Idx++]; |
| 8030 | LT->Toks.reserve(TokN); |
| 8031 | for (unsigned T = 0; T < TokN; ++T) |
| 8032 | LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx)); |
| 8033 | |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 8034 | LPTMap.insert(std::make_pair(FD, std::move(LT))); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8035 | } |
| 8036 | |
| 8037 | LateParsedTemplates.clear(); |
| 8038 | } |
| 8039 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8040 | void ASTReader::LoadSelector(Selector Sel) { |
| 8041 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 8042 | ReadMethodPool(Sel); |
| 8043 | } |
| 8044 | |
| 8045 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
| 8046 | assert(ID && "Non-zero identifier ID required"); |
| 8047 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
| 8048 | IdentifiersLoaded[ID - 1] = II; |
| 8049 | if (DeserializationListener) |
| 8050 | DeserializationListener->IdentifierRead(ID, II); |
| 8051 | } |
| 8052 | |
| 8053 | /// \brief Set the globally-visible declarations associated with the given |
| 8054 | /// identifier. |
| 8055 | /// |
| 8056 | /// If the AST reader is currently in a state where the given declaration IDs |
| 8057 | /// cannot safely be resolved, they are queued until it is safe to resolve |
| 8058 | /// them. |
| 8059 | /// |
| 8060 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 8061 | /// declarations. |
| 8062 | /// |
| 8063 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 8064 | /// visible at global scope. |
| 8065 | /// |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8066 | /// \param Decls if non-null, this vector will be populated with the set of |
| 8067 | /// deserialized declarations. These declarations will not be pushed into |
| 8068 | /// scope. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8069 | void |
| 8070 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
| 8071 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8072 | SmallVectorImpl<Decl *> *Decls) { |
| 8073 | if (NumCurrentElementsDeserializing && !Decls) { |
| 8074 | PendingIdentifierInfos[II].append(DeclIDs.begin(), DeclIDs.end()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8075 | return; |
| 8076 | } |
| 8077 | |
| 8078 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 8079 | if (!SemaObj) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8080 | // Queue this declaration so that it will be added to the |
| 8081 | // translation unit scope and identifier's declaration chain |
| 8082 | // once a Sema object is known. |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 8083 | PreloadedDeclIDs.push_back(DeclIDs[I]); |
| 8084 | continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8085 | } |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 8086 | |
| 8087 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 8088 | |
| 8089 | // If we're simply supposed to record the declarations, do so now. |
| 8090 | if (Decls) { |
| 8091 | Decls->push_back(D); |
| 8092 | continue; |
| 8093 | } |
| 8094 | |
| 8095 | // Introduce this declaration into the translation-unit scope |
| 8096 | // and add it to the declaration chain for this identifier, so |
| 8097 | // that (unqualified) name lookup will find it. |
| 8098 | pushExternalDeclIntoScope(D, II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8099 | } |
| 8100 | } |
| 8101 | |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 8102 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8103 | if (ID == 0) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8104 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8105 | |
| 8106 | if (IdentifiersLoaded.empty()) { |
| 8107 | Error("no identifier table in AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8108 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8109 | } |
| 8110 | |
| 8111 | ID -= 1; |
| 8112 | if (!IdentifiersLoaded[ID]) { |
| 8113 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 8114 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
| 8115 | ModuleFile *M = I->second; |
| 8116 | unsigned Index = ID - M->BaseIdentifierID; |
| 8117 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
| 8118 | |
| 8119 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 8120 | // Extract that 16-bit length to avoid having to execute strlen(). |
| 8121 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 8122 | // unsigned integers. This is important to avoid integer overflow when |
| 8123 | // we cast them to 'unsigned'. |
| 8124 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
| 8125 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 8126 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 8127 | auto &II = PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
| 8128 | IdentifiersLoaded[ID] = &II; |
| 8129 | markIdentifierFromAST(*this, II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8130 | if (DeserializationListener) |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 8131 | DeserializationListener->IdentifierRead(ID + 1, &II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8132 | } |
| 8133 | |
| 8134 | return IdentifiersLoaded[ID]; |
| 8135 | } |
| 8136 | |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 8137 | IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) { |
| 8138 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8139 | } |
| 8140 | |
| 8141 | IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) { |
| 8142 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 8143 | return LocalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8144 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8145 | if (!M.ModuleOffsetMap.empty()) |
| 8146 | ReadModuleOffsetMap(M); |
| 8147 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8148 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8149 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8150 | assert(I != M.IdentifierRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8151 | && "Invalid index into identifier index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8152 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8153 | return LocalID + I->second; |
| 8154 | } |
| 8155 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8156 | MacroInfo *ASTReader::getMacro(MacroID ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8157 | if (ID == 0) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8158 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8159 | |
| 8160 | if (MacrosLoaded.empty()) { |
| 8161 | Error("no macro table in AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8162 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8163 | } |
| 8164 | |
| 8165 | ID -= NUM_PREDEF_MACRO_IDS; |
| 8166 | if (!MacrosLoaded[ID]) { |
| 8167 | GlobalMacroMapType::iterator I |
| 8168 | = GlobalMacroMap.find(ID + NUM_PREDEF_MACRO_IDS); |
| 8169 | assert(I != GlobalMacroMap.end() && "Corrupted global macro map"); |
| 8170 | ModuleFile *M = I->second; |
| 8171 | unsigned Index = ID - M->BaseMacroID; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8172 | MacrosLoaded[ID] = ReadMacroRecord(*M, M->MacroOffsets[Index]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8173 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8174 | if (DeserializationListener) |
| 8175 | DeserializationListener->MacroRead(ID + NUM_PREDEF_MACRO_IDS, |
| 8176 | MacrosLoaded[ID]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8177 | } |
| 8178 | |
| 8179 | return MacrosLoaded[ID]; |
| 8180 | } |
| 8181 | |
| 8182 | MacroID ASTReader::getGlobalMacroID(ModuleFile &M, unsigned LocalID) { |
| 8183 | if (LocalID < NUM_PREDEF_MACRO_IDS) |
| 8184 | return LocalID; |
| 8185 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8186 | if (!M.ModuleOffsetMap.empty()) |
| 8187 | ReadModuleOffsetMap(M); |
| 8188 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8189 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8190 | = M.MacroRemap.find(LocalID - NUM_PREDEF_MACRO_IDS); |
| 8191 | assert(I != M.MacroRemap.end() && "Invalid index into macro index remap"); |
| 8192 | |
| 8193 | return LocalID + I->second; |
| 8194 | } |
| 8195 | |
| 8196 | serialization::SubmoduleID |
| 8197 | ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) { |
| 8198 | if (LocalID < NUM_PREDEF_SUBMODULE_IDS) |
| 8199 | return LocalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8200 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8201 | if (!M.ModuleOffsetMap.empty()) |
| 8202 | ReadModuleOffsetMap(M); |
| 8203 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8204 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8205 | = M.SubmoduleRemap.find(LocalID - NUM_PREDEF_SUBMODULE_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8206 | assert(I != M.SubmoduleRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8207 | && "Invalid index into submodule index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8208 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8209 | return LocalID + I->second; |
| 8210 | } |
| 8211 | |
| 8212 | Module *ASTReader::getSubmodule(SubmoduleID GlobalID) { |
| 8213 | if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) { |
| 8214 | assert(GlobalID == 0 && "Unhandled global submodule ID"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8215 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8216 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8217 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8218 | if (GlobalID > SubmodulesLoaded.size()) { |
| 8219 | Error("submodule ID out of range in AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8220 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8221 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8222 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8223 | return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS]; |
| 8224 | } |
Douglas Gregor | c147b0b | 2013-01-12 01:29:50 +0000 | [diff] [blame] | 8225 | |
| 8226 | Module *ASTReader::getModule(unsigned ID) { |
| 8227 | return getSubmodule(ID); |
| 8228 | } |
| 8229 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 8230 | ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &F, unsigned ID) { |
| 8231 | if (ID & 1) { |
| 8232 | // It's a module, look it up by submodule ID. |
| 8233 | auto I = GlobalSubmoduleMap.find(getGlobalSubmoduleID(F, ID >> 1)); |
| 8234 | return I == GlobalSubmoduleMap.end() ? nullptr : I->second; |
| 8235 | } else { |
| 8236 | // It's a prefix (preamble, PCH, ...). Look it up by index. |
| 8237 | unsigned IndexFromEnd = ID >> 1; |
| 8238 | assert(IndexFromEnd && "got reference to unknown module file"); |
| 8239 | return getModuleManager().pch_modules().end()[-IndexFromEnd]; |
| 8240 | } |
| 8241 | } |
| 8242 | |
| 8243 | unsigned ASTReader::getModuleFileID(ModuleFile *F) { |
| 8244 | if (!F) |
| 8245 | return 1; |
| 8246 | |
| 8247 | // For a file representing a module, use the submodule ID of the top-level |
| 8248 | // module as the file ID. For any other kind of file, the number of such |
| 8249 | // files loaded beforehand will be the same on reload. |
| 8250 | // FIXME: Is this true even if we have an explicit module file and a PCH? |
| 8251 | if (F->isModule()) |
| 8252 | return ((F->BaseSubmoduleID + NUM_PREDEF_SUBMODULE_IDS) << 1) | 1; |
| 8253 | |
| 8254 | auto PCHModules = getModuleManager().pch_modules(); |
| 8255 | auto I = std::find(PCHModules.begin(), PCHModules.end(), F); |
| 8256 | assert(I != PCHModules.end() && "emitting reference to unknown file"); |
| 8257 | return (I - PCHModules.end()) << 1; |
| 8258 | } |
| 8259 | |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8260 | llvm::Optional<ExternalASTSource::ASTSourceDescriptor> |
| 8261 | ASTReader::getSourceDescriptor(unsigned ID) { |
| 8262 | if (const Module *M = getSubmodule(ID)) |
Adrian Prantl | c6458d6 | 2015-09-19 00:10:32 +0000 | [diff] [blame] | 8263 | return ExternalASTSource::ASTSourceDescriptor(*M); |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8264 | |
| 8265 | // If there is only a single PCH, return it instead. |
Hiroshi Inoue | 3170de0 | 2017-07-01 08:46:43 +0000 | [diff] [blame] | 8266 | // Chained PCH are not supported. |
Saleem Abdulrasool | 97d2555 | 2017-03-02 17:37:11 +0000 | [diff] [blame] | 8267 | const auto &PCHChain = ModuleMgr.pch_modules(); |
| 8268 | if (std::distance(std::begin(PCHChain), std::end(PCHChain))) { |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8269 | ModuleFile &MF = ModuleMgr.getPrimaryModule(); |
Adrian Prantl | 3a2d494 | 2016-01-22 23:30:56 +0000 | [diff] [blame] | 8270 | StringRef ModuleName = llvm::sys::path::filename(MF.OriginalSourceFileName); |
Adrian Prantl | 9bc3c4f | 2016-04-27 17:06:22 +0000 | [diff] [blame] | 8271 | StringRef FileName = llvm::sys::path::filename(MF.FileName); |
| 8272 | return ASTReader::ASTSourceDescriptor(ModuleName, MF.OriginalDir, FileName, |
| 8273 | MF.Signature); |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8274 | } |
| 8275 | return None; |
| 8276 | } |
| 8277 | |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 8278 | ExternalASTSource::ExtKind ASTReader::hasExternalDefinitions(const Decl *FD) { |
David Blaikie | e6b7c28 | 2017-04-11 20:46:34 +0000 | [diff] [blame] | 8279 | auto I = BodySource.find(FD); |
| 8280 | if (I == BodySource.end()) |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 8281 | return EK_ReplyHazy; |
David Blaikie | e6b7c28 | 2017-04-11 20:46:34 +0000 | [diff] [blame] | 8282 | return I->second ? EK_Never : EK_Always; |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 8283 | } |
| 8284 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8285 | Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) { |
| 8286 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 8287 | } |
| 8288 | |
| 8289 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
| 8290 | if (ID == 0) |
| 8291 | return Selector(); |
| 8292 | |
| 8293 | if (ID > SelectorsLoaded.size()) { |
| 8294 | Error("selector ID out of range in AST file"); |
| 8295 | return Selector(); |
| 8296 | } |
| 8297 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8298 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == nullptr) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8299 | // Load this selector from the selector table. |
| 8300 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 8301 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
| 8302 | ModuleFile &M = *I->second; |
| 8303 | ASTSelectorLookupTrait Trait(*this, M); |
| 8304 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
| 8305 | SelectorsLoaded[ID - 1] = |
| 8306 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
| 8307 | if (DeserializationListener) |
| 8308 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 8309 | } |
| 8310 | |
| 8311 | return SelectorsLoaded[ID - 1]; |
| 8312 | } |
| 8313 | |
| 8314 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
| 8315 | return DecodeSelector(ID); |
| 8316 | } |
| 8317 | |
| 8318 | uint32_t ASTReader::GetNumExternalSelectors() { |
| 8319 | // ID 0 (the null selector) is considered an external selector. |
| 8320 | return getTotalNumSelectors() + 1; |
| 8321 | } |
| 8322 | |
| 8323 | serialization::SelectorID |
| 8324 | ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const { |
| 8325 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 8326 | return LocalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8327 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8328 | if (!M.ModuleOffsetMap.empty()) |
| 8329 | ReadModuleOffsetMap(M); |
| 8330 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8331 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8332 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8333 | assert(I != M.SelectorRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8334 | && "Invalid index into selector index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8335 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8336 | return LocalID + I->second; |
| 8337 | } |
| 8338 | |
| 8339 | DeclarationName |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8340 | ASTReader::ReadDeclarationName(ModuleFile &F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8341 | const RecordData &Record, unsigned &Idx) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8342 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8343 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 8344 | switch (Kind) { |
| 8345 | case DeclarationName::Identifier: |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 8346 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8347 | |
| 8348 | case DeclarationName::ObjCZeroArgSelector: |
| 8349 | case DeclarationName::ObjCOneArgSelector: |
| 8350 | case DeclarationName::ObjCMultiArgSelector: |
| 8351 | return DeclarationName(ReadSelector(F, Record, Idx)); |
| 8352 | |
| 8353 | case DeclarationName::CXXConstructorName: |
| 8354 | return Context.DeclarationNames.getCXXConstructorName( |
| 8355 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 8356 | |
| 8357 | case DeclarationName::CXXDestructorName: |
| 8358 | return Context.DeclarationNames.getCXXDestructorName( |
| 8359 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 8360 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8361 | case DeclarationName::CXXDeductionGuideName: |
| 8362 | return Context.DeclarationNames.getCXXDeductionGuideName( |
| 8363 | ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
| 8364 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8365 | case DeclarationName::CXXConversionFunctionName: |
| 8366 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 8367 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 8368 | |
| 8369 | case DeclarationName::CXXOperatorName: |
| 8370 | return Context.DeclarationNames.getCXXOperatorName( |
| 8371 | (OverloadedOperatorKind)Record[Idx++]); |
| 8372 | |
| 8373 | case DeclarationName::CXXLiteralOperatorName: |
| 8374 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
| 8375 | GetIdentifierInfo(F, Record, Idx)); |
| 8376 | |
| 8377 | case DeclarationName::CXXUsingDirective: |
| 8378 | return DeclarationName::getUsingDirectiveName(); |
| 8379 | } |
| 8380 | |
| 8381 | llvm_unreachable("Invalid NameKind!"); |
| 8382 | } |
| 8383 | |
| 8384 | void ASTReader::ReadDeclarationNameLoc(ModuleFile &F, |
| 8385 | DeclarationNameLoc &DNLoc, |
| 8386 | DeclarationName Name, |
| 8387 | const RecordData &Record, unsigned &Idx) { |
| 8388 | switch (Name.getNameKind()) { |
| 8389 | case DeclarationName::CXXConstructorName: |
| 8390 | case DeclarationName::CXXDestructorName: |
| 8391 | case DeclarationName::CXXConversionFunctionName: |
| 8392 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8393 | break; |
| 8394 | |
| 8395 | case DeclarationName::CXXOperatorName: |
| 8396 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 8397 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 8398 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 8399 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 8400 | break; |
| 8401 | |
| 8402 | case DeclarationName::CXXLiteralOperatorName: |
| 8403 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 8404 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 8405 | break; |
| 8406 | |
| 8407 | case DeclarationName::Identifier: |
| 8408 | case DeclarationName::ObjCZeroArgSelector: |
| 8409 | case DeclarationName::ObjCOneArgSelector: |
| 8410 | case DeclarationName::ObjCMultiArgSelector: |
| 8411 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8412 | case DeclarationName::CXXDeductionGuideName: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8413 | break; |
| 8414 | } |
| 8415 | } |
| 8416 | |
| 8417 | void ASTReader::ReadDeclarationNameInfo(ModuleFile &F, |
| 8418 | DeclarationNameInfo &NameInfo, |
| 8419 | const RecordData &Record, unsigned &Idx) { |
| 8420 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
| 8421 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 8422 | DeclarationNameLoc DNLoc; |
| 8423 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 8424 | NameInfo.setInfo(DNLoc); |
| 8425 | } |
| 8426 | |
| 8427 | void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, |
| 8428 | const RecordData &Record, unsigned &Idx) { |
| 8429 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
| 8430 | unsigned NumTPLists = Record[Idx++]; |
| 8431 | Info.NumTemplParamLists = NumTPLists; |
| 8432 | if (NumTPLists) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8433 | Info.TemplParamLists = |
| 8434 | new (getContext()) TemplateParameterList *[NumTPLists]; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 8435 | for (unsigned i = 0; i != NumTPLists; ++i) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8436 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 8437 | } |
| 8438 | } |
| 8439 | |
| 8440 | TemplateName |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8441 | ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8442 | unsigned &Idx) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8443 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8444 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
| 8445 | switch (Kind) { |
| 8446 | case TemplateName::Template: |
| 8447 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
| 8448 | |
| 8449 | case TemplateName::OverloadedTemplate: { |
| 8450 | unsigned size = Record[Idx++]; |
| 8451 | UnresolvedSet<8> Decls; |
| 8452 | while (size--) |
| 8453 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
| 8454 | |
| 8455 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 8456 | } |
| 8457 | |
| 8458 | case TemplateName::QualifiedTemplate: { |
| 8459 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
| 8460 | bool hasTemplKeyword = Record[Idx++]; |
| 8461 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
| 8462 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 8463 | } |
| 8464 | |
| 8465 | case TemplateName::DependentTemplate: { |
| 8466 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
| 8467 | if (Record[Idx++]) // isIdentifier |
| 8468 | return Context.getDependentTemplateName(NNS, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8469 | GetIdentifierInfo(F, Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8470 | Idx)); |
| 8471 | return Context.getDependentTemplateName(NNS, |
| 8472 | (OverloadedOperatorKind)Record[Idx++]); |
| 8473 | } |
| 8474 | |
| 8475 | case TemplateName::SubstTemplateTemplateParm: { |
| 8476 | TemplateTemplateParmDecl *param |
| 8477 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
| 8478 | if (!param) return TemplateName(); |
| 8479 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
| 8480 | return Context.getSubstTemplateTemplateParm(param, replacement); |
| 8481 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8482 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8483 | case TemplateName::SubstTemplateTemplateParmPack: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8484 | TemplateTemplateParmDecl *Param |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8485 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
| 8486 | if (!Param) |
| 8487 | return TemplateName(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8488 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8489 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 8490 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 8491 | return TemplateName(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8492 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8493 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 8494 | } |
| 8495 | } |
| 8496 | |
| 8497 | llvm_unreachable("Unhandled template name kind!"); |
| 8498 | } |
| 8499 | |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8500 | TemplateArgument ASTReader::ReadTemplateArgument(ModuleFile &F, |
| 8501 | const RecordData &Record, |
| 8502 | unsigned &Idx, |
| 8503 | bool Canonicalize) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8504 | ASTContext &Context = getContext(); |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8505 | if (Canonicalize) { |
| 8506 | // The caller wants a canonical template argument. Sometimes the AST only |
| 8507 | // wants template arguments in canonical form (particularly as the template |
| 8508 | // argument lists of template specializations) so ensure we preserve that |
| 8509 | // canonical form across serialization. |
| 8510 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Idx, false); |
| 8511 | return Context.getCanonicalTemplateArgument(Arg); |
| 8512 | } |
| 8513 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8514 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 8515 | switch (Kind) { |
| 8516 | case TemplateArgument::Null: |
| 8517 | return TemplateArgument(); |
| 8518 | case TemplateArgument::Type: |
| 8519 | return TemplateArgument(readType(F, Record, Idx)); |
| 8520 | case TemplateArgument::Declaration: { |
| 8521 | ValueDecl *D = ReadDeclAs<ValueDecl>(F, Record, Idx); |
David Blaikie | 0f62c8d | 2014-10-16 04:21:25 +0000 | [diff] [blame] | 8522 | return TemplateArgument(D, readType(F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8523 | } |
| 8524 | case TemplateArgument::NullPtr: |
| 8525 | return TemplateArgument(readType(F, Record, Idx), /*isNullPtr*/true); |
| 8526 | case TemplateArgument::Integral: { |
| 8527 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 8528 | QualType T = readType(F, Record, Idx); |
| 8529 | return TemplateArgument(Context, Value, T); |
| 8530 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8531 | case TemplateArgument::Template: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8532 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
| 8533 | case TemplateArgument::TemplateExpansion: { |
| 8534 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8535 | Optional<unsigned> NumTemplateExpansions; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8536 | if (unsigned NumExpansions = Record[Idx++]) |
| 8537 | NumTemplateExpansions = NumExpansions - 1; |
| 8538 | return TemplateArgument(Name, NumTemplateExpansions); |
| 8539 | } |
| 8540 | case TemplateArgument::Expression: |
| 8541 | return TemplateArgument(ReadExpr(F)); |
| 8542 | case TemplateArgument::Pack: { |
| 8543 | unsigned NumArgs = Record[Idx++]; |
| 8544 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
| 8545 | for (unsigned I = 0; I != NumArgs; ++I) |
| 8546 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 8547 | return TemplateArgument(llvm::makeArrayRef(Args, NumArgs)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8548 | } |
| 8549 | } |
| 8550 | |
| 8551 | llvm_unreachable("Unhandled template argument kind!"); |
| 8552 | } |
| 8553 | |
| 8554 | TemplateParameterList * |
| 8555 | ASTReader::ReadTemplateParameterList(ModuleFile &F, |
| 8556 | const RecordData &Record, unsigned &Idx) { |
| 8557 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 8558 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 8559 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 8560 | |
| 8561 | unsigned NumParams = Record[Idx++]; |
| 8562 | SmallVector<NamedDecl *, 16> Params; |
| 8563 | Params.reserve(NumParams); |
| 8564 | while (NumParams--) |
| 8565 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
| 8566 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 8567 | // TODO: Concepts |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8568 | TemplateParameterList *TemplateParams = TemplateParameterList::Create( |
| 8569 | getContext(), TemplateLoc, LAngleLoc, Params, RAngleLoc, nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8570 | return TemplateParams; |
| 8571 | } |
| 8572 | |
| 8573 | void |
| 8574 | ASTReader:: |
Craig Topper | 5603df4 | 2013-07-05 19:34:19 +0000 | [diff] [blame] | 8575 | ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8576 | ModuleFile &F, const RecordData &Record, |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8577 | unsigned &Idx, bool Canonicalize) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8578 | unsigned NumTemplateArgs = Record[Idx++]; |
| 8579 | TemplArgs.reserve(NumTemplateArgs); |
| 8580 | while (NumTemplateArgs--) |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8581 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx, Canonicalize)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8582 | } |
| 8583 | |
| 8584 | /// \brief Read a UnresolvedSet structure. |
Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 8585 | void ASTReader::ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8586 | const RecordData &Record, unsigned &Idx) { |
| 8587 | unsigned NumDecls = Record[Idx++]; |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8588 | Set.reserve(getContext(), NumDecls); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8589 | while (NumDecls--) { |
Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 8590 | DeclID ID = ReadDeclID(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8591 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8592 | Set.addLazyDecl(getContext(), ID, AS); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8593 | } |
| 8594 | } |
| 8595 | |
| 8596 | CXXBaseSpecifier |
| 8597 | ASTReader::ReadCXXBaseSpecifier(ModuleFile &F, |
| 8598 | const RecordData &Record, unsigned &Idx) { |
| 8599 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 8600 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 8601 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
| 8602 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
| 8603 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8604 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8605 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8606 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8607 | EllipsisLoc); |
| 8608 | Result.setInheritConstructors(inheritConstructors); |
| 8609 | return Result; |
| 8610 | } |
| 8611 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8612 | CXXCtorInitializer ** |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8613 | ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, |
| 8614 | unsigned &Idx) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8615 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8616 | unsigned NumInitializers = Record[Idx++]; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8617 | assert(NumInitializers && "wrote ctor initializers but have no inits"); |
| 8618 | auto **CtorInitializers = new (Context) CXXCtorInitializer*[NumInitializers]; |
| 8619 | for (unsigned i = 0; i != NumInitializers; ++i) { |
| 8620 | TypeSourceInfo *TInfo = nullptr; |
| 8621 | bool IsBaseVirtual = false; |
| 8622 | FieldDecl *Member = nullptr; |
| 8623 | IndirectFieldDecl *IndirectMember = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8624 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8625 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 8626 | switch (Type) { |
| 8627 | case CTOR_INITIALIZER_BASE: |
| 8628 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8629 | IsBaseVirtual = Record[Idx++]; |
| 8630 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8631 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8632 | case CTOR_INITIALIZER_DELEGATING: |
| 8633 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8634 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8635 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8636 | case CTOR_INITIALIZER_MEMBER: |
| 8637 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
| 8638 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8639 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8640 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
| 8641 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
| 8642 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8643 | } |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8644 | |
| 8645 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
| 8646 | Expr *Init = ReadExpr(F); |
| 8647 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 8648 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8649 | |
| 8650 | CXXCtorInitializer *BOMInit; |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8651 | if (Type == CTOR_INITIALIZER_BASE) |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8652 | BOMInit = new (Context) |
| 8653 | CXXCtorInitializer(Context, TInfo, IsBaseVirtual, LParenLoc, Init, |
| 8654 | RParenLoc, MemberOrEllipsisLoc); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8655 | else if (Type == CTOR_INITIALIZER_DELEGATING) |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8656 | BOMInit = new (Context) |
| 8657 | CXXCtorInitializer(Context, TInfo, LParenLoc, Init, RParenLoc); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8658 | else if (Member) |
| 8659 | BOMInit = new (Context) |
| 8660 | CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, LParenLoc, |
| 8661 | Init, RParenLoc); |
| 8662 | else |
| 8663 | BOMInit = new (Context) |
| 8664 | CXXCtorInitializer(Context, IndirectMember, MemberOrEllipsisLoc, |
| 8665 | LParenLoc, Init, RParenLoc); |
| 8666 | |
Richard Smith | 418ed82 | 2016-12-14 19:45:03 +0000 | [diff] [blame] | 8667 | if (/*IsWritten*/Record[Idx++]) { |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8668 | unsigned SourceOrder = Record[Idx++]; |
| 8669 | BOMInit->setSourceOrder(SourceOrder); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8670 | } |
| 8671 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8672 | CtorInitializers[i] = BOMInit; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8673 | } |
| 8674 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8675 | return CtorInitializers; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8676 | } |
| 8677 | |
| 8678 | NestedNameSpecifier * |
| 8679 | ASTReader::ReadNestedNameSpecifier(ModuleFile &F, |
| 8680 | const RecordData &Record, unsigned &Idx) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8681 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8682 | unsigned N = Record[Idx++]; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8683 | NestedNameSpecifier *NNS = nullptr, *Prev = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8684 | for (unsigned I = 0; I != N; ++I) { |
| 8685 | NestedNameSpecifier::SpecifierKind Kind |
| 8686 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 8687 | switch (Kind) { |
| 8688 | case NestedNameSpecifier::Identifier: { |
| 8689 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
| 8690 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
| 8691 | break; |
| 8692 | } |
| 8693 | |
| 8694 | case NestedNameSpecifier::Namespace: { |
| 8695 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
| 8696 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
| 8697 | break; |
| 8698 | } |
| 8699 | |
| 8700 | case NestedNameSpecifier::NamespaceAlias: { |
| 8701 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
| 8702 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
| 8703 | break; |
| 8704 | } |
| 8705 | |
| 8706 | case NestedNameSpecifier::TypeSpec: |
| 8707 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 8708 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
| 8709 | if (!T) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8710 | return nullptr; |
| 8711 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8712 | bool Template = Record[Idx++]; |
| 8713 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
| 8714 | break; |
| 8715 | } |
| 8716 | |
| 8717 | case NestedNameSpecifier::Global: { |
| 8718 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
| 8719 | // No associated value, and there can't be a prefix. |
| 8720 | break; |
| 8721 | } |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8722 | |
| 8723 | case NestedNameSpecifier::Super: { |
| 8724 | CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx); |
| 8725 | NNS = NestedNameSpecifier::SuperSpecifier(Context, RD); |
| 8726 | break; |
| 8727 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8728 | } |
| 8729 | Prev = NNS; |
| 8730 | } |
| 8731 | return NNS; |
| 8732 | } |
| 8733 | |
| 8734 | NestedNameSpecifierLoc |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8735 | ASTReader::ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8736 | unsigned &Idx) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8737 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8738 | unsigned N = Record[Idx++]; |
| 8739 | NestedNameSpecifierLocBuilder Builder; |
| 8740 | for (unsigned I = 0; I != N; ++I) { |
| 8741 | NestedNameSpecifier::SpecifierKind Kind |
| 8742 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 8743 | switch (Kind) { |
| 8744 | case NestedNameSpecifier::Identifier: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8745 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8746 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8747 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
| 8748 | break; |
| 8749 | } |
| 8750 | |
| 8751 | case NestedNameSpecifier::Namespace: { |
| 8752 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
| 8753 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8754 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
| 8755 | break; |
| 8756 | } |
| 8757 | |
| 8758 | case NestedNameSpecifier::NamespaceAlias: { |
| 8759 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
| 8760 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8761 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
| 8762 | break; |
| 8763 | } |
| 8764 | |
| 8765 | case NestedNameSpecifier::TypeSpec: |
| 8766 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 8767 | bool Template = Record[Idx++]; |
| 8768 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 8769 | if (!T) |
| 8770 | return NestedNameSpecifierLoc(); |
| 8771 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
| 8772 | |
| 8773 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8774 | Builder.Extend(Context, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8775 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 8776 | T->getTypeLoc(), ColonColonLoc); |
| 8777 | break; |
| 8778 | } |
| 8779 | |
| 8780 | case NestedNameSpecifier::Global: { |
| 8781 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
| 8782 | Builder.MakeGlobal(Context, ColonColonLoc); |
| 8783 | break; |
| 8784 | } |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8785 | |
| 8786 | case NestedNameSpecifier::Super: { |
| 8787 | CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx); |
| 8788 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8789 | Builder.MakeSuper(Context, RD, Range.getBegin(), Range.getEnd()); |
| 8790 | break; |
| 8791 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8792 | } |
| 8793 | } |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8794 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8795 | return Builder.getWithLocInContext(Context); |
| 8796 | } |
| 8797 | |
| 8798 | SourceRange |
| 8799 | ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record, |
| 8800 | unsigned &Idx) { |
| 8801 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 8802 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
| 8803 | return SourceRange(beg, end); |
| 8804 | } |
| 8805 | |
| 8806 | /// \brief Read an integral value |
| 8807 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
| 8808 | unsigned BitWidth = Record[Idx++]; |
| 8809 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 8810 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 8811 | Idx += NumWords; |
| 8812 | return Result; |
| 8813 | } |
| 8814 | |
| 8815 | /// \brief Read a signed integral value |
| 8816 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
| 8817 | bool isUnsigned = Record[Idx++]; |
| 8818 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 8819 | } |
| 8820 | |
| 8821 | /// \brief Read a floating-point value |
Tim Northover | 178723a | 2013-01-22 09:46:51 +0000 | [diff] [blame] | 8822 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, |
| 8823 | const llvm::fltSemantics &Sem, |
| 8824 | unsigned &Idx) { |
| 8825 | return llvm::APFloat(Sem, ReadAPInt(Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8826 | } |
| 8827 | |
| 8828 | // \brief Read a string |
| 8829 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
| 8830 | unsigned Len = Record[Idx++]; |
| 8831 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
| 8832 | Idx += Len; |
| 8833 | return Result; |
| 8834 | } |
| 8835 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 8836 | std::string ASTReader::ReadPath(ModuleFile &F, const RecordData &Record, |
| 8837 | unsigned &Idx) { |
| 8838 | std::string Filename = ReadString(Record, Idx); |
| 8839 | ResolveImportedPath(F, Filename); |
| 8840 | return Filename; |
| 8841 | } |
| 8842 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8843 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8844 | unsigned &Idx) { |
| 8845 | unsigned Major = Record[Idx++]; |
| 8846 | unsigned Minor = Record[Idx++]; |
| 8847 | unsigned Subminor = Record[Idx++]; |
| 8848 | if (Minor == 0) |
| 8849 | return VersionTuple(Major); |
| 8850 | if (Subminor == 0) |
| 8851 | return VersionTuple(Major, Minor - 1); |
| 8852 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 8853 | } |
| 8854 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8855 | CXXTemporary *ASTReader::ReadCXXTemporary(ModuleFile &F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8856 | const RecordData &Record, |
| 8857 | unsigned &Idx) { |
| 8858 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8859 | return CXXTemporary::Create(getContext(), Decl); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8860 | } |
| 8861 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8862 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) const { |
Argyrios Kyrtzidis | dc9fdaf | 2013-05-24 05:44:08 +0000 | [diff] [blame] | 8863 | return Diag(CurrentImportLoc, DiagID); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8864 | } |
| 8865 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8866 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8867 | return Diags.Report(Loc, DiagID); |
| 8868 | } |
| 8869 | |
| 8870 | /// \brief Retrieve the identifier table associated with the |
| 8871 | /// preprocessor. |
| 8872 | IdentifierTable &ASTReader::getIdentifierTable() { |
| 8873 | return PP.getIdentifierTable(); |
| 8874 | } |
| 8875 | |
| 8876 | /// \brief Record that the given ID maps to the given switch-case |
| 8877 | /// statement. |
| 8878 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8879 | assert((*CurrSwitchCaseStmts)[ID] == nullptr && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8880 | "Already have a SwitchCase with this ID"); |
| 8881 | (*CurrSwitchCaseStmts)[ID] = SC; |
| 8882 | } |
| 8883 | |
| 8884 | /// \brief Retrieve the switch-case statement with the given ID. |
| 8885 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8886 | assert((*CurrSwitchCaseStmts)[ID] != nullptr && "No SwitchCase with this ID"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8887 | return (*CurrSwitchCaseStmts)[ID]; |
| 8888 | } |
| 8889 | |
| 8890 | void ASTReader::ClearSwitchCaseIDs() { |
| 8891 | CurrSwitchCaseStmts->clear(); |
| 8892 | } |
| 8893 | |
| 8894 | void ASTReader::ReadComments() { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8895 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8896 | std::vector<RawComment *> Comments; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 8897 | for (SmallVectorImpl<std::pair<BitstreamCursor, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8898 | serialization::ModuleFile *> >::iterator |
| 8899 | I = CommentsCursors.begin(), |
| 8900 | E = CommentsCursors.end(); |
| 8901 | I != E; ++I) { |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 8902 | Comments.clear(); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 8903 | BitstreamCursor &Cursor = I->first; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8904 | serialization::ModuleFile &F = *I->second; |
| 8905 | SavedStreamPosition SavedPosition(Cursor); |
| 8906 | |
| 8907 | RecordData Record; |
| 8908 | while (true) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 8909 | llvm::BitstreamEntry Entry = |
| 8910 | Cursor.advanceSkippingSubblocks(BitstreamCursor::AF_DontPopBlockAtEnd); |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 8911 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 8912 | switch (Entry.Kind) { |
| 8913 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 8914 | case llvm::BitstreamEntry::Error: |
| 8915 | Error("malformed block record in AST file"); |
| 8916 | return; |
| 8917 | case llvm::BitstreamEntry::EndBlock: |
| 8918 | goto NextCursor; |
| 8919 | case llvm::BitstreamEntry::Record: |
| 8920 | // The interesting case. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8921 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8922 | } |
| 8923 | |
| 8924 | // Read a record. |
| 8925 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 8926 | switch ((CommentRecordTypes)Cursor.readRecord(Entry.ID, Record)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8927 | case COMMENTS_RAW_COMMENT: { |
| 8928 | unsigned Idx = 0; |
| 8929 | SourceRange SR = ReadSourceRange(F, Record, Idx); |
| 8930 | RawComment::CommentKind Kind = |
| 8931 | (RawComment::CommentKind) Record[Idx++]; |
| 8932 | bool IsTrailingComment = Record[Idx++]; |
| 8933 | bool IsAlmostTrailingComment = Record[Idx++]; |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 8934 | Comments.push_back(new (Context) RawComment( |
| 8935 | SR, Kind, IsTrailingComment, IsAlmostTrailingComment, |
| 8936 | Context.getLangOpts().CommentOpts.ParseAllComments)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8937 | break; |
| 8938 | } |
| 8939 | } |
| 8940 | } |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 8941 | NextCursor: |
Bruno Cardoso Lopes | c23af57 | 2016-12-19 21:06:06 +0000 | [diff] [blame] | 8942 | // De-serialized SourceLocations get negative FileIDs for other modules, |
| 8943 | // potentially invalidating the original order. Sort it again. |
| 8944 | std::sort(Comments.begin(), Comments.end(), |
| 8945 | BeforeThanCompare<RawComment>(SourceMgr)); |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 8946 | Context.Comments.addDeserializedComments(Comments); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8947 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8948 | } |
| 8949 | |
Argyrios Kyrtzidis | a38cb20 | 2017-01-30 06:05:58 +0000 | [diff] [blame] | 8950 | void ASTReader::visitInputFiles(serialization::ModuleFile &MF, |
| 8951 | bool IncludeSystem, bool Complain, |
| 8952 | llvm::function_ref<void(const serialization::InputFile &IF, |
| 8953 | bool isSystem)> Visitor) { |
| 8954 | unsigned NumUserInputs = MF.NumUserInputFiles; |
| 8955 | unsigned NumInputs = MF.InputFilesLoaded.size(); |
| 8956 | assert(NumUserInputs <= NumInputs); |
| 8957 | unsigned N = IncludeSystem ? NumInputs : NumUserInputs; |
| 8958 | for (unsigned I = 0; I < N; ++I) { |
| 8959 | bool IsSystem = I >= NumUserInputs; |
| 8960 | InputFile IF = getInputFile(MF, I+1, Complain); |
| 8961 | Visitor(IF, IsSystem); |
| 8962 | } |
| 8963 | } |
| 8964 | |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 8965 | void ASTReader::visitTopLevelModuleMaps( |
| 8966 | serialization::ModuleFile &MF, |
| 8967 | llvm::function_ref<void(const FileEntry *FE)> Visitor) { |
| 8968 | unsigned NumInputs = MF.InputFilesLoaded.size(); |
| 8969 | for (unsigned I = 0; I < NumInputs; ++I) { |
| 8970 | InputFileInfo IFI = readInputFileInfo(MF, I + 1); |
| 8971 | if (IFI.TopLevelModuleMap) |
| 8972 | // FIXME: This unnecessarily re-reads the InputFileInfo. |
| 8973 | if (auto *FE = getInputFile(MF, I + 1).getFile()) |
| 8974 | Visitor(FE); |
| 8975 | } |
| 8976 | } |
| 8977 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 8978 | std::string ASTReader::getOwningModuleNameForDiagnostic(const Decl *D) { |
| 8979 | // If we know the owning module, use it. |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 8980 | if (Module *M = D->getImportedOwningModule()) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 8981 | return M->getFullModuleName(); |
| 8982 | |
| 8983 | // Otherwise, use the name of the top-level module the decl is within. |
| 8984 | if (ModuleFile *M = getOwningModuleFile(D)) |
| 8985 | return M->ModuleName; |
| 8986 | |
| 8987 | // Not from a module. |
| 8988 | return ""; |
| 8989 | } |
| 8990 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8991 | void ASTReader::finishPendingActions() { |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 8992 | while (!PendingIdentifierInfos.empty() || |
| 8993 | !PendingIncompleteDeclChains.empty() || !PendingDeclChains.empty() || |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 8994 | !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() || |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 8995 | !PendingUpdateRecords.empty()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8996 | // If any identifiers with corresponding top-level declarations have |
| 8997 | // been loaded, load those declarations now. |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 8998 | typedef llvm::DenseMap<IdentifierInfo *, SmallVector<Decl *, 2> > |
| 8999 | TopLevelDeclsMap; |
| 9000 | TopLevelDeclsMap TopLevelDecls; |
| 9001 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9002 | while (!PendingIdentifierInfos.empty()) { |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9003 | IdentifierInfo *II = PendingIdentifierInfos.back().first; |
Richard Smith | f0ae3c2d | 2014-03-28 17:31:23 +0000 | [diff] [blame] | 9004 | SmallVector<uint32_t, 4> DeclIDs = |
| 9005 | std::move(PendingIdentifierInfos.back().second); |
Douglas Gregor | cb15f08 | 2013-02-19 18:26:28 +0000 | [diff] [blame] | 9006 | PendingIdentifierInfos.pop_back(); |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9007 | |
| 9008 | SetGloballyVisibleDecls(II, DeclIDs, &TopLevelDecls[II]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9009 | } |
Richard Smith | f0ae3c2d | 2014-03-28 17:31:23 +0000 | [diff] [blame] | 9010 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 9011 | // For each decl chain that we wanted to complete while deserializing, mark |
| 9012 | // it as "still needs to be completed". |
| 9013 | for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) { |
| 9014 | markIncompleteDeclChain(PendingIncompleteDeclChains[I]); |
| 9015 | } |
| 9016 | PendingIncompleteDeclChains.clear(); |
| 9017 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9018 | // Load pending declaration chains. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 9019 | for (unsigned I = 0; I != PendingDeclChains.size(); ++I) |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 9020 | loadPendingDeclChain(PendingDeclChains[I].first, PendingDeclChains[I].second); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9021 | PendingDeclChains.clear(); |
| 9022 | |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9023 | // Make the most recent of the top-level declarations visible. |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 9024 | for (TopLevelDeclsMap::iterator TLD = TopLevelDecls.begin(), |
| 9025 | TLDEnd = TopLevelDecls.end(); TLD != TLDEnd; ++TLD) { |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9026 | IdentifierInfo *II = TLD->first; |
| 9027 | for (unsigned I = 0, N = TLD->second.size(); I != N; ++I) { |
Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 9028 | pushExternalDeclIntoScope(cast<NamedDecl>(TLD->second[I]), II); |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9029 | } |
| 9030 | } |
| 9031 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9032 | // Load any pending macro definitions. |
| 9033 | for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) { |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9034 | IdentifierInfo *II = PendingMacroIDs.begin()[I].first; |
| 9035 | SmallVector<PendingMacroInfo, 2> GlobalIDs; |
| 9036 | GlobalIDs.swap(PendingMacroIDs.begin()[I].second); |
| 9037 | // Initialize the macro history from chained-PCHs ahead of module imports. |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 9038 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
Argyrios Kyrtzidis | 719736c | 2013-01-19 03:14:56 +0000 | [diff] [blame] | 9039 | ++IDIdx) { |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9040 | const PendingMacroInfo &Info = GlobalIDs[IDIdx]; |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 9041 | if (!Info.M->isModule()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9042 | resolvePendingMacro(II, Info); |
| 9043 | } |
| 9044 | // Handle module imports. |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 9045 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9046 | ++IDIdx) { |
| 9047 | const PendingMacroInfo &Info = GlobalIDs[IDIdx]; |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 9048 | if (Info.M->isModule()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9049 | resolvePendingMacro(II, Info); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9050 | } |
| 9051 | } |
| 9052 | PendingMacroIDs.clear(); |
Argyrios Kyrtzidis | 83a6e3b | 2013-02-16 00:48:59 +0000 | [diff] [blame] | 9053 | |
| 9054 | // Wire up the DeclContexts for Decls that we delayed setting until |
| 9055 | // recursive loading is completed. |
| 9056 | while (!PendingDeclContextInfos.empty()) { |
| 9057 | PendingDeclContextInfo Info = PendingDeclContextInfos.front(); |
| 9058 | PendingDeclContextInfos.pop_front(); |
| 9059 | DeclContext *SemaDC = cast<DeclContext>(GetDecl(Info.SemaDC)); |
| 9060 | DeclContext *LexicalDC = cast<DeclContext>(GetDecl(Info.LexicalDC)); |
| 9061 | Info.D->setDeclContextsImpl(SemaDC, LexicalDC, getContext()); |
| 9062 | } |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 9063 | |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 9064 | // Perform any pending declaration updates. |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 9065 | while (!PendingUpdateRecords.empty()) { |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 9066 | auto Update = PendingUpdateRecords.pop_back_val(); |
| 9067 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 9068 | loadDeclUpdateRecords(Update); |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 9069 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9070 | } |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 9071 | |
| 9072 | // At this point, all update records for loaded decls are in place, so any |
| 9073 | // fake class definitions should have become real. |
| 9074 | assert(PendingFakeDefinitionData.empty() && |
| 9075 | "faked up a class definition but never saw the real one"); |
| 9076 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9077 | // If we deserialized any C++ or Objective-C class definitions, any |
| 9078 | // Objective-C protocol definitions, or any redeclarable templates, make sure |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 9079 | // that all redeclarations point to the definitions. Note that this can only |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9080 | // happen now, after the redeclaration chains have been fully wired. |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9081 | for (Decl *D : PendingDefinitions) { |
| 9082 | if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
Richard Smith | 5b21db8 | 2014-04-23 18:20:42 +0000 | [diff] [blame] | 9083 | if (const TagType *TagT = dyn_cast<TagType>(TD->getTypeForDecl())) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9084 | // Make sure that the TagType points at the definition. |
| 9085 | const_cast<TagType*>(TagT)->decl = TD; |
| 9086 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9087 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9088 | if (auto RD = dyn_cast<CXXRecordDecl>(D)) { |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9089 | for (auto *R = getMostRecentExistingDecl(RD); R; |
| 9090 | R = R->getPreviousDecl()) { |
| 9091 | assert((R == D) == |
| 9092 | cast<CXXRecordDecl>(R)->isThisDeclarationADefinition() && |
Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 9093 | "declaration thinks it's the definition but it isn't"); |
Aaron Ballman | 86c9390 | 2014-03-06 23:45:36 +0000 | [diff] [blame] | 9094 | cast<CXXRecordDecl>(R)->DefinitionData = RD->DefinitionData; |
Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 9095 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9096 | } |
| 9097 | |
| 9098 | continue; |
| 9099 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9100 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9101 | if (auto ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9102 | // Make sure that the ObjCInterfaceType points at the definition. |
| 9103 | const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl)) |
| 9104 | ->Decl = ID; |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9105 | |
| 9106 | for (auto *R = getMostRecentExistingDecl(ID); R; R = R->getPreviousDecl()) |
| 9107 | cast<ObjCInterfaceDecl>(R)->Data = ID->Data; |
| 9108 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9109 | continue; |
| 9110 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9111 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9112 | if (auto PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9113 | for (auto *R = getMostRecentExistingDecl(PD); R; R = R->getPreviousDecl()) |
| 9114 | cast<ObjCProtocolDecl>(R)->Data = PD->Data; |
| 9115 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9116 | continue; |
| 9117 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9118 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9119 | auto RTD = cast<RedeclarableTemplateDecl>(D)->getCanonicalDecl(); |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9120 | for (auto *R = getMostRecentExistingDecl(RTD); R; R = R->getPreviousDecl()) |
| 9121 | cast<RedeclarableTemplateDecl>(R)->Common = RTD->Common; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9122 | } |
| 9123 | PendingDefinitions.clear(); |
| 9124 | |
| 9125 | // Load the bodies of any functions or methods we've encountered. We do |
| 9126 | // 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] | 9127 | // have been fully wired up (hasBody relies on this). |
| 9128 | // FIXME: We shouldn't require complete redeclaration chains here. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9129 | for (PendingBodiesMap::iterator PB = PendingBodies.begin(), |
| 9130 | PBEnd = PendingBodies.end(); |
| 9131 | PB != PBEnd; ++PB) { |
| 9132 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(PB->first)) { |
| 9133 | // FIXME: Check for =delete/=default? |
| 9134 | // FIXME: Complain about ODR violations here? |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 9135 | const FunctionDecl *Defn = nullptr; |
David Blaikie | e6b7c28 | 2017-04-11 20:46:34 +0000 | [diff] [blame] | 9136 | if (!getContext().getLangOpts().Modules || !FD->hasBody(Defn)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9137 | FD->setLazyBody(PB->second); |
David Blaikie | e6b7c28 | 2017-04-11 20:46:34 +0000 | [diff] [blame] | 9138 | } else |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 9139 | mergeDefinitionVisibility(const_cast<FunctionDecl*>(Defn), FD); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9140 | continue; |
| 9141 | } |
| 9142 | |
| 9143 | ObjCMethodDecl *MD = cast<ObjCMethodDecl>(PB->first); |
| 9144 | if (!getContext().getLangOpts().Modules || !MD->hasBody()) |
| 9145 | MD->setLazyBody(PB->second); |
| 9146 | } |
| 9147 | PendingBodies.clear(); |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 9148 | |
| 9149 | // Do some cleanup. |
| 9150 | for (auto *ND : PendingMergedDefinitionsToDeduplicate) |
| 9151 | getContext().deduplicateMergedDefinitonsFor(ND); |
| 9152 | PendingMergedDefinitionsToDeduplicate.clear(); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9153 | } |
| 9154 | |
| 9155 | void ASTReader::diagnoseOdrViolations() { |
Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 9156 | if (PendingOdrMergeFailures.empty() && PendingOdrMergeChecks.empty()) |
| 9157 | return; |
| 9158 | |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9159 | // Trigger the import of the full definition of each class that had any |
| 9160 | // odr-merging problems, so we can produce better diagnostics for them. |
Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 9161 | // These updates may in turn find and diagnose some ODR failures, so take |
| 9162 | // ownership of the set first. |
| 9163 | auto OdrMergeFailures = std::move(PendingOdrMergeFailures); |
| 9164 | PendingOdrMergeFailures.clear(); |
| 9165 | for (auto &Merge : OdrMergeFailures) { |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9166 | Merge.first->buildLookup(); |
| 9167 | Merge.first->decls_begin(); |
| 9168 | Merge.first->bases_begin(); |
| 9169 | Merge.first->vbases_begin(); |
| 9170 | for (auto *RD : Merge.second) { |
| 9171 | RD->decls_begin(); |
| 9172 | RD->bases_begin(); |
| 9173 | RD->vbases_begin(); |
| 9174 | } |
| 9175 | } |
| 9176 | |
| 9177 | // For each declaration from a merged context, check that the canonical |
| 9178 | // definition of that context also contains a declaration of the same |
| 9179 | // entity. |
| 9180 | // |
| 9181 | // Caution: this loop does things that might invalidate iterators into |
| 9182 | // PendingOdrMergeChecks. Don't turn this into a range-based for loop! |
| 9183 | while (!PendingOdrMergeChecks.empty()) { |
| 9184 | NamedDecl *D = PendingOdrMergeChecks.pop_back_val(); |
| 9185 | |
| 9186 | // FIXME: Skip over implicit declarations for now. This matters for things |
| 9187 | // like implicitly-declared special member functions. This isn't entirely |
| 9188 | // correct; we can end up with multiple unmerged declarations of the same |
| 9189 | // implicit entity. |
| 9190 | if (D->isImplicit()) |
| 9191 | continue; |
| 9192 | |
| 9193 | DeclContext *CanonDef = D->getDeclContext(); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9194 | |
| 9195 | bool Found = false; |
| 9196 | const Decl *DCanon = D->getCanonicalDecl(); |
| 9197 | |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 9198 | for (auto RI : D->redecls()) { |
| 9199 | if (RI->getLexicalDeclContext() == CanonDef) { |
| 9200 | Found = true; |
| 9201 | break; |
| 9202 | } |
| 9203 | } |
| 9204 | if (Found) |
| 9205 | continue; |
| 9206 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9207 | // Quick check failed, time to do the slow thing. Note, we can't just |
| 9208 | // look up the name of D in CanonDef here, because the member that is |
| 9209 | // in CanonDef might not be found by name lookup (it might have been |
| 9210 | // replaced by a more recent declaration in the lookup table), and we |
| 9211 | // can't necessarily find it in the redeclaration chain because it might |
| 9212 | // be merely mergeable, not redeclarable. |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9213 | llvm::SmallVector<const NamedDecl*, 4> Candidates; |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9214 | for (auto *CanonMember : CanonDef->decls()) { |
| 9215 | if (CanonMember->getCanonicalDecl() == DCanon) { |
| 9216 | // This can happen if the declaration is merely mergeable and not |
| 9217 | // actually redeclarable (we looked for redeclarations earlier). |
| 9218 | // |
| 9219 | // FIXME: We should be able to detect this more efficiently, without |
| 9220 | // pulling in all of the members of CanonDef. |
| 9221 | Found = true; |
| 9222 | break; |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9223 | } |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9224 | if (auto *ND = dyn_cast<NamedDecl>(CanonMember)) |
| 9225 | if (ND->getDeclName() == D->getDeclName()) |
| 9226 | Candidates.push_back(ND); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9227 | } |
| 9228 | |
| 9229 | if (!Found) { |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 9230 | // The AST doesn't like TagDecls becoming invalid after they've been |
| 9231 | // completed. We only really need to mark FieldDecls as invalid here. |
| 9232 | if (!isa<TagDecl>(D)) |
| 9233 | D->setInvalidDecl(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 9234 | |
Richard Smith | 4ab3dbd | 2015-02-13 22:43:51 +0000 | [diff] [blame] | 9235 | // Ensure we don't accidentally recursively enter deserialization while |
| 9236 | // we're producing our diagnostic. |
| 9237 | Deserializing RecursionGuard(this); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9238 | |
| 9239 | std::string CanonDefModule = |
| 9240 | getOwningModuleNameForDiagnostic(cast<Decl>(CanonDef)); |
| 9241 | Diag(D->getLocation(), diag::err_module_odr_violation_missing_decl) |
| 9242 | << D << getOwningModuleNameForDiagnostic(D) |
| 9243 | << CanonDef << CanonDefModule.empty() << CanonDefModule; |
| 9244 | |
| 9245 | if (Candidates.empty()) |
| 9246 | Diag(cast<Decl>(CanonDef)->getLocation(), |
| 9247 | diag::note_module_odr_violation_no_possible_decls) << D; |
| 9248 | else { |
| 9249 | for (unsigned I = 0, N = Candidates.size(); I != N; ++I) |
| 9250 | Diag(Candidates[I]->getLocation(), |
| 9251 | diag::note_module_odr_violation_possible_decl) |
| 9252 | << Candidates[I]; |
| 9253 | } |
| 9254 | |
| 9255 | DiagnosedOdrMergeFailures.insert(CanonDef); |
| 9256 | } |
| 9257 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9258 | |
Richard Smith | 4ab3dbd | 2015-02-13 22:43:51 +0000 | [diff] [blame] | 9259 | if (OdrMergeFailures.empty()) |
| 9260 | return; |
| 9261 | |
| 9262 | // Ensure we don't accidentally recursively enter deserialization while |
| 9263 | // we're producing our diagnostics. |
| 9264 | Deserializing RecursionGuard(this); |
| 9265 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9266 | // Issue any pending ODR-failure diagnostics. |
Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 9267 | for (auto &Merge : OdrMergeFailures) { |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9268 | // If we've already pointed out a specific problem with this class, don't |
| 9269 | // bother issuing a general "something's different" diagnostic. |
David Blaikie | 82e95a3 | 2014-11-19 07:49:47 +0000 | [diff] [blame] | 9270 | if (!DiagnosedOdrMergeFailures.insert(Merge.first).second) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9271 | continue; |
| 9272 | |
| 9273 | bool Diagnosed = false; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9274 | CXXRecordDecl *FirstRecord = Merge.first; |
| 9275 | std::string FirstModule = getOwningModuleNameForDiagnostic(FirstRecord); |
| 9276 | for (CXXRecordDecl *SecondRecord : Merge.second) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9277 | // Multiple different declarations got merged together; tell the user |
| 9278 | // where they came from. |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9279 | if (FirstRecord == SecondRecord) |
| 9280 | continue; |
| 9281 | |
| 9282 | std::string SecondModule = getOwningModuleNameForDiagnostic(SecondRecord); |
| 9283 | using DeclHashes = llvm::SmallVector<std::pair<Decl *, unsigned>, 4>; |
| 9284 | DeclHashes FirstHashes; |
| 9285 | DeclHashes SecondHashes; |
| 9286 | ODRHash Hash; |
| 9287 | |
| 9288 | auto PopulateHashes = [&Hash, FirstRecord](DeclHashes &Hashes, |
| 9289 | CXXRecordDecl *Record) { |
| 9290 | for (auto *D : Record->decls()) { |
| 9291 | // Due to decl merging, the first CXXRecordDecl is the parent of |
| 9292 | // Decls in both records. |
| 9293 | if (!ODRHash::isWhitelistedDecl(D, FirstRecord)) |
| 9294 | continue; |
| 9295 | Hash.clear(); |
| 9296 | Hash.AddSubDecl(D); |
| 9297 | Hashes.emplace_back(D, Hash.CalculateHash()); |
| 9298 | } |
| 9299 | }; |
| 9300 | PopulateHashes(FirstHashes, FirstRecord); |
| 9301 | PopulateHashes(SecondHashes, SecondRecord); |
| 9302 | |
| 9303 | // Used with err_module_odr_violation_mismatch_decl and |
| 9304 | // note_module_odr_violation_mismatch_decl |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 9305 | // This list should be the same Decl's as in ODRHash::isWhiteListedDecl |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9306 | enum { |
| 9307 | EndOfClass, |
| 9308 | PublicSpecifer, |
| 9309 | PrivateSpecifer, |
| 9310 | ProtectedSpecifer, |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9311 | StaticAssert, |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9312 | Field, |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9313 | CXXMethod, |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 9314 | TypeAlias, |
| 9315 | TypeDef, |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9316 | Var, |
Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 9317 | Friend, |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9318 | Other |
| 9319 | } FirstDiffType = Other, |
| 9320 | SecondDiffType = Other; |
| 9321 | |
| 9322 | auto DifferenceSelector = [](Decl *D) { |
| 9323 | assert(D && "valid Decl required"); |
| 9324 | switch (D->getKind()) { |
| 9325 | default: |
| 9326 | return Other; |
| 9327 | case Decl::AccessSpec: |
| 9328 | switch (D->getAccess()) { |
| 9329 | case AS_public: |
| 9330 | return PublicSpecifer; |
| 9331 | case AS_private: |
| 9332 | return PrivateSpecifer; |
| 9333 | case AS_protected: |
| 9334 | return ProtectedSpecifer; |
| 9335 | case AS_none: |
Simon Pilgrim | eeb1b30 | 2017-02-22 13:21:24 +0000 | [diff] [blame] | 9336 | break; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9337 | } |
Simon Pilgrim | eeb1b30 | 2017-02-22 13:21:24 +0000 | [diff] [blame] | 9338 | llvm_unreachable("Invalid access specifier"); |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9339 | case Decl::StaticAssert: |
| 9340 | return StaticAssert; |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9341 | case Decl::Field: |
| 9342 | return Field; |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9343 | case Decl::CXXMethod: |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9344 | case Decl::CXXConstructor: |
| 9345 | case Decl::CXXDestructor: |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9346 | return CXXMethod; |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 9347 | case Decl::TypeAlias: |
| 9348 | return TypeAlias; |
| 9349 | case Decl::Typedef: |
| 9350 | return TypeDef; |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9351 | case Decl::Var: |
| 9352 | return Var; |
Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 9353 | case Decl::Friend: |
| 9354 | return Friend; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9355 | } |
| 9356 | }; |
| 9357 | |
| 9358 | Decl *FirstDecl = nullptr; |
| 9359 | Decl *SecondDecl = nullptr; |
| 9360 | auto FirstIt = FirstHashes.begin(); |
| 9361 | auto SecondIt = SecondHashes.begin(); |
| 9362 | |
| 9363 | // If there is a diagnoseable difference, FirstDiffType and |
| 9364 | // SecondDiffType will not be Other and FirstDecl and SecondDecl will be |
| 9365 | // filled in if not EndOfClass. |
| 9366 | while (FirstIt != FirstHashes.end() || SecondIt != SecondHashes.end()) { |
Benjamin Kramer | 6f224d2 | 2017-02-22 10:19:45 +0000 | [diff] [blame] | 9367 | if (FirstIt != FirstHashes.end() && SecondIt != SecondHashes.end() && |
| 9368 | FirstIt->second == SecondIt->second) { |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9369 | ++FirstIt; |
| 9370 | ++SecondIt; |
| 9371 | continue; |
Richard Trieu | dc4cb02 | 2017-02-17 07:19:24 +0000 | [diff] [blame] | 9372 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9373 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9374 | FirstDecl = FirstIt == FirstHashes.end() ? nullptr : FirstIt->first; |
| 9375 | SecondDecl = SecondIt == SecondHashes.end() ? nullptr : SecondIt->first; |
| 9376 | |
| 9377 | FirstDiffType = FirstDecl ? DifferenceSelector(FirstDecl) : EndOfClass; |
| 9378 | SecondDiffType = |
| 9379 | SecondDecl ? DifferenceSelector(SecondDecl) : EndOfClass; |
| 9380 | |
| 9381 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9382 | } |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9383 | |
| 9384 | if (FirstDiffType == Other || SecondDiffType == Other) { |
| 9385 | // Reaching this point means an unexpected Decl was encountered |
| 9386 | // or no difference was detected. This causes a generic error |
| 9387 | // message to be emitted. |
| 9388 | Diag(FirstRecord->getLocation(), |
| 9389 | diag::err_module_odr_violation_different_definitions) |
| 9390 | << FirstRecord << FirstModule.empty() << FirstModule; |
| 9391 | |
Richard Trieu | ca48d36 | 2017-06-21 01:43:13 +0000 | [diff] [blame] | 9392 | if (FirstDecl) { |
| 9393 | Diag(FirstDecl->getLocation(), diag::note_first_module_difference) |
| 9394 | << FirstRecord << FirstDecl->getSourceRange(); |
| 9395 | } |
| 9396 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9397 | Diag(SecondRecord->getLocation(), |
| 9398 | diag::note_module_odr_violation_different_definitions) |
| 9399 | << SecondModule; |
Richard Trieu | ca48d36 | 2017-06-21 01:43:13 +0000 | [diff] [blame] | 9400 | |
| 9401 | if (SecondDecl) { |
| 9402 | Diag(SecondDecl->getLocation(), diag::note_second_module_difference) |
| 9403 | << SecondDecl->getSourceRange(); |
| 9404 | } |
| 9405 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9406 | Diagnosed = true; |
| 9407 | break; |
| 9408 | } |
| 9409 | |
| 9410 | if (FirstDiffType != SecondDiffType) { |
| 9411 | SourceLocation FirstLoc; |
| 9412 | SourceRange FirstRange; |
| 9413 | if (FirstDiffType == EndOfClass) { |
| 9414 | FirstLoc = FirstRecord->getBraceRange().getEnd(); |
| 9415 | } else { |
| 9416 | FirstLoc = FirstIt->first->getLocation(); |
| 9417 | FirstRange = FirstIt->first->getSourceRange(); |
| 9418 | } |
| 9419 | Diag(FirstLoc, diag::err_module_odr_violation_mismatch_decl) |
| 9420 | << FirstRecord << FirstModule.empty() << FirstModule << FirstRange |
| 9421 | << FirstDiffType; |
| 9422 | |
| 9423 | SourceLocation SecondLoc; |
| 9424 | SourceRange SecondRange; |
| 9425 | if (SecondDiffType == EndOfClass) { |
| 9426 | SecondLoc = SecondRecord->getBraceRange().getEnd(); |
| 9427 | } else { |
| 9428 | SecondLoc = SecondDecl->getLocation(); |
| 9429 | SecondRange = SecondDecl->getSourceRange(); |
| 9430 | } |
| 9431 | Diag(SecondLoc, diag::note_module_odr_violation_mismatch_decl) |
| 9432 | << SecondModule << SecondRange << SecondDiffType; |
| 9433 | Diagnosed = true; |
| 9434 | break; |
| 9435 | } |
| 9436 | |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9437 | assert(FirstDiffType == SecondDiffType); |
| 9438 | |
| 9439 | // Used with err_module_odr_violation_mismatch_decl_diff and |
| 9440 | // note_module_odr_violation_mismatch_decl_diff |
| 9441 | enum ODRDeclDifference{ |
| 9442 | StaticAssertCondition, |
| 9443 | StaticAssertMessage, |
| 9444 | StaticAssertOnlyMessage, |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9445 | FieldName, |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 9446 | FieldTypeName, |
Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 9447 | FieldSingleBitField, |
Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 9448 | FieldDifferentWidthBitField, |
| 9449 | FieldSingleMutable, |
| 9450 | FieldSingleInitializer, |
| 9451 | FieldDifferentInitializers, |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9452 | MethodName, |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9453 | MethodDeleted, |
| 9454 | MethodVirtual, |
| 9455 | MethodStatic, |
| 9456 | MethodVolatile, |
| 9457 | MethodConst, |
| 9458 | MethodInline, |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 9459 | MethodNumberParameters, |
| 9460 | MethodParameterType, |
| 9461 | MethodParameterName, |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9462 | MethodParameterSingleDefaultArgument, |
| 9463 | MethodParameterDifferentDefaultArgument, |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 9464 | TypedefName, |
| 9465 | TypedefType, |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9466 | VarName, |
| 9467 | VarType, |
| 9468 | VarSingleInitializer, |
| 9469 | VarDifferentInitializer, |
| 9470 | VarConstexpr, |
Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 9471 | FriendTypeFunction, |
| 9472 | FriendType, |
| 9473 | FriendFunction, |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9474 | }; |
| 9475 | |
| 9476 | // These lambdas have the common portions of the ODR diagnostics. This |
| 9477 | // has the same return as Diag(), so addition parameters can be passed |
| 9478 | // in with operator<< |
| 9479 | auto ODRDiagError = [FirstRecord, &FirstModule, this]( |
| 9480 | SourceLocation Loc, SourceRange Range, ODRDeclDifference DiffType) { |
| 9481 | return Diag(Loc, diag::err_module_odr_violation_mismatch_decl_diff) |
| 9482 | << FirstRecord << FirstModule.empty() << FirstModule << Range |
| 9483 | << DiffType; |
| 9484 | }; |
| 9485 | auto ODRDiagNote = [&SecondModule, this]( |
| 9486 | SourceLocation Loc, SourceRange Range, ODRDeclDifference DiffType) { |
| 9487 | return Diag(Loc, diag::note_module_odr_violation_mismatch_decl_diff) |
| 9488 | << SecondModule << Range << DiffType; |
| 9489 | }; |
| 9490 | |
| 9491 | auto ComputeODRHash = [&Hash](const Stmt* S) { |
| 9492 | assert(S); |
| 9493 | Hash.clear(); |
| 9494 | Hash.AddStmt(S); |
| 9495 | return Hash.CalculateHash(); |
| 9496 | }; |
| 9497 | |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 9498 | auto ComputeQualTypeODRHash = [&Hash](QualType Ty) { |
| 9499 | Hash.clear(); |
| 9500 | Hash.AddQualType(Ty); |
| 9501 | return Hash.CalculateHash(); |
| 9502 | }; |
| 9503 | |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9504 | switch (FirstDiffType) { |
| 9505 | case Other: |
| 9506 | case EndOfClass: |
| 9507 | case PublicSpecifer: |
| 9508 | case PrivateSpecifer: |
| 9509 | case ProtectedSpecifer: |
| 9510 | llvm_unreachable("Invalid diff type"); |
| 9511 | |
| 9512 | case StaticAssert: { |
| 9513 | StaticAssertDecl *FirstSA = cast<StaticAssertDecl>(FirstDecl); |
| 9514 | StaticAssertDecl *SecondSA = cast<StaticAssertDecl>(SecondDecl); |
| 9515 | |
| 9516 | Expr *FirstExpr = FirstSA->getAssertExpr(); |
| 9517 | Expr *SecondExpr = SecondSA->getAssertExpr(); |
| 9518 | unsigned FirstODRHash = ComputeODRHash(FirstExpr); |
| 9519 | unsigned SecondODRHash = ComputeODRHash(SecondExpr); |
| 9520 | if (FirstODRHash != SecondODRHash) { |
| 9521 | ODRDiagError(FirstExpr->getLocStart(), FirstExpr->getSourceRange(), |
| 9522 | StaticAssertCondition); |
| 9523 | ODRDiagNote(SecondExpr->getLocStart(), |
| 9524 | SecondExpr->getSourceRange(), StaticAssertCondition); |
| 9525 | Diagnosed = true; |
| 9526 | break; |
| 9527 | } |
| 9528 | |
| 9529 | StringLiteral *FirstStr = FirstSA->getMessage(); |
| 9530 | StringLiteral *SecondStr = SecondSA->getMessage(); |
| 9531 | assert((FirstStr || SecondStr) && "Both messages cannot be empty"); |
| 9532 | if ((FirstStr && !SecondStr) || (!FirstStr && SecondStr)) { |
| 9533 | SourceLocation FirstLoc, SecondLoc; |
| 9534 | SourceRange FirstRange, SecondRange; |
| 9535 | if (FirstStr) { |
| 9536 | FirstLoc = FirstStr->getLocStart(); |
| 9537 | FirstRange = FirstStr->getSourceRange(); |
| 9538 | } else { |
| 9539 | FirstLoc = FirstSA->getLocStart(); |
| 9540 | FirstRange = FirstSA->getSourceRange(); |
| 9541 | } |
| 9542 | if (SecondStr) { |
| 9543 | SecondLoc = SecondStr->getLocStart(); |
| 9544 | SecondRange = SecondStr->getSourceRange(); |
| 9545 | } else { |
| 9546 | SecondLoc = SecondSA->getLocStart(); |
| 9547 | SecondRange = SecondSA->getSourceRange(); |
| 9548 | } |
| 9549 | ODRDiagError(FirstLoc, FirstRange, StaticAssertOnlyMessage) |
| 9550 | << (FirstStr == nullptr); |
| 9551 | ODRDiagNote(SecondLoc, SecondRange, StaticAssertOnlyMessage) |
| 9552 | << (SecondStr == nullptr); |
| 9553 | Diagnosed = true; |
| 9554 | break; |
| 9555 | } |
| 9556 | |
| 9557 | if (FirstStr && SecondStr && |
| 9558 | FirstStr->getString() != SecondStr->getString()) { |
| 9559 | ODRDiagError(FirstStr->getLocStart(), FirstStr->getSourceRange(), |
| 9560 | StaticAssertMessage); |
| 9561 | ODRDiagNote(SecondStr->getLocStart(), SecondStr->getSourceRange(), |
| 9562 | StaticAssertMessage); |
| 9563 | Diagnosed = true; |
| 9564 | break; |
| 9565 | } |
| 9566 | break; |
| 9567 | } |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9568 | case Field: { |
| 9569 | FieldDecl *FirstField = cast<FieldDecl>(FirstDecl); |
| 9570 | FieldDecl *SecondField = cast<FieldDecl>(SecondDecl); |
| 9571 | IdentifierInfo *FirstII = FirstField->getIdentifier(); |
| 9572 | IdentifierInfo *SecondII = SecondField->getIdentifier(); |
| 9573 | if (FirstII->getName() != SecondII->getName()) { |
| 9574 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9575 | FieldName) |
| 9576 | << FirstII; |
| 9577 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9578 | FieldName) |
| 9579 | << SecondII; |
| 9580 | |
| 9581 | Diagnosed = true; |
| 9582 | break; |
| 9583 | } |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 9584 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 9585 | assert(getContext().hasSameType(FirstField->getType(), |
| 9586 | SecondField->getType())); |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 9587 | |
| 9588 | QualType FirstType = FirstField->getType(); |
| 9589 | QualType SecondType = SecondField->getType(); |
Richard Trieu | ce81b19 | 2017-05-17 03:23:35 +0000 | [diff] [blame] | 9590 | if (ComputeQualTypeODRHash(FirstType) != |
| 9591 | ComputeQualTypeODRHash(SecondType)) { |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 9592 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9593 | FieldTypeName) |
| 9594 | << FirstII << FirstType; |
| 9595 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9596 | FieldTypeName) |
| 9597 | << SecondII << SecondType; |
| 9598 | |
| 9599 | Diagnosed = true; |
| 9600 | break; |
| 9601 | } |
| 9602 | |
Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 9603 | const bool IsFirstBitField = FirstField->isBitField(); |
| 9604 | const bool IsSecondBitField = SecondField->isBitField(); |
| 9605 | if (IsFirstBitField != IsSecondBitField) { |
| 9606 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9607 | FieldSingleBitField) |
| 9608 | << FirstII << IsFirstBitField; |
| 9609 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9610 | FieldSingleBitField) |
| 9611 | << SecondII << IsSecondBitField; |
| 9612 | Diagnosed = true; |
| 9613 | break; |
| 9614 | } |
| 9615 | |
| 9616 | if (IsFirstBitField && IsSecondBitField) { |
| 9617 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9618 | FieldDifferentWidthBitField) |
| 9619 | << FirstII << FirstField->getBitWidth()->getSourceRange(); |
| 9620 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9621 | FieldDifferentWidthBitField) |
| 9622 | << SecondII << SecondField->getBitWidth()->getSourceRange(); |
| 9623 | Diagnosed = true; |
| 9624 | break; |
| 9625 | } |
| 9626 | |
Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 9627 | const bool IsFirstMutable = FirstField->isMutable(); |
| 9628 | const bool IsSecondMutable = SecondField->isMutable(); |
| 9629 | if (IsFirstMutable != IsSecondMutable) { |
| 9630 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9631 | FieldSingleMutable) |
| 9632 | << FirstII << IsFirstMutable; |
| 9633 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9634 | FieldSingleMutable) |
| 9635 | << SecondII << IsSecondMutable; |
| 9636 | Diagnosed = true; |
| 9637 | break; |
| 9638 | } |
| 9639 | |
| 9640 | const Expr *FirstInitializer = FirstField->getInClassInitializer(); |
| 9641 | const Expr *SecondInitializer = SecondField->getInClassInitializer(); |
| 9642 | if ((!FirstInitializer && SecondInitializer) || |
| 9643 | (FirstInitializer && !SecondInitializer)) { |
| 9644 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 9645 | FieldSingleInitializer) |
| 9646 | << FirstII << (FirstInitializer != nullptr); |
| 9647 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 9648 | FieldSingleInitializer) |
| 9649 | << SecondII << (SecondInitializer != nullptr); |
| 9650 | Diagnosed = true; |
| 9651 | break; |
| 9652 | } |
| 9653 | |
| 9654 | if (FirstInitializer && SecondInitializer) { |
| 9655 | unsigned FirstInitHash = ComputeODRHash(FirstInitializer); |
| 9656 | unsigned SecondInitHash = ComputeODRHash(SecondInitializer); |
| 9657 | if (FirstInitHash != SecondInitHash) { |
| 9658 | ODRDiagError(FirstField->getLocation(), |
| 9659 | FirstField->getSourceRange(), |
| 9660 | FieldDifferentInitializers) |
| 9661 | << FirstII << FirstInitializer->getSourceRange(); |
| 9662 | ODRDiagNote(SecondField->getLocation(), |
| 9663 | SecondField->getSourceRange(), |
| 9664 | FieldDifferentInitializers) |
| 9665 | << SecondII << SecondInitializer->getSourceRange(); |
| 9666 | Diagnosed = true; |
| 9667 | break; |
| 9668 | } |
| 9669 | } |
| 9670 | |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9671 | break; |
| 9672 | } |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9673 | case CXXMethod: { |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9674 | enum { |
| 9675 | DiagMethod, |
| 9676 | DiagConstructor, |
| 9677 | DiagDestructor, |
| 9678 | } FirstMethodType, |
| 9679 | SecondMethodType; |
| 9680 | auto GetMethodTypeForDiagnostics = [](const CXXMethodDecl* D) { |
| 9681 | if (isa<CXXConstructorDecl>(D)) return DiagConstructor; |
| 9682 | if (isa<CXXDestructorDecl>(D)) return DiagDestructor; |
| 9683 | return DiagMethod; |
| 9684 | }; |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9685 | const CXXMethodDecl *FirstMethod = cast<CXXMethodDecl>(FirstDecl); |
| 9686 | const CXXMethodDecl *SecondMethod = cast<CXXMethodDecl>(SecondDecl); |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9687 | FirstMethodType = GetMethodTypeForDiagnostics(FirstMethod); |
| 9688 | SecondMethodType = GetMethodTypeForDiagnostics(SecondMethod); |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9689 | auto FirstName = FirstMethod->getDeclName(); |
| 9690 | auto SecondName = SecondMethod->getDeclName(); |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9691 | if (FirstMethodType != SecondMethodType || FirstName != SecondName) { |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9692 | ODRDiagError(FirstMethod->getLocation(), |
| 9693 | FirstMethod->getSourceRange(), MethodName) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9694 | << FirstMethodType << FirstName; |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9695 | ODRDiagNote(SecondMethod->getLocation(), |
| 9696 | SecondMethod->getSourceRange(), MethodName) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9697 | << SecondMethodType << SecondName; |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9698 | |
| 9699 | Diagnosed = true; |
| 9700 | break; |
| 9701 | } |
| 9702 | |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9703 | const bool FirstDeleted = FirstMethod->isDeleted(); |
| 9704 | const bool SecondDeleted = SecondMethod->isDeleted(); |
| 9705 | if (FirstDeleted != SecondDeleted) { |
| 9706 | ODRDiagError(FirstMethod->getLocation(), |
| 9707 | FirstMethod->getSourceRange(), MethodDeleted) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9708 | << FirstMethodType << FirstName << FirstDeleted; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9709 | |
| 9710 | ODRDiagNote(SecondMethod->getLocation(), |
| 9711 | SecondMethod->getSourceRange(), MethodDeleted) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9712 | << SecondMethodType << SecondName << SecondDeleted; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9713 | Diagnosed = true; |
| 9714 | break; |
| 9715 | } |
| 9716 | |
| 9717 | const bool FirstVirtual = FirstMethod->isVirtualAsWritten(); |
| 9718 | const bool SecondVirtual = SecondMethod->isVirtualAsWritten(); |
| 9719 | const bool FirstPure = FirstMethod->isPure(); |
| 9720 | const bool SecondPure = SecondMethod->isPure(); |
| 9721 | if ((FirstVirtual || SecondVirtual) && |
| 9722 | (FirstVirtual != SecondVirtual || FirstPure != SecondPure)) { |
| 9723 | ODRDiagError(FirstMethod->getLocation(), |
| 9724 | FirstMethod->getSourceRange(), MethodVirtual) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9725 | << FirstMethodType << FirstName << FirstPure << FirstVirtual; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9726 | ODRDiagNote(SecondMethod->getLocation(), |
| 9727 | SecondMethod->getSourceRange(), MethodVirtual) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9728 | << SecondMethodType << SecondName << SecondPure << SecondVirtual; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9729 | Diagnosed = true; |
| 9730 | break; |
| 9731 | } |
| 9732 | |
| 9733 | // CXXMethodDecl::isStatic uses the canonical Decl. With Decl merging, |
| 9734 | // FirstDecl is the canonical Decl of SecondDecl, so the storage |
| 9735 | // class needs to be checked instead. |
| 9736 | const auto FirstStorage = FirstMethod->getStorageClass(); |
| 9737 | const auto SecondStorage = SecondMethod->getStorageClass(); |
| 9738 | const bool FirstStatic = FirstStorage == SC_Static; |
| 9739 | const bool SecondStatic = SecondStorage == SC_Static; |
| 9740 | if (FirstStatic != SecondStatic) { |
| 9741 | ODRDiagError(FirstMethod->getLocation(), |
| 9742 | FirstMethod->getSourceRange(), MethodStatic) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9743 | << FirstMethodType << FirstName << FirstStatic; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9744 | ODRDiagNote(SecondMethod->getLocation(), |
| 9745 | SecondMethod->getSourceRange(), MethodStatic) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9746 | << SecondMethodType << SecondName << SecondStatic; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9747 | Diagnosed = true; |
| 9748 | break; |
| 9749 | } |
| 9750 | |
| 9751 | const bool FirstVolatile = FirstMethod->isVolatile(); |
| 9752 | const bool SecondVolatile = SecondMethod->isVolatile(); |
| 9753 | if (FirstVolatile != SecondVolatile) { |
| 9754 | ODRDiagError(FirstMethod->getLocation(), |
| 9755 | FirstMethod->getSourceRange(), MethodVolatile) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9756 | << FirstMethodType << FirstName << FirstVolatile; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9757 | ODRDiagNote(SecondMethod->getLocation(), |
| 9758 | SecondMethod->getSourceRange(), MethodVolatile) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9759 | << SecondMethodType << SecondName << SecondVolatile; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9760 | Diagnosed = true; |
| 9761 | break; |
| 9762 | } |
| 9763 | |
| 9764 | const bool FirstConst = FirstMethod->isConst(); |
| 9765 | const bool SecondConst = SecondMethod->isConst(); |
| 9766 | if (FirstConst != SecondConst) { |
| 9767 | ODRDiagError(FirstMethod->getLocation(), |
| 9768 | FirstMethod->getSourceRange(), MethodConst) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9769 | << FirstMethodType << FirstName << FirstConst; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9770 | ODRDiagNote(SecondMethod->getLocation(), |
| 9771 | SecondMethod->getSourceRange(), MethodConst) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9772 | << SecondMethodType << SecondName << SecondConst; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9773 | Diagnosed = true; |
| 9774 | break; |
| 9775 | } |
| 9776 | |
| 9777 | const bool FirstInline = FirstMethod->isInlineSpecified(); |
| 9778 | const bool SecondInline = SecondMethod->isInlineSpecified(); |
| 9779 | if (FirstInline != SecondInline) { |
| 9780 | ODRDiagError(FirstMethod->getLocation(), |
| 9781 | FirstMethod->getSourceRange(), MethodInline) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9782 | << FirstMethodType << FirstName << FirstInline; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9783 | ODRDiagNote(SecondMethod->getLocation(), |
| 9784 | SecondMethod->getSourceRange(), MethodInline) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9785 | << SecondMethodType << SecondName << SecondInline; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9786 | Diagnosed = true; |
| 9787 | break; |
| 9788 | } |
| 9789 | |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 9790 | const unsigned FirstNumParameters = FirstMethod->param_size(); |
| 9791 | const unsigned SecondNumParameters = SecondMethod->param_size(); |
| 9792 | if (FirstNumParameters != SecondNumParameters) { |
| 9793 | ODRDiagError(FirstMethod->getLocation(), |
| 9794 | FirstMethod->getSourceRange(), MethodNumberParameters) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9795 | << FirstMethodType << FirstName << FirstNumParameters; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 9796 | ODRDiagNote(SecondMethod->getLocation(), |
| 9797 | SecondMethod->getSourceRange(), MethodNumberParameters) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9798 | << SecondMethodType << SecondName << SecondNumParameters; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 9799 | Diagnosed = true; |
| 9800 | break; |
| 9801 | } |
| 9802 | |
| 9803 | // Need this status boolean to know when break out of the switch. |
| 9804 | bool ParameterMismatch = false; |
| 9805 | for (unsigned I = 0; I < FirstNumParameters; ++I) { |
| 9806 | const ParmVarDecl *FirstParam = FirstMethod->getParamDecl(I); |
| 9807 | const ParmVarDecl *SecondParam = SecondMethod->getParamDecl(I); |
| 9808 | |
| 9809 | QualType FirstParamType = FirstParam->getType(); |
| 9810 | QualType SecondParamType = SecondParam->getType(); |
| 9811 | if (FirstParamType != SecondParamType && |
| 9812 | ComputeQualTypeODRHash(FirstParamType) != |
| 9813 | ComputeQualTypeODRHash(SecondParamType)) { |
| 9814 | if (const DecayedType *ParamDecayedType = |
| 9815 | FirstParamType->getAs<DecayedType>()) { |
| 9816 | ODRDiagError(FirstMethod->getLocation(), |
| 9817 | FirstMethod->getSourceRange(), MethodParameterType) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9818 | << FirstMethodType << FirstName << (I + 1) << FirstParamType |
| 9819 | << true << ParamDecayedType->getOriginalType(); |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 9820 | } else { |
| 9821 | ODRDiagError(FirstMethod->getLocation(), |
| 9822 | FirstMethod->getSourceRange(), MethodParameterType) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9823 | << FirstMethodType << FirstName << (I + 1) << FirstParamType |
| 9824 | << false; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 9825 | } |
| 9826 | |
| 9827 | if (const DecayedType *ParamDecayedType = |
| 9828 | SecondParamType->getAs<DecayedType>()) { |
| 9829 | ODRDiagNote(SecondMethod->getLocation(), |
| 9830 | SecondMethod->getSourceRange(), MethodParameterType) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9831 | << SecondMethodType << SecondName << (I + 1) |
| 9832 | << SecondParamType << true |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 9833 | << ParamDecayedType->getOriginalType(); |
| 9834 | } else { |
| 9835 | ODRDiagNote(SecondMethod->getLocation(), |
| 9836 | SecondMethod->getSourceRange(), MethodParameterType) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9837 | << SecondMethodType << SecondName << (I + 1) |
| 9838 | << SecondParamType << false; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 9839 | } |
| 9840 | ParameterMismatch = true; |
| 9841 | break; |
| 9842 | } |
| 9843 | |
| 9844 | DeclarationName FirstParamName = FirstParam->getDeclName(); |
| 9845 | DeclarationName SecondParamName = SecondParam->getDeclName(); |
| 9846 | if (FirstParamName != SecondParamName) { |
| 9847 | ODRDiagError(FirstMethod->getLocation(), |
| 9848 | FirstMethod->getSourceRange(), MethodParameterName) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9849 | << FirstMethodType << FirstName << (I + 1) << FirstParamName; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 9850 | ODRDiagNote(SecondMethod->getLocation(), |
| 9851 | SecondMethod->getSourceRange(), MethodParameterName) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9852 | << SecondMethodType << SecondName << (I + 1) << SecondParamName; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 9853 | ParameterMismatch = true; |
| 9854 | break; |
| 9855 | } |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9856 | |
| 9857 | const Expr *FirstInit = FirstParam->getInit(); |
| 9858 | const Expr *SecondInit = SecondParam->getInit(); |
| 9859 | if ((FirstInit == nullptr) != (SecondInit == nullptr)) { |
| 9860 | ODRDiagError(FirstMethod->getLocation(), |
| 9861 | FirstMethod->getSourceRange(), |
| 9862 | MethodParameterSingleDefaultArgument) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9863 | << FirstMethodType << FirstName << (I + 1) |
| 9864 | << (FirstInit == nullptr) |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9865 | << (FirstInit ? FirstInit->getSourceRange() : SourceRange()); |
| 9866 | ODRDiagNote(SecondMethod->getLocation(), |
| 9867 | SecondMethod->getSourceRange(), |
| 9868 | MethodParameterSingleDefaultArgument) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9869 | << SecondMethodType << SecondName << (I + 1) |
| 9870 | << (SecondInit == nullptr) |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9871 | << (SecondInit ? SecondInit->getSourceRange() : SourceRange()); |
| 9872 | ParameterMismatch = true; |
| 9873 | break; |
| 9874 | } |
| 9875 | |
| 9876 | if (FirstInit && SecondInit && |
| 9877 | ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) { |
| 9878 | ODRDiagError(FirstMethod->getLocation(), |
| 9879 | FirstMethod->getSourceRange(), |
| 9880 | MethodParameterDifferentDefaultArgument) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9881 | << FirstMethodType << FirstName << (I + 1) |
| 9882 | << FirstInit->getSourceRange(); |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9883 | ODRDiagNote(SecondMethod->getLocation(), |
| 9884 | SecondMethod->getSourceRange(), |
| 9885 | MethodParameterDifferentDefaultArgument) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9886 | << SecondMethodType << SecondName << (I + 1) |
| 9887 | << SecondInit->getSourceRange(); |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9888 | ParameterMismatch = true; |
| 9889 | break; |
| 9890 | |
| 9891 | } |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 9892 | } |
| 9893 | |
| 9894 | if (ParameterMismatch) { |
| 9895 | Diagnosed = true; |
| 9896 | break; |
| 9897 | } |
| 9898 | |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9899 | break; |
| 9900 | } |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 9901 | case TypeAlias: |
| 9902 | case TypeDef: { |
| 9903 | TypedefNameDecl *FirstTD = cast<TypedefNameDecl>(FirstDecl); |
| 9904 | TypedefNameDecl *SecondTD = cast<TypedefNameDecl>(SecondDecl); |
| 9905 | auto FirstName = FirstTD->getDeclName(); |
| 9906 | auto SecondName = SecondTD->getDeclName(); |
| 9907 | if (FirstName != SecondName) { |
| 9908 | ODRDiagError(FirstTD->getLocation(), FirstTD->getSourceRange(), |
| 9909 | TypedefName) |
| 9910 | << (FirstDiffType == TypeAlias) << FirstName; |
| 9911 | ODRDiagNote(SecondTD->getLocation(), SecondTD->getSourceRange(), |
| 9912 | TypedefName) |
| 9913 | << (FirstDiffType == TypeAlias) << SecondName; |
| 9914 | Diagnosed = true; |
| 9915 | break; |
| 9916 | } |
| 9917 | |
| 9918 | QualType FirstType = FirstTD->getUnderlyingType(); |
| 9919 | QualType SecondType = SecondTD->getUnderlyingType(); |
| 9920 | if (ComputeQualTypeODRHash(FirstType) != |
| 9921 | ComputeQualTypeODRHash(SecondType)) { |
| 9922 | ODRDiagError(FirstTD->getLocation(), FirstTD->getSourceRange(), |
| 9923 | TypedefType) |
| 9924 | << (FirstDiffType == TypeAlias) << FirstName << FirstType; |
| 9925 | ODRDiagNote(SecondTD->getLocation(), SecondTD->getSourceRange(), |
| 9926 | TypedefType) |
| 9927 | << (FirstDiffType == TypeAlias) << SecondName << SecondType; |
| 9928 | Diagnosed = true; |
| 9929 | break; |
| 9930 | } |
| 9931 | break; |
| 9932 | } |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9933 | case Var: { |
| 9934 | VarDecl *FirstVD = cast<VarDecl>(FirstDecl); |
| 9935 | VarDecl *SecondVD = cast<VarDecl>(SecondDecl); |
| 9936 | auto FirstName = FirstVD->getDeclName(); |
| 9937 | auto SecondName = SecondVD->getDeclName(); |
| 9938 | if (FirstName != SecondName) { |
| 9939 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 9940 | VarName) |
| 9941 | << FirstName; |
| 9942 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 9943 | VarName) |
| 9944 | << SecondName; |
| 9945 | Diagnosed = true; |
| 9946 | break; |
| 9947 | } |
| 9948 | |
| 9949 | QualType FirstType = FirstVD->getType(); |
| 9950 | QualType SecondType = SecondVD->getType(); |
| 9951 | if (ComputeQualTypeODRHash(FirstType) != |
| 9952 | ComputeQualTypeODRHash(SecondType)) { |
| 9953 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 9954 | VarType) |
| 9955 | << FirstName << FirstType; |
| 9956 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 9957 | VarType) |
| 9958 | << SecondName << SecondType; |
| 9959 | Diagnosed = true; |
| 9960 | break; |
| 9961 | } |
| 9962 | |
| 9963 | const Expr *FirstInit = FirstVD->getInit(); |
| 9964 | const Expr *SecondInit = SecondVD->getInit(); |
| 9965 | if ((FirstInit == nullptr) != (SecondInit == nullptr)) { |
| 9966 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 9967 | VarSingleInitializer) |
| 9968 | << FirstName << (FirstInit == nullptr) |
| 9969 | << (FirstInit ? FirstInit->getSourceRange(): SourceRange()); |
| 9970 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 9971 | VarSingleInitializer) |
| 9972 | << SecondName << (SecondInit == nullptr) |
| 9973 | << (SecondInit ? SecondInit->getSourceRange() : SourceRange()); |
| 9974 | Diagnosed = true; |
| 9975 | break; |
| 9976 | } |
| 9977 | |
| 9978 | if (FirstInit && SecondInit && |
| 9979 | ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) { |
| 9980 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 9981 | VarDifferentInitializer) |
| 9982 | << FirstName << FirstInit->getSourceRange(); |
| 9983 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 9984 | VarDifferentInitializer) |
| 9985 | << SecondName << SecondInit->getSourceRange(); |
| 9986 | Diagnosed = true; |
| 9987 | break; |
| 9988 | } |
| 9989 | |
| 9990 | const bool FirstIsConstexpr = FirstVD->isConstexpr(); |
| 9991 | const bool SecondIsConstexpr = SecondVD->isConstexpr(); |
| 9992 | if (FirstIsConstexpr != SecondIsConstexpr) { |
| 9993 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 9994 | VarConstexpr) |
| 9995 | << FirstName << FirstIsConstexpr; |
| 9996 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 9997 | VarConstexpr) |
| 9998 | << SecondName << SecondIsConstexpr; |
| 9999 | Diagnosed = true; |
| 10000 | break; |
| 10001 | } |
| 10002 | break; |
| 10003 | } |
Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 10004 | case Friend: { |
| 10005 | FriendDecl *FirstFriend = cast<FriendDecl>(FirstDecl); |
| 10006 | FriendDecl *SecondFriend = cast<FriendDecl>(SecondDecl); |
| 10007 | |
| 10008 | NamedDecl *FirstND = FirstFriend->getFriendDecl(); |
| 10009 | NamedDecl *SecondND = SecondFriend->getFriendDecl(); |
| 10010 | |
| 10011 | TypeSourceInfo *FirstTSI = FirstFriend->getFriendType(); |
| 10012 | TypeSourceInfo *SecondTSI = SecondFriend->getFriendType(); |
| 10013 | |
| 10014 | if (FirstND && SecondND) { |
| 10015 | ODRDiagError(FirstFriend->getFriendLoc(), |
| 10016 | FirstFriend->getSourceRange(), FriendFunction) |
| 10017 | << FirstND; |
| 10018 | ODRDiagNote(SecondFriend->getFriendLoc(), |
| 10019 | SecondFriend->getSourceRange(), FriendFunction) |
| 10020 | << SecondND; |
| 10021 | |
| 10022 | Diagnosed = true; |
| 10023 | break; |
| 10024 | } |
| 10025 | |
| 10026 | if (FirstTSI && SecondTSI) { |
| 10027 | QualType FirstFriendType = FirstTSI->getType(); |
| 10028 | QualType SecondFriendType = SecondTSI->getType(); |
| 10029 | assert(ComputeQualTypeODRHash(FirstFriendType) != |
| 10030 | ComputeQualTypeODRHash(SecondFriendType)); |
| 10031 | ODRDiagError(FirstFriend->getFriendLoc(), |
| 10032 | FirstFriend->getSourceRange(), FriendType) |
| 10033 | << FirstFriendType; |
| 10034 | ODRDiagNote(SecondFriend->getFriendLoc(), |
| 10035 | SecondFriend->getSourceRange(), FriendType) |
| 10036 | << SecondFriendType; |
| 10037 | Diagnosed = true; |
| 10038 | break; |
| 10039 | } |
| 10040 | |
| 10041 | ODRDiagError(FirstFriend->getFriendLoc(), FirstFriend->getSourceRange(), |
| 10042 | FriendTypeFunction) |
| 10043 | << (FirstTSI == nullptr); |
| 10044 | ODRDiagNote(SecondFriend->getFriendLoc(), |
| 10045 | SecondFriend->getSourceRange(), FriendTypeFunction) |
| 10046 | << (SecondTSI == nullptr); |
| 10047 | |
| 10048 | Diagnosed = true; |
| 10049 | break; |
| 10050 | } |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10051 | } |
| 10052 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 10053 | if (Diagnosed == true) |
| 10054 | continue; |
| 10055 | |
Richard Trieu | 708859a | 2017-06-08 00:56:21 +0000 | [diff] [blame] | 10056 | Diag(FirstDecl->getLocation(), |
| 10057 | diag::err_module_odr_violation_mismatch_decl_unknown) |
| 10058 | << FirstRecord << FirstModule.empty() << FirstModule << FirstDiffType |
| 10059 | << FirstDecl->getSourceRange(); |
| 10060 | Diag(SecondDecl->getLocation(), |
| 10061 | diag::note_module_odr_violation_mismatch_decl_unknown) |
| 10062 | << SecondModule << FirstDiffType << SecondDecl->getSourceRange(); |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 10063 | Diagnosed = true; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 10064 | } |
| 10065 | |
| 10066 | if (!Diagnosed) { |
| 10067 | // All definitions are updates to the same declaration. This happens if a |
| 10068 | // module instantiates the declaration of a class template specialization |
| 10069 | // and two or more other modules instantiate its definition. |
| 10070 | // |
| 10071 | // FIXME: Indicate which modules had instantiations of this definition. |
| 10072 | // FIXME: How can this even happen? |
| 10073 | Diag(Merge.first->getLocation(), |
| 10074 | diag::err_module_odr_violation_different_instantiations) |
| 10075 | << Merge.first; |
| 10076 | } |
| 10077 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10078 | } |
| 10079 | |
Richard Smith | ce18a18 | 2015-07-14 00:26:00 +0000 | [diff] [blame] | 10080 | void ASTReader::StartedDeserializing() { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 10081 | if (++NumCurrentElementsDeserializing == 1 && ReadTimer.get()) |
Richard Smith | ce18a18 | 2015-07-14 00:26:00 +0000 | [diff] [blame] | 10082 | ReadTimer->startTimer(); |
| 10083 | } |
| 10084 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10085 | void ASTReader::FinishedDeserializing() { |
| 10086 | assert(NumCurrentElementsDeserializing && |
| 10087 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 10088 | if (NumCurrentElementsDeserializing == 1) { |
| 10089 | // We decrease NumCurrentElementsDeserializing only after pending actions |
| 10090 | // are finished, to avoid recursively re-calling finishPendingActions(). |
| 10091 | finishPendingActions(); |
| 10092 | } |
| 10093 | --NumCurrentElementsDeserializing; |
| 10094 | |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 10095 | if (NumCurrentElementsDeserializing == 0) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 10096 | // Propagate exception specification updates along redeclaration chains. |
Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 10097 | while (!PendingExceptionSpecUpdates.empty()) { |
| 10098 | auto Updates = std::move(PendingExceptionSpecUpdates); |
| 10099 | PendingExceptionSpecUpdates.clear(); |
| 10100 | for (auto Update : Updates) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 10101 | ProcessingUpdatesRAIIObj ProcessingUpdates(*this); |
Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 10102 | auto *FPT = Update.second->getType()->castAs<FunctionProtoType>(); |
Richard Smith | 1d0f199 | 2015-08-19 21:09:32 +0000 | [diff] [blame] | 10103 | auto ESI = FPT->getExtProtoInfo().ExceptionSpec; |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 10104 | if (auto *Listener = getContext().getASTMutationListener()) |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 10105 | Listener->ResolvedExceptionSpec(cast<FunctionDecl>(Update.second)); |
Richard Smith | 1d0f199 | 2015-08-19 21:09:32 +0000 | [diff] [blame] | 10106 | for (auto *Redecl : Update.second->redecls()) |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 10107 | getContext().adjustExceptionSpec(cast<FunctionDecl>(Redecl), ESI); |
Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 10108 | } |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 10109 | } |
| 10110 | |
Richard Smith | ce18a18 | 2015-07-14 00:26:00 +0000 | [diff] [blame] | 10111 | if (ReadTimer) |
| 10112 | ReadTimer->stopTimer(); |
| 10113 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 10114 | diagnoseOdrViolations(); |
| 10115 | |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 10116 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 10117 | // decls to the consumer. |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 10118 | if (Consumer) |
| 10119 | PassInterestingDeclsToConsumer(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10120 | } |
| 10121 | } |
| 10122 | |
Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 10123 | void ASTReader::pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 10124 | if (IdentifierInfo *II = Name.getAsIdentifierInfo()) { |
| 10125 | // Remove any fake results before adding any real ones. |
| 10126 | auto It = PendingFakeLookupResults.find(II); |
| 10127 | if (It != PendingFakeLookupResults.end()) { |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 10128 | for (auto *ND : It->second) |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 10129 | SemaObj->IdResolver.RemoveDecl(ND); |
Ben Langmuir | eb8bd2d | 2015-04-10 22:25:42 +0000 | [diff] [blame] | 10130 | // FIXME: this works around module+PCH performance issue. |
| 10131 | // Rather than erase the result from the map, which is O(n), just clear |
| 10132 | // the vector of NamedDecls. |
| 10133 | It->second.clear(); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 10134 | } |
| 10135 | } |
Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 10136 | |
| 10137 | if (SemaObj->IdResolver.tryAddTopLevelDecl(D, Name) && SemaObj->TUScope) { |
| 10138 | SemaObj->TUScope->AddDecl(D); |
| 10139 | } else if (SemaObj->TUScope) { |
| 10140 | // Adding the decl to IdResolver may have failed because it was already in |
| 10141 | // (even though it was not added in scope). If it is already in, make sure |
| 10142 | // it gets in the scope as well. |
| 10143 | if (std::find(SemaObj->IdResolver.begin(Name), |
| 10144 | SemaObj->IdResolver.end(), D) != SemaObj->IdResolver.end()) |
| 10145 | SemaObj->TUScope->AddDecl(D); |
| 10146 | } |
| 10147 | } |
| 10148 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 10149 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 10150 | const PCHContainerReader &PCHContainerRdr, |
| 10151 | ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, |
| 10152 | StringRef isysroot, bool DisableValidation, |
| 10153 | bool AllowASTWithCompilerErrors, |
| 10154 | bool AllowConfigurationMismatch, bool ValidateSystemInputs, |
| 10155 | bool UseGlobalIndex, |
| 10156 | std::unique_ptr<llvm::Timer> ReadTimer) |
| 10157 | : Listener(DisableValidation |
| 10158 | ? cast<ASTReaderListener>(new SimpleASTReaderListener(PP)) |
| 10159 | : cast<ASTReaderListener>(new PCHValidator(PP, *this))), |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 10160 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
David Blaikie | 9d7c1ba | 2017-01-05 18:45:43 +0000 | [diff] [blame] | 10161 | PCHContainerRdr(PCHContainerRdr), Diags(PP.getDiagnostics()), PP(PP), |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 10162 | ContextObj(Context), |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 10163 | ModuleMgr(PP.getFileManager(), PP.getPCMCache(), PCHContainerRdr), |
| 10164 | PCMCache(PP.getPCMCache()), DummyIdResolver(PP), |
| 10165 | ReadTimer(std::move(ReadTimer)), isysroot(isysroot), |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 10166 | DisableValidation(DisableValidation), |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 10167 | AllowASTWithCompilerErrors(AllowASTWithCompilerErrors), |
| 10168 | AllowConfigurationMismatch(AllowConfigurationMismatch), |
| 10169 | ValidateSystemInputs(ValidateSystemInputs), |
David Blaikie | 9d7c1ba | 2017-01-05 18:45:43 +0000 | [diff] [blame] | 10170 | UseGlobalIndex(UseGlobalIndex), CurrSwitchCaseStmts(&SwitchCaseStmts) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10171 | SourceMgr.setExternalSLocEntrySource(this); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 10172 | |
| 10173 | for (const auto &Ext : Extensions) { |
| 10174 | auto BlockName = Ext->getExtensionMetadata().BlockName; |
| 10175 | auto Known = ModuleFileExtensions.find(BlockName); |
| 10176 | if (Known != ModuleFileExtensions.end()) { |
| 10177 | Diags.Report(diag::warn_duplicate_module_file_extension) |
| 10178 | << BlockName; |
| 10179 | continue; |
| 10180 | } |
| 10181 | |
| 10182 | ModuleFileExtensions.insert({BlockName, Ext}); |
| 10183 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10184 | } |
| 10185 | |
| 10186 | ASTReader::~ASTReader() { |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 10187 | if (OwnsDeserializationListener) |
| 10188 | delete DeserializationListener; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10189 | } |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 10190 | |
| 10191 | IdentifierResolver &ASTReader::getIdResolver() { |
| 10192 | return SemaObj ? SemaObj->IdResolver : DummyIdResolver; |
| 10193 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 10194 | |
| 10195 | unsigned ASTRecordReader::readRecord(llvm::BitstreamCursor &Cursor, |
| 10196 | unsigned AbbrevID) { |
| 10197 | Idx = 0; |
| 10198 | Record.clear(); |
| 10199 | return Cursor.readRecord(AbbrevID, Record); |
| 10200 | } |