Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +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" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclBase.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclCXX.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclFriend.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 25 | #include "clang/AST/DeclGroup.h" |
| 26 | #include "clang/AST/DeclObjC.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 27 | #include "clang/AST/DeclTemplate.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 28 | #include "clang/AST/DeclarationName.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 29 | #include "clang/AST/Expr.h" |
| 30 | #include "clang/AST/ExprCXX.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 31 | #include "clang/AST/ExternalASTSource.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 32 | #include "clang/AST/NestedNameSpecifier.h" |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 33 | #include "clang/AST/ODRHash.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 34 | #include "clang/AST/RawCommentList.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 35 | #include "clang/AST/TemplateBase.h" |
| 36 | #include "clang/AST/TemplateName.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 37 | #include "clang/AST/Type.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 38 | #include "clang/AST/TypeLoc.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 39 | #include "clang/AST/TypeLocVisitor.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 40 | #include "clang/AST/UnresolvedSet.h" |
| 41 | #include "clang/Basic/CommentOptions.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 42 | #include "clang/Basic/Diagnostic.h" |
Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 43 | #include "clang/Basic/DiagnosticOptions.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 44 | #include "clang/Basic/ExceptionSpecificationType.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 45 | #include "clang/Basic/FileManager.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 46 | #include "clang/Basic/FileSystemOptions.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 47 | #include "clang/Basic/IdentifierTable.h" |
| 48 | #include "clang/Basic/LLVM.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 49 | #include "clang/Basic/LangOptions.h" |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 50 | #include "clang/Basic/MemoryBufferCache.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 51 | #include "clang/Basic/Module.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 52 | #include "clang/Basic/ObjCRuntime.h" |
| 53 | #include "clang/Basic/OperatorKinds.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 54 | #include "clang/Basic/PragmaKinds.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 55 | #include "clang/Basic/Sanitizers.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 56 | #include "clang/Basic/SourceLocation.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 57 | #include "clang/Basic/SourceManager.h" |
| 58 | #include "clang/Basic/SourceManagerInternals.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 59 | #include "clang/Basic/Specifiers.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 60 | #include "clang/Basic/TargetInfo.h" |
| 61 | #include "clang/Basic/TargetOptions.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 62 | #include "clang/Basic/TokenKinds.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 63 | #include "clang/Basic/Version.h" |
| 64 | #include "clang/Basic/VersionTuple.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 65 | #include "clang/Frontend/PCHContainerOperations.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 66 | #include "clang/Lex/HeaderSearch.h" |
| 67 | #include "clang/Lex/HeaderSearchOptions.h" |
| 68 | #include "clang/Lex/MacroInfo.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 69 | #include "clang/Lex/ModuleMap.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 70 | #include "clang/Lex/PreprocessingRecord.h" |
| 71 | #include "clang/Lex/Preprocessor.h" |
| 72 | #include "clang/Lex/PreprocessorOptions.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 73 | #include "clang/Lex/Token.h" |
| 74 | #include "clang/Sema/ObjCMethodList.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 75 | #include "clang/Sema/Scope.h" |
| 76 | #include "clang/Sema/Sema.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 77 | #include "clang/Sema/Weak.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 78 | #include "clang/Serialization/ASTBitCodes.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 79 | #include "clang/Serialization/ASTDeserializationListener.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 80 | #include "clang/Serialization/ContinuousRangeMap.h" |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 81 | #include "clang/Serialization/GlobalModuleIndex.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 82 | #include "clang/Serialization/Module.h" |
| 83 | #include "clang/Serialization/ModuleFileExtension.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 84 | #include "clang/Serialization/ModuleManager.h" |
| 85 | #include "clang/Serialization/SerializationDiagnostic.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 86 | #include "llvm/ADT/APFloat.h" |
| 87 | #include "llvm/ADT/APInt.h" |
| 88 | #include "llvm/ADT/APSInt.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 89 | #include "llvm/ADT/ArrayRef.h" |
| 90 | #include "llvm/ADT/DenseMap.h" |
| 91 | #include "llvm/ADT/FoldingSet.h" |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 92 | #include "llvm/ADT/Hashing.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 93 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
| 94 | #include "llvm/ADT/None.h" |
| 95 | #include "llvm/ADT/Optional.h" |
| 96 | #include "llvm/ADT/STLExtras.h" |
| 97 | #include "llvm/ADT/SmallPtrSet.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 98 | #include "llvm/ADT/SmallString.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 99 | #include "llvm/ADT/SmallVector.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 100 | #include "llvm/ADT/StringExtras.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 101 | #include "llvm/ADT/StringMap.h" |
| 102 | #include "llvm/ADT/StringRef.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 103 | #include "llvm/ADT/Triple.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 104 | #include "llvm/ADT/iterator_range.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 105 | #include "llvm/Bitcode/BitstreamReader.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 106 | #include "llvm/Support/Casting.h" |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 107 | #include "llvm/Support/Compression.h" |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 108 | #include "llvm/Support/Compiler.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 109 | #include "llvm/Support/Endian.h" |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 110 | #include "llvm/Support/Error.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 111 | #include "llvm/Support/ErrorHandling.h" |
| 112 | #include "llvm/Support/FileSystem.h" |
| 113 | #include "llvm/Support/MemoryBuffer.h" |
| 114 | #include "llvm/Support/Path.h" |
| 115 | #include "llvm/Support/SaveAndRestore.h" |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 116 | #include "llvm/Support/Timer.h" |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 117 | #include "llvm/Support/raw_ostream.h" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 118 | #include <algorithm> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 119 | #include <cassert> |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 120 | #include <cstddef> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 121 | #include <cstdint> |
Chris Lattner | 91f373e | 2013-01-20 00:57:52 +0000 | [diff] [blame] | 122 | #include <cstdio> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 123 | #include <ctime> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 124 | #include <iterator> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 125 | #include <limits> |
| 126 | #include <map> |
| 127 | #include <memory> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 128 | #include <string> |
Rafael Espindola | 8a8e554 | 2014-06-12 17:19:42 +0000 | [diff] [blame] | 129 | #include <system_error> |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 130 | #include <tuple> |
| 131 | #include <utility> |
| 132 | #include <vector> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 133 | |
| 134 | using namespace clang; |
| 135 | using namespace clang::serialization; |
| 136 | using namespace clang::serialization::reader; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 137 | using llvm::BitstreamCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 138 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 139 | //===----------------------------------------------------------------------===// |
| 140 | // ChainedASTReaderListener implementation |
| 141 | //===----------------------------------------------------------------------===// |
| 142 | |
| 143 | bool |
| 144 | ChainedASTReaderListener::ReadFullVersionInformation(StringRef FullVersion) { |
| 145 | return First->ReadFullVersionInformation(FullVersion) || |
| 146 | Second->ReadFullVersionInformation(FullVersion); |
| 147 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 148 | |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 149 | void ChainedASTReaderListener::ReadModuleName(StringRef ModuleName) { |
| 150 | First->ReadModuleName(ModuleName); |
| 151 | Second->ReadModuleName(ModuleName); |
| 152 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 153 | |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 154 | void ChainedASTReaderListener::ReadModuleMapFile(StringRef ModuleMapPath) { |
| 155 | First->ReadModuleMapFile(ModuleMapPath); |
| 156 | Second->ReadModuleMapFile(ModuleMapPath); |
| 157 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 158 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 159 | bool |
| 160 | ChainedASTReaderListener::ReadLanguageOptions(const LangOptions &LangOpts, |
| 161 | bool Complain, |
| 162 | bool AllowCompatibleDifferences) { |
| 163 | return First->ReadLanguageOptions(LangOpts, Complain, |
| 164 | AllowCompatibleDifferences) || |
| 165 | Second->ReadLanguageOptions(LangOpts, Complain, |
| 166 | AllowCompatibleDifferences); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 167 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 168 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 169 | bool ChainedASTReaderListener::ReadTargetOptions( |
| 170 | const TargetOptions &TargetOpts, bool Complain, |
| 171 | bool AllowCompatibleDifferences) { |
| 172 | return First->ReadTargetOptions(TargetOpts, Complain, |
| 173 | AllowCompatibleDifferences) || |
| 174 | Second->ReadTargetOptions(TargetOpts, Complain, |
| 175 | AllowCompatibleDifferences); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 176 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 177 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 178 | bool ChainedASTReaderListener::ReadDiagnosticOptions( |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 179 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) { |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 180 | return First->ReadDiagnosticOptions(DiagOpts, Complain) || |
| 181 | Second->ReadDiagnosticOptions(DiagOpts, Complain); |
| 182 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 183 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 184 | bool |
| 185 | ChainedASTReaderListener::ReadFileSystemOptions(const FileSystemOptions &FSOpts, |
| 186 | bool Complain) { |
| 187 | return First->ReadFileSystemOptions(FSOpts, Complain) || |
| 188 | Second->ReadFileSystemOptions(FSOpts, Complain); |
| 189 | } |
| 190 | |
| 191 | bool ChainedASTReaderListener::ReadHeaderSearchOptions( |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 192 | const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, |
| 193 | bool Complain) { |
| 194 | return First->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 195 | Complain) || |
| 196 | Second->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 197 | Complain); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 198 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 199 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 200 | bool ChainedASTReaderListener::ReadPreprocessorOptions( |
| 201 | const PreprocessorOptions &PPOpts, bool Complain, |
| 202 | std::string &SuggestedPredefines) { |
| 203 | return First->ReadPreprocessorOptions(PPOpts, Complain, |
| 204 | SuggestedPredefines) || |
| 205 | Second->ReadPreprocessorOptions(PPOpts, Complain, SuggestedPredefines); |
| 206 | } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 207 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 208 | void ChainedASTReaderListener::ReadCounter(const serialization::ModuleFile &M, |
| 209 | unsigned Value) { |
| 210 | First->ReadCounter(M, Value); |
| 211 | Second->ReadCounter(M, Value); |
| 212 | } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 213 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 214 | bool ChainedASTReaderListener::needsInputFileVisitation() { |
| 215 | return First->needsInputFileVisitation() || |
| 216 | Second->needsInputFileVisitation(); |
| 217 | } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 218 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 219 | bool ChainedASTReaderListener::needsSystemInputFileVisitation() { |
| 220 | return First->needsSystemInputFileVisitation() || |
| 221 | Second->needsSystemInputFileVisitation(); |
| 222 | } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 223 | |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 224 | void ChainedASTReaderListener::visitModuleFile(StringRef Filename, |
| 225 | ModuleKind Kind) { |
| 226 | First->visitModuleFile(Filename, Kind); |
| 227 | Second->visitModuleFile(Filename, Kind); |
Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 228 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 229 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 230 | bool ChainedASTReaderListener::visitInputFile(StringRef Filename, |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 231 | bool isSystem, |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 232 | bool isOverridden, |
| 233 | bool isExplicitModule) { |
Justin Bogner | c65a66d | 2014-05-22 06:04:59 +0000 | [diff] [blame] | 234 | bool Continue = false; |
| 235 | if (First->needsInputFileVisitation() && |
| 236 | (!isSystem || First->needsSystemInputFileVisitation())) |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 237 | Continue |= First->visitInputFile(Filename, isSystem, isOverridden, |
| 238 | isExplicitModule); |
Justin Bogner | c65a66d | 2014-05-22 06:04:59 +0000 | [diff] [blame] | 239 | if (Second->needsInputFileVisitation() && |
| 240 | (!isSystem || Second->needsSystemInputFileVisitation())) |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 241 | Continue |= Second->visitInputFile(Filename, isSystem, isOverridden, |
| 242 | isExplicitModule); |
Justin Bogner | c65a66d | 2014-05-22 06:04:59 +0000 | [diff] [blame] | 243 | return Continue; |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 246 | void ChainedASTReaderListener::readModuleFileExtension( |
| 247 | const ModuleFileExtensionMetadata &Metadata) { |
| 248 | First->readModuleFileExtension(Metadata); |
| 249 | Second->readModuleFileExtension(Metadata); |
| 250 | } |
| 251 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 252 | //===----------------------------------------------------------------------===// |
| 253 | // PCH validator implementation |
| 254 | //===----------------------------------------------------------------------===// |
| 255 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 256 | ASTReaderListener::~ASTReaderListener() = default; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 257 | |
| 258 | /// \brief Compare the given set of language options against an existing set of |
| 259 | /// language options. |
| 260 | /// |
| 261 | /// \param Diags If non-NULL, diagnostics will be emitted via this engine. |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 262 | /// \param AllowCompatibleDifferences If true, differences between compatible |
| 263 | /// language options will be permitted. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 264 | /// |
| 265 | /// \returns true if the languagae options mis-match, false otherwise. |
| 266 | static bool checkLanguageOptions(const LangOptions &LangOpts, |
| 267 | const LangOptions &ExistingLangOpts, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 268 | DiagnosticsEngine *Diags, |
| 269 | bool AllowCompatibleDifferences = true) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 270 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 271 | if (ExistingLangOpts.Name != LangOpts.Name) { \ |
| 272 | if (Diags) \ |
| 273 | Diags->Report(diag::err_pch_langopt_mismatch) \ |
| 274 | << Description << LangOpts.Name << ExistingLangOpts.Name; \ |
| 275 | return true; \ |
| 276 | } |
| 277 | |
| 278 | #define VALUE_LANGOPT(Name, Bits, Default, Description) \ |
| 279 | if (ExistingLangOpts.Name != LangOpts.Name) { \ |
| 280 | if (Diags) \ |
| 281 | Diags->Report(diag::err_pch_langopt_value_mismatch) \ |
| 282 | << Description; \ |
| 283 | return true; \ |
| 284 | } |
| 285 | |
| 286 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 287 | if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \ |
| 288 | if (Diags) \ |
| 289 | Diags->Report(diag::err_pch_langopt_value_mismatch) \ |
| 290 | << Description; \ |
| 291 | return true; \ |
| 292 | } |
| 293 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 294 | #define COMPATIBLE_LANGOPT(Name, Bits, Default, Description) \ |
| 295 | if (!AllowCompatibleDifferences) \ |
| 296 | LANGOPT(Name, Bits, Default, Description) |
| 297 | |
| 298 | #define COMPATIBLE_ENUM_LANGOPT(Name, Bits, Default, Description) \ |
| 299 | if (!AllowCompatibleDifferences) \ |
| 300 | ENUM_LANGOPT(Name, Bits, Default, Description) |
| 301 | |
Richard Smith | a1ddf5e | 2016-04-07 20:47:37 +0000 | [diff] [blame] | 302 | #define COMPATIBLE_VALUE_LANGOPT(Name, Bits, Default, Description) \ |
| 303 | if (!AllowCompatibleDifferences) \ |
| 304 | VALUE_LANGOPT(Name, Bits, Default, Description) |
| 305 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 306 | #define BENIGN_LANGOPT(Name, Bits, Default, Description) |
| 307 | #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) |
Richard Smith | a1ddf5e | 2016-04-07 20:47:37 +0000 | [diff] [blame] | 308 | #define BENIGN_VALUE_LANGOPT(Name, Type, Bits, Default, Description) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 309 | #include "clang/Basic/LangOptions.def" |
| 310 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 311 | if (ExistingLangOpts.ModuleFeatures != LangOpts.ModuleFeatures) { |
| 312 | if (Diags) |
| 313 | Diags->Report(diag::err_pch_langopt_value_mismatch) << "module features"; |
| 314 | return true; |
| 315 | } |
| 316 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 317 | if (ExistingLangOpts.ObjCRuntime != LangOpts.ObjCRuntime) { |
| 318 | if (Diags) |
| 319 | Diags->Report(diag::err_pch_langopt_value_mismatch) |
| 320 | << "target Objective-C runtime"; |
| 321 | return true; |
| 322 | } |
| 323 | |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 324 | if (ExistingLangOpts.CommentOpts.BlockCommandNames != |
| 325 | LangOpts.CommentOpts.BlockCommandNames) { |
| 326 | if (Diags) |
| 327 | Diags->Report(diag::err_pch_langopt_value_mismatch) |
| 328 | << "block command names"; |
| 329 | return true; |
| 330 | } |
| 331 | |
Vedant Kumar | 85a83c2 | 2017-06-01 20:01:01 +0000 | [diff] [blame] | 332 | // Sanitizer feature mismatches are treated as compatible differences. If |
| 333 | // compatible differences aren't allowed, we still only want to check for |
| 334 | // mismatches of non-modular sanitizers (the only ones which can affect AST |
| 335 | // generation). |
| 336 | if (!AllowCompatibleDifferences) { |
| 337 | SanitizerMask ModularSanitizers = getPPTransparentSanitizers(); |
| 338 | SanitizerSet ExistingSanitizers = ExistingLangOpts.Sanitize; |
| 339 | SanitizerSet ImportedSanitizers = LangOpts.Sanitize; |
| 340 | ExistingSanitizers.clear(ModularSanitizers); |
| 341 | ImportedSanitizers.clear(ModularSanitizers); |
| 342 | if (ExistingSanitizers.Mask != ImportedSanitizers.Mask) { |
| 343 | const std::string Flag = "-fsanitize="; |
| 344 | if (Diags) { |
| 345 | #define SANITIZER(NAME, ID) \ |
| 346 | { \ |
| 347 | bool InExistingModule = ExistingSanitizers.has(SanitizerKind::ID); \ |
| 348 | bool InImportedModule = ImportedSanitizers.has(SanitizerKind::ID); \ |
| 349 | if (InExistingModule != InImportedModule) \ |
| 350 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) \ |
| 351 | << InExistingModule << (Flag + NAME); \ |
| 352 | } |
| 353 | #include "clang/Basic/Sanitizers.def" |
| 354 | } |
| 355 | return true; |
| 356 | } |
| 357 | } |
| 358 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 359 | return false; |
| 360 | } |
| 361 | |
| 362 | /// \brief Compare the given set of target options against an existing set of |
| 363 | /// target options. |
| 364 | /// |
| 365 | /// \param Diags If non-NULL, diagnostics will be emitted via this engine. |
| 366 | /// |
| 367 | /// \returns true if the target options mis-match, false otherwise. |
| 368 | static bool checkTargetOptions(const TargetOptions &TargetOpts, |
| 369 | const TargetOptions &ExistingTargetOpts, |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 370 | DiagnosticsEngine *Diags, |
| 371 | bool AllowCompatibleDifferences = true) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 372 | #define CHECK_TARGET_OPT(Field, Name) \ |
| 373 | if (TargetOpts.Field != ExistingTargetOpts.Field) { \ |
| 374 | if (Diags) \ |
| 375 | Diags->Report(diag::err_pch_targetopt_mismatch) \ |
| 376 | << Name << TargetOpts.Field << ExistingTargetOpts.Field; \ |
| 377 | return true; \ |
| 378 | } |
| 379 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 380 | // The triple and ABI must match exactly. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 381 | CHECK_TARGET_OPT(Triple, "target"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 382 | CHECK_TARGET_OPT(ABI, "target ABI"); |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 383 | |
| 384 | // We can tolerate different CPUs in many cases, notably when one CPU |
| 385 | // supports a strict superset of another. When allowing compatible |
| 386 | // differences skip this check. |
| 387 | if (!AllowCompatibleDifferences) |
| 388 | CHECK_TARGET_OPT(CPU, "target CPU"); |
| 389 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 390 | #undef CHECK_TARGET_OPT |
| 391 | |
| 392 | // Compare feature sets. |
| 393 | SmallVector<StringRef, 4> ExistingFeatures( |
| 394 | ExistingTargetOpts.FeaturesAsWritten.begin(), |
| 395 | ExistingTargetOpts.FeaturesAsWritten.end()); |
| 396 | SmallVector<StringRef, 4> ReadFeatures(TargetOpts.FeaturesAsWritten.begin(), |
| 397 | TargetOpts.FeaturesAsWritten.end()); |
| 398 | std::sort(ExistingFeatures.begin(), ExistingFeatures.end()); |
| 399 | std::sort(ReadFeatures.begin(), ReadFeatures.end()); |
| 400 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 401 | // We compute the set difference in both directions explicitly so that we can |
| 402 | // diagnose the differences differently. |
| 403 | SmallVector<StringRef, 4> UnmatchedExistingFeatures, UnmatchedReadFeatures; |
| 404 | std::set_difference( |
| 405 | ExistingFeatures.begin(), ExistingFeatures.end(), ReadFeatures.begin(), |
| 406 | ReadFeatures.end(), std::back_inserter(UnmatchedExistingFeatures)); |
| 407 | std::set_difference(ReadFeatures.begin(), ReadFeatures.end(), |
| 408 | ExistingFeatures.begin(), ExistingFeatures.end(), |
| 409 | std::back_inserter(UnmatchedReadFeatures)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 410 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 411 | // If we are allowing compatible differences and the read feature set is |
| 412 | // a strict subset of the existing feature set, there is nothing to diagnose. |
| 413 | if (AllowCompatibleDifferences && UnmatchedReadFeatures.empty()) |
| 414 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 415 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 416 | if (Diags) { |
| 417 | for (StringRef Feature : UnmatchedReadFeatures) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 418 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 419 | << /* is-existing-feature */ false << Feature; |
| 420 | for (StringRef Feature : UnmatchedExistingFeatures) |
| 421 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
| 422 | << /* is-existing-feature */ true << Feature; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 423 | } |
| 424 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 425 | return !UnmatchedReadFeatures.empty() || !UnmatchedExistingFeatures.empty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | bool |
| 429 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 430 | bool Complain, |
| 431 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 432 | const LangOptions &ExistingLangOpts = PP.getLangOpts(); |
| 433 | return checkLanguageOptions(LangOpts, ExistingLangOpts, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 434 | Complain ? &Reader.Diags : nullptr, |
| 435 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | bool PCHValidator::ReadTargetOptions(const TargetOptions &TargetOpts, |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 439 | bool Complain, |
| 440 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 441 | const TargetOptions &ExistingTargetOpts = PP.getTargetInfo().getTargetOpts(); |
| 442 | return checkTargetOptions(TargetOpts, ExistingTargetOpts, |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 443 | Complain ? &Reader.Diags : nullptr, |
| 444 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 448 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 449 | using MacroDefinitionsMap = |
| 450 | llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/>>; |
| 451 | using DeclsMap = llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8>>; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 452 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 453 | } // namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 454 | |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 455 | static bool checkDiagnosticGroupMappings(DiagnosticsEngine &StoredDiags, |
| 456 | DiagnosticsEngine &Diags, |
| 457 | bool Complain) { |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 458 | using Level = DiagnosticsEngine::Level; |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 459 | |
| 460 | // Check current mappings for new -Werror mappings, and the stored mappings |
| 461 | // for cases that were explicitly mapped to *not* be errors that are now |
| 462 | // errors because of options like -Werror. |
| 463 | DiagnosticsEngine *MappingSources[] = { &Diags, &StoredDiags }; |
| 464 | |
| 465 | for (DiagnosticsEngine *MappingSource : MappingSources) { |
| 466 | for (auto DiagIDMappingPair : MappingSource->getDiagnosticMappings()) { |
| 467 | diag::kind DiagID = DiagIDMappingPair.first; |
| 468 | Level CurLevel = Diags.getDiagnosticLevel(DiagID, SourceLocation()); |
| 469 | if (CurLevel < DiagnosticsEngine::Error) |
| 470 | continue; // not significant |
| 471 | Level StoredLevel = |
| 472 | StoredDiags.getDiagnosticLevel(DiagID, SourceLocation()); |
| 473 | if (StoredLevel < DiagnosticsEngine::Error) { |
| 474 | if (Complain) |
| 475 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror=" + |
| 476 | Diags.getDiagnosticIDs()->getWarningOptionForDiag(DiagID).str(); |
| 477 | return true; |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | return false; |
| 483 | } |
| 484 | |
Alp Toker | ac4e8e5 | 2014-06-22 21:58:33 +0000 | [diff] [blame] | 485 | static bool isExtHandlingFromDiagsError(DiagnosticsEngine &Diags) { |
| 486 | diag::Severity Ext = Diags.getExtensionHandlingBehavior(); |
| 487 | if (Ext == diag::Severity::Warning && Diags.getWarningsAsErrors()) |
| 488 | return true; |
| 489 | return Ext >= diag::Severity::Error; |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | static bool checkDiagnosticMappings(DiagnosticsEngine &StoredDiags, |
| 493 | DiagnosticsEngine &Diags, |
| 494 | bool IsSystem, bool Complain) { |
| 495 | // Top-level options |
| 496 | if (IsSystem) { |
| 497 | if (Diags.getSuppressSystemWarnings()) |
| 498 | return false; |
| 499 | // If -Wsystem-headers was not enabled before, be conservative |
| 500 | if (StoredDiags.getSuppressSystemWarnings()) { |
| 501 | if (Complain) |
| 502 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Wsystem-headers"; |
| 503 | return true; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | if (Diags.getWarningsAsErrors() && !StoredDiags.getWarningsAsErrors()) { |
| 508 | if (Complain) |
| 509 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror"; |
| 510 | return true; |
| 511 | } |
| 512 | |
| 513 | if (Diags.getWarningsAsErrors() && Diags.getEnableAllWarnings() && |
| 514 | !StoredDiags.getEnableAllWarnings()) { |
| 515 | if (Complain) |
| 516 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Weverything -Werror"; |
| 517 | return true; |
| 518 | } |
| 519 | |
| 520 | if (isExtHandlingFromDiagsError(Diags) && |
| 521 | !isExtHandlingFromDiagsError(StoredDiags)) { |
| 522 | if (Complain) |
| 523 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-pedantic-errors"; |
| 524 | return true; |
| 525 | } |
| 526 | |
| 527 | return checkDiagnosticGroupMappings(StoredDiags, Diags, Complain); |
| 528 | } |
| 529 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 530 | /// Return the top import module if it is implicit, nullptr otherwise. |
| 531 | static Module *getTopImportImplicitModule(ModuleManager &ModuleMgr, |
| 532 | Preprocessor &PP) { |
| 533 | // If the original import came from a file explicitly generated by the user, |
| 534 | // don't check the diagnostic mappings. |
| 535 | // FIXME: currently this is approximated by checking whether this is not a |
| 536 | // module import of an implicitly-loaded module file. |
| 537 | // Note: ModuleMgr.rbegin() may not be the current module, but it must be in |
| 538 | // the transitive closure of its imports, since unrelated modules cannot be |
| 539 | // imported until after this module finishes validation. |
| 540 | ModuleFile *TopImport = &*ModuleMgr.rbegin(); |
| 541 | while (!TopImport->ImportedBy.empty()) |
| 542 | TopImport = TopImport->ImportedBy[0]; |
| 543 | if (TopImport->Kind != MK_ImplicitModule) |
| 544 | return nullptr; |
| 545 | |
| 546 | StringRef ModuleName = TopImport->ModuleName; |
| 547 | assert(!ModuleName.empty() && "diagnostic options read before module name"); |
| 548 | |
| 549 | Module *M = PP.getHeaderSearchInfo().lookupModule(ModuleName); |
| 550 | assert(M && "missing module"); |
| 551 | return M; |
| 552 | } |
| 553 | |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 554 | bool PCHValidator::ReadDiagnosticOptions( |
| 555 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) { |
| 556 | DiagnosticsEngine &ExistingDiags = PP.getDiagnostics(); |
| 557 | IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(ExistingDiags.getDiagnosticIDs()); |
| 558 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags( |
Alp Toker | f994cef | 2014-07-05 03:08:06 +0000 | [diff] [blame] | 559 | new DiagnosticsEngine(DiagIDs, DiagOpts.get())); |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 560 | // This should never fail, because we would have processed these options |
| 561 | // before writing them to an ASTFile. |
| 562 | ProcessWarningOptions(*Diags, *DiagOpts, /*Report*/false); |
| 563 | |
| 564 | ModuleManager &ModuleMgr = Reader.getModuleManager(); |
| 565 | assert(ModuleMgr.size() >= 1 && "what ASTFile is this then"); |
| 566 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 567 | Module *TopM = getTopImportImplicitModule(ModuleMgr, PP); |
| 568 | if (!TopM) |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 569 | return false; |
| 570 | |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 571 | // FIXME: if the diagnostics are incompatible, save a DiagnosticOptions that |
| 572 | // contains the union of their flags. |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 573 | return checkDiagnosticMappings(*Diags, ExistingDiags, TopM->IsSystem, |
| 574 | Complain); |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 577 | /// \brief Collect the macro definitions provided by the given preprocessor |
| 578 | /// options. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 579 | static void |
| 580 | collectMacroDefinitions(const PreprocessorOptions &PPOpts, |
| 581 | MacroDefinitionsMap &Macros, |
| 582 | SmallVectorImpl<StringRef> *MacroNames = nullptr) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 583 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 584 | StringRef Macro = PPOpts.Macros[I].first; |
| 585 | bool IsUndef = PPOpts.Macros[I].second; |
| 586 | |
| 587 | std::pair<StringRef, StringRef> MacroPair = Macro.split('='); |
| 588 | StringRef MacroName = MacroPair.first; |
| 589 | StringRef MacroBody = MacroPair.second; |
| 590 | |
| 591 | // For an #undef'd macro, we only care about the name. |
| 592 | if (IsUndef) { |
| 593 | if (MacroNames && !Macros.count(MacroName)) |
| 594 | MacroNames->push_back(MacroName); |
| 595 | |
| 596 | Macros[MacroName] = std::make_pair("", true); |
| 597 | continue; |
| 598 | } |
| 599 | |
| 600 | // For a #define'd macro, figure out the actual definition. |
| 601 | if (MacroName.size() == Macro.size()) |
| 602 | MacroBody = "1"; |
| 603 | else { |
| 604 | // Note: GCC drops anything following an end-of-line character. |
| 605 | StringRef::size_type End = MacroBody.find_first_of("\n\r"); |
| 606 | MacroBody = MacroBody.substr(0, End); |
| 607 | } |
| 608 | |
| 609 | if (MacroNames && !Macros.count(MacroName)) |
| 610 | MacroNames->push_back(MacroName); |
| 611 | Macros[MacroName] = std::make_pair(MacroBody, false); |
| 612 | } |
| 613 | } |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 614 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 615 | /// \brief Check the preprocessor options deserialized from the control block |
| 616 | /// against the preprocessor options in an existing preprocessor. |
| 617 | /// |
| 618 | /// \param Diags If non-null, produce diagnostics for any mismatches incurred. |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 619 | /// \param Validate If true, validate preprocessor options. If false, allow |
| 620 | /// macros defined by \p ExistingPPOpts to override those defined by |
| 621 | /// \p PPOpts in SuggestedPredefines. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 622 | static bool checkPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 623 | const PreprocessorOptions &ExistingPPOpts, |
| 624 | DiagnosticsEngine *Diags, |
| 625 | FileManager &FileMgr, |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 626 | std::string &SuggestedPredefines, |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 627 | const LangOptions &LangOpts, |
| 628 | bool Validate = true) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 629 | // Check macro definitions. |
| 630 | MacroDefinitionsMap ASTFileMacros; |
| 631 | collectMacroDefinitions(PPOpts, ASTFileMacros); |
| 632 | MacroDefinitionsMap ExistingMacros; |
| 633 | SmallVector<StringRef, 4> ExistingMacroNames; |
| 634 | collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames); |
| 635 | |
| 636 | for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) { |
| 637 | // Dig out the macro definition in the existing preprocessor options. |
| 638 | StringRef MacroName = ExistingMacroNames[I]; |
| 639 | std::pair<StringRef, bool> Existing = ExistingMacros[MacroName]; |
| 640 | |
| 641 | // Check whether we know anything about this macro name or not. |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 642 | llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/>>::iterator Known = |
| 643 | ASTFileMacros.find(MacroName); |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 644 | if (!Validate || Known == ASTFileMacros.end()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 645 | // FIXME: Check whether this identifier was referenced anywhere in the |
| 646 | // AST file. If so, we should reject the AST file. Unfortunately, this |
| 647 | // information isn't in the control block. What shall we do about it? |
| 648 | |
| 649 | if (Existing.second) { |
| 650 | SuggestedPredefines += "#undef "; |
| 651 | SuggestedPredefines += MacroName.str(); |
| 652 | SuggestedPredefines += '\n'; |
| 653 | } else { |
| 654 | SuggestedPredefines += "#define "; |
| 655 | SuggestedPredefines += MacroName.str(); |
| 656 | SuggestedPredefines += ' '; |
| 657 | SuggestedPredefines += Existing.first.str(); |
| 658 | SuggestedPredefines += '\n'; |
| 659 | } |
| 660 | continue; |
| 661 | } |
| 662 | |
| 663 | // If the macro was defined in one but undef'd in the other, we have a |
| 664 | // conflict. |
| 665 | if (Existing.second != Known->second.second) { |
| 666 | if (Diags) { |
| 667 | Diags->Report(diag::err_pch_macro_def_undef) |
| 668 | << MacroName << Known->second.second; |
| 669 | } |
| 670 | return true; |
| 671 | } |
| 672 | |
| 673 | // If the macro was #undef'd in both, or if the macro bodies are identical, |
| 674 | // it's fine. |
| 675 | if (Existing.second || Existing.first == Known->second.first) |
| 676 | continue; |
| 677 | |
| 678 | // The macro bodies differ; complain. |
| 679 | if (Diags) { |
| 680 | Diags->Report(diag::err_pch_macro_def_conflict) |
| 681 | << MacroName << Known->second.first << Existing.first; |
| 682 | } |
| 683 | return true; |
| 684 | } |
| 685 | |
| 686 | // Check whether we're using predefines. |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 687 | if (PPOpts.UsePredefines != ExistingPPOpts.UsePredefines && Validate) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 688 | if (Diags) { |
| 689 | Diags->Report(diag::err_pch_undef) << ExistingPPOpts.UsePredefines; |
| 690 | } |
| 691 | return true; |
| 692 | } |
| 693 | |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 694 | // Detailed record is important since it is used for the module cache hash. |
| 695 | if (LangOpts.Modules && |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 696 | PPOpts.DetailedRecord != ExistingPPOpts.DetailedRecord && Validate) { |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 697 | if (Diags) { |
| 698 | Diags->Report(diag::err_pch_pp_detailed_record) << PPOpts.DetailedRecord; |
| 699 | } |
| 700 | return true; |
| 701 | } |
| 702 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 703 | // Compute the #include and #include_macros lines we need. |
| 704 | for (unsigned I = 0, N = ExistingPPOpts.Includes.size(); I != N; ++I) { |
| 705 | StringRef File = ExistingPPOpts.Includes[I]; |
| 706 | if (File == ExistingPPOpts.ImplicitPCHInclude) |
| 707 | continue; |
| 708 | |
| 709 | if (std::find(PPOpts.Includes.begin(), PPOpts.Includes.end(), File) |
| 710 | != PPOpts.Includes.end()) |
| 711 | continue; |
| 712 | |
| 713 | SuggestedPredefines += "#include \""; |
Manuel Klimek | 9af34ae | 2014-08-12 08:25:57 +0000 | [diff] [blame] | 714 | SuggestedPredefines += File; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 715 | SuggestedPredefines += "\"\n"; |
| 716 | } |
| 717 | |
| 718 | for (unsigned I = 0, N = ExistingPPOpts.MacroIncludes.size(); I != N; ++I) { |
| 719 | StringRef File = ExistingPPOpts.MacroIncludes[I]; |
| 720 | if (std::find(PPOpts.MacroIncludes.begin(), PPOpts.MacroIncludes.end(), |
| 721 | File) |
| 722 | != PPOpts.MacroIncludes.end()) |
| 723 | continue; |
| 724 | |
| 725 | SuggestedPredefines += "#__include_macros \""; |
Manuel Klimek | 9af34ae | 2014-08-12 08:25:57 +0000 | [diff] [blame] | 726 | SuggestedPredefines += File; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 727 | SuggestedPredefines += "\"\n##\n"; |
| 728 | } |
| 729 | |
| 730 | return false; |
| 731 | } |
| 732 | |
| 733 | bool PCHValidator::ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 734 | bool Complain, |
| 735 | std::string &SuggestedPredefines) { |
| 736 | const PreprocessorOptions &ExistingPPOpts = PP.getPreprocessorOpts(); |
| 737 | |
| 738 | return checkPreprocessorOptions(PPOpts, ExistingPPOpts, |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 739 | Complain? &Reader.Diags : nullptr, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 740 | PP.getFileManager(), |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 741 | SuggestedPredefines, |
| 742 | PP.getLangOpts()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 743 | } |
| 744 | |
Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 745 | bool SimpleASTReaderListener::ReadPreprocessorOptions( |
| 746 | const PreprocessorOptions &PPOpts, |
| 747 | bool Complain, |
| 748 | std::string &SuggestedPredefines) { |
| 749 | return checkPreprocessorOptions(PPOpts, |
| 750 | PP.getPreprocessorOpts(), |
| 751 | nullptr, |
| 752 | PP.getFileManager(), |
| 753 | SuggestedPredefines, |
| 754 | PP.getLangOpts(), |
| 755 | false); |
| 756 | } |
| 757 | |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 758 | /// Check the header search options deserialized from the control block |
| 759 | /// against the header search options in an existing preprocessor. |
| 760 | /// |
| 761 | /// \param Diags If non-null, produce diagnostics for any mismatches incurred. |
| 762 | static bool checkHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 763 | StringRef SpecificModuleCachePath, |
| 764 | StringRef ExistingModuleCachePath, |
| 765 | DiagnosticsEngine *Diags, |
| 766 | const LangOptions &LangOpts) { |
| 767 | if (LangOpts.Modules) { |
| 768 | if (SpecificModuleCachePath != ExistingModuleCachePath) { |
| 769 | if (Diags) |
| 770 | Diags->Report(diag::err_pch_modulecache_mismatch) |
| 771 | << SpecificModuleCachePath << ExistingModuleCachePath; |
| 772 | return true; |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | return false; |
| 777 | } |
| 778 | |
| 779 | bool PCHValidator::ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 780 | StringRef SpecificModuleCachePath, |
| 781 | bool Complain) { |
| 782 | return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 783 | PP.getHeaderSearchInfo().getModuleCachePath(), |
| 784 | Complain ? &Reader.Diags : nullptr, |
| 785 | PP.getLangOpts()); |
| 786 | } |
| 787 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 788 | void PCHValidator::ReadCounter(const ModuleFile &M, unsigned Value) { |
| 789 | PP.setCounterValue(Value); |
| 790 | } |
| 791 | |
| 792 | //===----------------------------------------------------------------------===// |
| 793 | // AST reader implementation |
| 794 | //===----------------------------------------------------------------------===// |
| 795 | |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 796 | void ASTReader::setDeserializationListener(ASTDeserializationListener *Listener, |
| 797 | bool TakeOwnership) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 798 | DeserializationListener = Listener; |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 799 | OwnsDeserializationListener = TakeOwnership; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 800 | } |
| 801 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 802 | unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { |
| 803 | return serialization::ComputeHash(Sel); |
| 804 | } |
| 805 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 806 | std::pair<unsigned, unsigned> |
| 807 | ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 808 | using namespace llvm::support; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 809 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 810 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 811 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 812 | return std::make_pair(KeyLen, DataLen); |
| 813 | } |
| 814 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 815 | ASTSelectorLookupTrait::internal_key_type |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 816 | ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 817 | using namespace llvm::support; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 818 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 819 | SelectorTable &SelTable = Reader.getContext().Selectors; |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 820 | unsigned N = endian::readNext<uint16_t, little, unaligned>(d); |
| 821 | IdentifierInfo *FirstII = Reader.getLocalIdentifier( |
| 822 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 823 | if (N == 0) |
| 824 | return SelTable.getNullarySelector(FirstII); |
| 825 | else if (N == 1) |
| 826 | return SelTable.getUnarySelector(FirstII); |
| 827 | |
| 828 | SmallVector<IdentifierInfo *, 16> Args; |
| 829 | Args.push_back(FirstII); |
| 830 | for (unsigned I = 1; I != N; ++I) |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 831 | Args.push_back(Reader.getLocalIdentifier( |
| 832 | F, endian::readNext<uint32_t, little, unaligned>(d))); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 833 | |
| 834 | return SelTable.getSelector(N, Args.data()); |
| 835 | } |
| 836 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 837 | ASTSelectorLookupTrait::data_type |
| 838 | ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 839 | unsigned DataLen) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 840 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 841 | |
| 842 | data_type Result; |
| 843 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 844 | Result.ID = Reader.getGlobalSelectorID( |
| 845 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 846 | unsigned FullInstanceBits = endian::readNext<uint16_t, little, unaligned>(d); |
| 847 | unsigned FullFactoryBits = endian::readNext<uint16_t, little, unaligned>(d); |
| 848 | Result.InstanceBits = FullInstanceBits & 0x3; |
| 849 | Result.InstanceHasMoreThanOneDecl = (FullInstanceBits >> 2) & 0x1; |
| 850 | Result.FactoryBits = FullFactoryBits & 0x3; |
| 851 | Result.FactoryHasMoreThanOneDecl = (FullFactoryBits >> 2) & 0x1; |
| 852 | unsigned NumInstanceMethods = FullInstanceBits >> 3; |
| 853 | unsigned NumFactoryMethods = FullFactoryBits >> 3; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 854 | |
| 855 | // Load instance methods |
| 856 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 857 | if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>( |
| 858 | F, endian::readNext<uint32_t, little, unaligned>(d))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 859 | Result.Instance.push_back(Method); |
| 860 | } |
| 861 | |
| 862 | // Load factory methods |
| 863 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 864 | if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>( |
| 865 | F, endian::readNext<uint32_t, little, unaligned>(d))) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 866 | Result.Factory.push_back(Method); |
| 867 | } |
| 868 | |
| 869 | return Result; |
| 870 | } |
| 871 | |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 872 | unsigned ASTIdentifierLookupTraitBase::ComputeHash(const internal_key_type& a) { |
| 873 | return llvm::HashString(a); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | std::pair<unsigned, unsigned> |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 877 | ASTIdentifierLookupTraitBase::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 878 | using namespace llvm::support; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 879 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 880 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 881 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 882 | return std::make_pair(KeyLen, DataLen); |
| 883 | } |
| 884 | |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 885 | ASTIdentifierLookupTraitBase::internal_key_type |
| 886 | ASTIdentifierLookupTraitBase::ReadKey(const unsigned char* d, unsigned n) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 887 | assert(n >= 2 && d[n-1] == '\0'); |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 888 | return StringRef((const char*) d, n-1); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 889 | } |
| 890 | |
Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 891 | /// \brief Whether the given identifier is "interesting". |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 892 | static bool isInterestingIdentifier(ASTReader &Reader, IdentifierInfo &II, |
| 893 | bool IsModule) { |
Richard Smith | cab8980 | 2015-07-17 20:19:56 +0000 | [diff] [blame] | 894 | return II.hadMacroDefinition() || |
| 895 | II.isPoisoned() || |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 896 | (IsModule ? II.hasRevertedBuiltin() : II.getObjCOrBuiltinID()) || |
Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 897 | II.hasRevertedTokenIDToIdentifier() || |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 898 | (!(IsModule && Reader.getPreprocessor().getLangOpts().CPlusPlus) && |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 899 | II.getFETokenInfo<void>()); |
Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 902 | static bool readBit(unsigned &Bits) { |
| 903 | bool Value = Bits & 0x1; |
| 904 | Bits >>= 1; |
| 905 | return Value; |
| 906 | } |
| 907 | |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 908 | IdentID ASTIdentifierLookupTrait::ReadIdentifierID(const unsigned char *d) { |
| 909 | using namespace llvm::support; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 910 | |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 911 | unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d); |
| 912 | return Reader.getGlobalIdentifierID(F, RawID >> 1); |
| 913 | } |
| 914 | |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 915 | static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II) { |
| 916 | if (!II.isFromAST()) { |
| 917 | II.setIsFromAST(); |
| 918 | bool IsModule = Reader.getPreprocessor().getCurrentModule() != nullptr; |
| 919 | if (isInterestingIdentifier(Reader, II, IsModule)) |
| 920 | II.setChangedSinceDeserialization(); |
| 921 | } |
| 922 | } |
| 923 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 924 | IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, |
| 925 | const unsigned char* d, |
| 926 | unsigned DataLen) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 927 | using namespace llvm::support; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 928 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 929 | unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 930 | bool IsInteresting = RawID & 0x01; |
| 931 | |
| 932 | // Wipe out the "is interesting" bit. |
| 933 | RawID = RawID >> 1; |
| 934 | |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 935 | // Build the IdentifierInfo and link the identifier ID with it. |
| 936 | IdentifierInfo *II = KnownII; |
| 937 | if (!II) { |
| 938 | II = &Reader.getIdentifierTable().getOwn(k); |
| 939 | KnownII = II; |
| 940 | } |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 941 | markIdentifierFromAST(Reader, *II); |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 942 | Reader.markIdentifierUpToDate(II); |
| 943 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 944 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
| 945 | if (!IsInteresting) { |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 946 | // For uninteresting identifiers, there's nothing else to do. Just notify |
| 947 | // the reader that we've finished loading this identifier. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 948 | Reader.SetIdentifierInfo(ID, II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 949 | return II; |
| 950 | } |
| 951 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 952 | unsigned ObjCOrBuiltinID = endian::readNext<uint16_t, little, unaligned>(d); |
| 953 | unsigned Bits = endian::readNext<uint16_t, little, unaligned>(d); |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 954 | bool CPlusPlusOperatorKeyword = readBit(Bits); |
| 955 | bool HasRevertedTokenIDToIdentifier = readBit(Bits); |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 956 | bool HasRevertedBuiltin = readBit(Bits); |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 957 | bool Poisoned = readBit(Bits); |
| 958 | bool ExtensionToken = readBit(Bits); |
| 959 | bool HadMacroDefinition = readBit(Bits); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 960 | |
| 961 | assert(Bits == 0 && "Extra bits in the identifier?"); |
| 962 | DataLen -= 8; |
| 963 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 964 | // Set or check the various bits in the IdentifierInfo structure. |
| 965 | // Token IDs are read-only. |
Argyrios Kyrtzidis | ddee8c9 | 2013-02-27 01:13:51 +0000 | [diff] [blame] | 966 | if (HasRevertedTokenIDToIdentifier && II->getTokenID() != tok::identifier) |
Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 967 | II->revertTokenIDToIdentifier(); |
| 968 | if (!F.isModule()) |
| 969 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 970 | else if (HasRevertedBuiltin && II->getBuiltinID()) { |
| 971 | II->revertBuiltin(); |
| 972 | assert((II->hasRevertedBuiltin() || |
| 973 | II->getObjCOrBuiltinID() == ObjCOrBuiltinID) && |
| 974 | "Incorrect ObjC keyword or builtin ID"); |
| 975 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 976 | assert(II->isExtensionToken() == ExtensionToken && |
| 977 | "Incorrect extension token flag"); |
| 978 | (void)ExtensionToken; |
| 979 | if (Poisoned) |
| 980 | II->setIsPoisoned(true); |
| 981 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 982 | "Incorrect C++ operator keyword flag"); |
| 983 | (void)CPlusPlusOperatorKeyword; |
| 984 | |
| 985 | // If this identifier is a macro, deserialize the macro |
| 986 | // definition. |
Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 987 | if (HadMacroDefinition) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 988 | uint32_t MacroDirectivesOffset = |
| 989 | endian::readNext<uint32_t, little, unaligned>(d); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 990 | DataLen -= 4; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 991 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 992 | Reader.addPendingMacro(II, &F, MacroDirectivesOffset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | Reader.SetIdentifierInfo(ID, II); |
| 996 | |
| 997 | // Read all of the declarations visible at global scope with this |
| 998 | // name. |
| 999 | if (DataLen > 0) { |
| 1000 | SmallVector<uint32_t, 4> DeclIDs; |
| 1001 | for (; DataLen > 0; DataLen -= 4) |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1002 | DeclIDs.push_back(Reader.getGlobalDeclID( |
| 1003 | F, endian::readNext<uint32_t, little, unaligned>(d))); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1004 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
| 1005 | } |
| 1006 | |
| 1007 | return II; |
| 1008 | } |
| 1009 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1010 | DeclarationNameKey::DeclarationNameKey(DeclarationName Name) |
| 1011 | : Kind(Name.getNameKind()) { |
| 1012 | switch (Kind) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1013 | case DeclarationName::Identifier: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1014 | Data = (uint64_t)Name.getAsIdentifierInfo(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1015 | break; |
| 1016 | case DeclarationName::ObjCZeroArgSelector: |
| 1017 | case DeclarationName::ObjCOneArgSelector: |
| 1018 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1019 | Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1020 | break; |
| 1021 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1022 | Data = Name.getCXXOverloadedOperator(); |
| 1023 | break; |
| 1024 | case DeclarationName::CXXLiteralOperatorName: |
| 1025 | Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 1026 | break; |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1027 | case DeclarationName::CXXDeductionGuideName: |
| 1028 | Data = (uint64_t)Name.getCXXDeductionGuideTemplate() |
| 1029 | ->getDeclName().getAsIdentifierInfo(); |
| 1030 | break; |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1031 | case DeclarationName::CXXConstructorName: |
| 1032 | case DeclarationName::CXXDestructorName: |
| 1033 | case DeclarationName::CXXConversionFunctionName: |
| 1034 | case DeclarationName::CXXUsingDirective: |
| 1035 | Data = 0; |
| 1036 | break; |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | unsigned DeclarationNameKey::getHash() const { |
| 1041 | llvm::FoldingSetNodeID ID; |
| 1042 | ID.AddInteger(Kind); |
| 1043 | |
| 1044 | switch (Kind) { |
| 1045 | case DeclarationName::Identifier: |
| 1046 | case DeclarationName::CXXLiteralOperatorName: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1047 | case DeclarationName::CXXDeductionGuideName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1048 | ID.AddString(((IdentifierInfo*)Data)->getName()); |
| 1049 | break; |
| 1050 | case DeclarationName::ObjCZeroArgSelector: |
| 1051 | case DeclarationName::ObjCOneArgSelector: |
| 1052 | case DeclarationName::ObjCMultiArgSelector: |
| 1053 | ID.AddInteger(serialization::ComputeHash(Selector(Data))); |
| 1054 | break; |
| 1055 | case DeclarationName::CXXOperatorName: |
| 1056 | ID.AddInteger((OverloadedOperatorKind)Data); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1057 | break; |
| 1058 | case DeclarationName::CXXConstructorName: |
| 1059 | case DeclarationName::CXXDestructorName: |
| 1060 | case DeclarationName::CXXConversionFunctionName: |
| 1061 | case DeclarationName::CXXUsingDirective: |
| 1062 | break; |
| 1063 | } |
| 1064 | |
| 1065 | return ID.ComputeHash(); |
| 1066 | } |
| 1067 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1068 | ModuleFile * |
| 1069 | ASTDeclContextNameLookupTrait::ReadFileRef(const unsigned char *&d) { |
| 1070 | using namespace llvm::support; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1071 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1072 | uint32_t ModuleFileID = endian::readNext<uint32_t, little, unaligned>(d); |
| 1073 | return Reader.getLocalModuleFile(F, ModuleFileID); |
| 1074 | } |
| 1075 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1076 | std::pair<unsigned, unsigned> |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1077 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char *&d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1078 | using namespace llvm::support; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1079 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1080 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 1081 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1082 | return std::make_pair(KeyLen, DataLen); |
| 1083 | } |
| 1084 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1085 | ASTDeclContextNameLookupTrait::internal_key_type |
| 1086 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char *d, unsigned) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1087 | using namespace llvm::support; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1088 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1089 | auto Kind = (DeclarationName::NameKind)*d++; |
| 1090 | uint64_t Data; |
| 1091 | switch (Kind) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1092 | case DeclarationName::Identifier: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1093 | case DeclarationName::CXXLiteralOperatorName: |
| 1094 | case DeclarationName::CXXDeductionGuideName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1095 | Data = (uint64_t)Reader.getLocalIdentifier( |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1096 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1097 | break; |
| 1098 | case DeclarationName::ObjCZeroArgSelector: |
| 1099 | case DeclarationName::ObjCOneArgSelector: |
| 1100 | case DeclarationName::ObjCMultiArgSelector: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1101 | Data = |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1102 | (uint64_t)Reader.getLocalSelector( |
| 1103 | F, endian::readNext<uint32_t, little, unaligned>( |
| 1104 | d)).getAsOpaquePtr(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1105 | break; |
| 1106 | case DeclarationName::CXXOperatorName: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1107 | Data = *d++; // OverloadedOperatorKind |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1108 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1109 | case DeclarationName::CXXConstructorName: |
| 1110 | case DeclarationName::CXXDestructorName: |
| 1111 | case DeclarationName::CXXConversionFunctionName: |
| 1112 | case DeclarationName::CXXUsingDirective: |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1113 | Data = 0; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1114 | break; |
| 1115 | } |
| 1116 | |
Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1117 | return DeclarationNameKey(Kind, Data); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1120 | void ASTDeclContextNameLookupTrait::ReadDataInto(internal_key_type, |
| 1121 | const unsigned char *d, |
| 1122 | unsigned DataLen, |
| 1123 | data_type_builder &Val) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1124 | using namespace llvm::support; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1125 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1126 | for (unsigned NumDecls = DataLen / 4; NumDecls; --NumDecls) { |
| 1127 | uint32_t LocalID = endian::readNext<uint32_t, little, unaligned>(d); |
| 1128 | Val.insert(Reader.getGlobalDeclID(F, LocalID)); |
| 1129 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1132 | bool ASTReader::ReadLexicalDeclContextStorage(ModuleFile &M, |
| 1133 | BitstreamCursor &Cursor, |
| 1134 | uint64_t Offset, |
| 1135 | DeclContext *DC) { |
| 1136 | assert(Offset != 0); |
| 1137 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1138 | SavedStreamPosition SavedPosition(Cursor); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1139 | Cursor.JumpToBit(Offset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1140 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1141 | RecordData Record; |
| 1142 | StringRef Blob; |
| 1143 | unsigned Code = Cursor.ReadCode(); |
| 1144 | unsigned RecCode = Cursor.readRecord(Code, Record, &Blob); |
| 1145 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 1146 | Error("Expected lexical block"); |
| 1147 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 1150 | assert(!isa<TranslationUnitDecl>(DC) && |
| 1151 | "expected a TU_UPDATE_LEXICAL record for TU"); |
Richard Smith | 9c9173d | 2015-08-11 22:00:24 +0000 | [diff] [blame] | 1152 | // If we are handling a C++ class template instantiation, we can see multiple |
| 1153 | // lexical updates for the same record. It's important that we select only one |
| 1154 | // of them, so that field numbering works properly. Just pick the first one we |
| 1155 | // see. |
| 1156 | auto &Lex = LexicalDecls[DC]; |
| 1157 | if (!Lex.first) { |
| 1158 | Lex = std::make_pair( |
| 1159 | &M, llvm::makeArrayRef( |
| 1160 | reinterpret_cast<const llvm::support::unaligned_uint32_t *>( |
| 1161 | Blob.data()), |
| 1162 | Blob.size() / 4)); |
| 1163 | } |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1164 | DC->setHasExternalLexicalStorage(true); |
| 1165 | return false; |
| 1166 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1167 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1168 | bool ASTReader::ReadVisibleDeclContextStorage(ModuleFile &M, |
| 1169 | BitstreamCursor &Cursor, |
| 1170 | uint64_t Offset, |
| 1171 | DeclID ID) { |
| 1172 | assert(Offset != 0); |
| 1173 | |
| 1174 | SavedStreamPosition SavedPosition(Cursor); |
| 1175 | Cursor.JumpToBit(Offset); |
| 1176 | |
| 1177 | RecordData Record; |
| 1178 | StringRef Blob; |
| 1179 | unsigned Code = Cursor.ReadCode(); |
| 1180 | unsigned RecCode = Cursor.readRecord(Code, Record, &Blob); |
| 1181 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 1182 | Error("Expected visible lookup table block"); |
| 1183 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1186 | // We can't safely determine the primary context yet, so delay attaching the |
| 1187 | // lookup table until we're done with recursive deserialization. |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1188 | auto *Data = (const unsigned char*)Blob.data(); |
| 1189 | PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&M, Data}); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1190 | return false; |
| 1191 | } |
| 1192 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 1193 | void ASTReader::Error(StringRef Msg) const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1194 | Error(diag::err_fe_pch_malformed, Msg); |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 1195 | if (PP.getLangOpts().Modules && !Diags.isDiagnosticInFlight() && |
Richard Smith | fb1e7f7 | 2015-08-14 05:02:58 +0000 | [diff] [blame] | 1196 | !PP.getHeaderSearchInfo().getModuleCachePath().empty()) { |
Douglas Gregor | 940e805 | 2013-05-10 22:15:13 +0000 | [diff] [blame] | 1197 | Diag(diag::note_module_cache_path) |
| 1198 | << PP.getHeaderSearchInfo().getModuleCachePath(); |
| 1199 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | void ASTReader::Error(unsigned DiagID, |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 1203 | StringRef Arg1, StringRef Arg2) const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1204 | if (Diags.isDiagnosticInFlight()) |
| 1205 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 1206 | else |
| 1207 | Diag(DiagID) << Arg1 << Arg2; |
| 1208 | } |
| 1209 | |
| 1210 | //===----------------------------------------------------------------------===// |
| 1211 | // Source Manager Deserialization |
| 1212 | //===----------------------------------------------------------------------===// |
| 1213 | |
| 1214 | /// \brief Read the line table in the source manager block. |
| 1215 | /// \returns true if there was an error. |
| 1216 | bool ASTReader::ParseLineTable(ModuleFile &F, |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1217 | const RecordData &Record) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1218 | unsigned Idx = 0; |
| 1219 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1220 | |
| 1221 | // Parse the file names |
| 1222 | std::map<int, int> FileIDs; |
Hans Wennborg | 1448736 | 2017-12-04 22:28:45 +0000 | [diff] [blame] | 1223 | FileIDs[-1] = -1; // For unspecified filenames. |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1224 | for (unsigned I = 0; Record[Idx]; ++I) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1225 | // Extract the file name |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1226 | auto Filename = ReadPath(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1227 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
| 1228 | } |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1229 | ++Idx; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1230 | |
| 1231 | // Parse the line entries |
| 1232 | std::vector<LineEntry> Entries; |
| 1233 | while (Idx < Record.size()) { |
| 1234 | int FID = Record[Idx++]; |
| 1235 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 1236 | // Remap FileID from 1-based old view. |
| 1237 | FID += F.SLocEntryBaseID - 1; |
| 1238 | |
| 1239 | // Extract the line entries |
| 1240 | unsigned NumEntries = Record[Idx++]; |
Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1241 | assert(NumEntries && "no line entries for file ID"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1242 | Entries.clear(); |
| 1243 | Entries.reserve(NumEntries); |
| 1244 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1245 | unsigned FileOffset = Record[Idx++]; |
| 1246 | unsigned LineNo = Record[Idx++]; |
| 1247 | int FilenameID = FileIDs[Record[Idx++]]; |
| 1248 | SrcMgr::CharacteristicKind FileKind |
| 1249 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1250 | unsigned IncludeOffset = Record[Idx++]; |
| 1251 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1252 | FileKind, IncludeOffset)); |
| 1253 | } |
| 1254 | LineTable.AddEntry(FileID::get(FID), Entries); |
| 1255 | } |
| 1256 | |
| 1257 | return false; |
| 1258 | } |
| 1259 | |
| 1260 | /// \brief Read a source manager block |
| 1261 | bool ASTReader::ReadSourceManagerBlock(ModuleFile &F) { |
| 1262 | using namespace SrcMgr; |
| 1263 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1264 | BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1265 | |
| 1266 | // Set the source-location entry cursor to the current position in |
| 1267 | // the stream. This cursor will be used to read the contents of the |
| 1268 | // source manager block initially, and then lazily read |
| 1269 | // source-location entries as needed. |
| 1270 | SLocEntryCursor = F.Stream; |
| 1271 | |
| 1272 | // The stream itself is going to skip over the source manager block. |
| 1273 | if (F.Stream.SkipBlock()) { |
| 1274 | Error("malformed block record in AST file"); |
| 1275 | return true; |
| 1276 | } |
| 1277 | |
| 1278 | // Enter the source manager block. |
| 1279 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
| 1280 | Error("malformed source manager block record in AST file"); |
| 1281 | return true; |
| 1282 | } |
| 1283 | |
| 1284 | RecordData Record; |
| 1285 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1286 | llvm::BitstreamEntry E = SLocEntryCursor.advanceSkippingSubblocks(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1287 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1288 | switch (E.Kind) { |
| 1289 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1290 | case llvm::BitstreamEntry::Error: |
| 1291 | Error("malformed block record in AST file"); |
| 1292 | return true; |
| 1293 | case llvm::BitstreamEntry::EndBlock: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1294 | return false; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1295 | case llvm::BitstreamEntry::Record: |
| 1296 | // The interesting case. |
| 1297 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1298 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1299 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1300 | // Read a record. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1301 | Record.clear(); |
Chris Lattner | 15c3e7d | 2013-01-21 18:28:26 +0000 | [diff] [blame] | 1302 | StringRef Blob; |
| 1303 | switch (SLocEntryCursor.readRecord(E.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1304 | default: // Default behavior: ignore. |
| 1305 | break; |
| 1306 | |
| 1307 | case SM_SLOC_FILE_ENTRY: |
| 1308 | case SM_SLOC_BUFFER_ENTRY: |
| 1309 | case SM_SLOC_EXPANSION_ENTRY: |
| 1310 | // Once we hit one of the source location entries, we're done. |
| 1311 | return false; |
| 1312 | } |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | /// \brief If a header file is not found at the path that we expect it to be |
| 1317 | /// and the PCH file was moved from its original location, try to resolve the |
| 1318 | /// file by assuming that header+PCH were moved together and the header is in |
| 1319 | /// the same place relative to the PCH. |
| 1320 | static std::string |
| 1321 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1322 | const std::string &OriginalDir, |
| 1323 | const std::string &CurrDir) { |
| 1324 | assert(OriginalDir != CurrDir && |
| 1325 | "No point trying to resolve the file if the PCH dir didn't change"); |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1326 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1327 | using namespace llvm::sys; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1328 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1329 | SmallString<128> filePath(Filename); |
| 1330 | fs::make_absolute(filePath); |
| 1331 | assert(path::is_absolute(OriginalDir)); |
| 1332 | SmallString<128> currPCHPath(CurrDir); |
| 1333 | |
| 1334 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1335 | fileDirE = path::end(path::parent_path(filePath)); |
| 1336 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1337 | origDirE = path::end(OriginalDir); |
| 1338 | // Skip the common path components from filePath and OriginalDir. |
| 1339 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1340 | *fileDirI == *origDirI) { |
| 1341 | ++fileDirI; |
| 1342 | ++origDirI; |
| 1343 | } |
| 1344 | for (; origDirI != origDirE; ++origDirI) |
| 1345 | path::append(currPCHPath, ".."); |
| 1346 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1347 | path::append(currPCHPath, path::filename(Filename)); |
| 1348 | return currPCHPath.str(); |
| 1349 | } |
| 1350 | |
| 1351 | bool ASTReader::ReadSLocEntry(int ID) { |
| 1352 | if (ID == 0) |
| 1353 | return false; |
| 1354 | |
| 1355 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
| 1356 | Error("source location entry ID out-of-range for AST file"); |
| 1357 | return true; |
| 1358 | } |
| 1359 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1360 | // Local helper to read the (possibly-compressed) buffer data following the |
| 1361 | // entry record. |
| 1362 | auto ReadBuffer = [this]( |
| 1363 | BitstreamCursor &SLocEntryCursor, |
| 1364 | StringRef Name) -> std::unique_ptr<llvm::MemoryBuffer> { |
| 1365 | RecordData Record; |
| 1366 | StringRef Blob; |
| 1367 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1368 | unsigned RecCode = SLocEntryCursor.readRecord(Code, Record, &Blob); |
| 1369 | |
| 1370 | if (RecCode == SM_SLOC_BUFFER_BLOB_COMPRESSED) { |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 1371 | if (!llvm::zlib::isAvailable()) { |
| 1372 | Error("zlib is not available"); |
| 1373 | return nullptr; |
| 1374 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1375 | SmallString<0> Uncompressed; |
George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 1376 | if (llvm::Error E = |
| 1377 | llvm::zlib::uncompress(Blob, Uncompressed, Record[0])) { |
| 1378 | Error("could not decompress embedded file contents: " + |
| 1379 | llvm::toString(std::move(E))); |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1380 | return nullptr; |
| 1381 | } |
| 1382 | return llvm::MemoryBuffer::getMemBufferCopy(Uncompressed, Name); |
| 1383 | } else if (RecCode == SM_SLOC_BUFFER_BLOB) { |
| 1384 | return llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), Name, true); |
| 1385 | } else { |
| 1386 | Error("AST record has invalid code"); |
| 1387 | return nullptr; |
| 1388 | } |
| 1389 | }; |
| 1390 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1391 | ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second; |
| 1392 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1393 | BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1394 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
| 1395 | |
| 1396 | ++NumSLocEntriesRead; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1397 | llvm::BitstreamEntry Entry = SLocEntryCursor.advance(); |
| 1398 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1399 | Error("incorrectly-formatted source location entry in AST file"); |
| 1400 | return true; |
| 1401 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1402 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1403 | RecordData Record; |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1404 | StringRef Blob; |
| 1405 | switch (SLocEntryCursor.readRecord(Entry.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1406 | default: |
| 1407 | Error("incorrectly-formatted source location entry in AST file"); |
| 1408 | return true; |
| 1409 | |
| 1410 | case SM_SLOC_FILE_ENTRY: { |
| 1411 | // We will detect whether a file changed and return 'Failure' for it, but |
| 1412 | // we will also try to fail gracefully by setting up the SLocEntry. |
| 1413 | unsigned InputID = Record[4]; |
| 1414 | InputFile IF = getInputFile(*F, InputID); |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 1415 | const FileEntry *File = IF.getFile(); |
| 1416 | bool OverriddenBuffer = IF.isOverridden(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1417 | |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 1418 | // Note that we only check if a File was returned. If it was out-of-date |
| 1419 | // we have complained but we will continue creating a FileID to recover |
| 1420 | // gracefully. |
| 1421 | if (!File) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1422 | return true; |
| 1423 | |
| 1424 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
| 1425 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
| 1426 | // This is the module's main file. |
| 1427 | IncludeLoc = getImportLocation(F); |
| 1428 | } |
| 1429 | SrcMgr::CharacteristicKind |
| 1430 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1431 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter, |
| 1432 | ID, BaseOffset + Record[0]); |
| 1433 | SrcMgr::FileInfo &FileInfo = |
| 1434 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
| 1435 | FileInfo.NumCreatedFIDs = Record[5]; |
| 1436 | if (Record[3]) |
| 1437 | FileInfo.setHasLineDirectives(); |
| 1438 | |
| 1439 | const DeclID *FirstDecl = F->FileSortedDecls + Record[6]; |
| 1440 | unsigned NumFileDecls = Record[7]; |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 1441 | if (NumFileDecls && ContextObj) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1442 | assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?"); |
| 1443 | FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl, |
| 1444 | NumFileDecls)); |
| 1445 | } |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1446 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1447 | const SrcMgr::ContentCache *ContentCache |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1448 | = SourceMgr.getOrCreateContentCache(File, isSystem(FileCharacter)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1449 | if (OverriddenBuffer && !ContentCache->BufferOverridden && |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1450 | ContentCache->ContentsEntry == ContentCache->OrigEntry && |
| 1451 | !ContentCache->getRawBuffer()) { |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1452 | auto Buffer = ReadBuffer(SLocEntryCursor, File->getName()); |
| 1453 | if (!Buffer) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1454 | return true; |
David Blaikie | 49cc318 | 2014-08-27 20:54:45 +0000 | [diff] [blame] | 1455 | SourceMgr.overrideFileContents(File, std::move(Buffer)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | break; |
| 1459 | } |
| 1460 | |
| 1461 | case SM_SLOC_BUFFER_ENTRY: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1462 | const char *Name = Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1463 | unsigned Offset = Record[0]; |
| 1464 | SrcMgr::CharacteristicKind |
| 1465 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1466 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 1467 | if (IncludeLoc.isInvalid() && F->isModule()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1468 | IncludeLoc = getImportLocation(F); |
| 1469 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1470 | |
Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1471 | auto Buffer = ReadBuffer(SLocEntryCursor, Name); |
| 1472 | if (!Buffer) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1473 | return true; |
David Blaikie | 50a5f97 | 2014-08-29 07:59:55 +0000 | [diff] [blame] | 1474 | SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID, |
Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 1475 | BaseOffset + Offset, IncludeLoc); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1476 | break; |
| 1477 | } |
| 1478 | |
| 1479 | case SM_SLOC_EXPANSION_ENTRY: { |
| 1480 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
| 1481 | SourceMgr.createExpansionLoc(SpellingLoc, |
| 1482 | ReadSourceLocation(*F, Record[2]), |
| 1483 | ReadSourceLocation(*F, Record[3]), |
| 1484 | Record[4], |
| 1485 | ID, |
| 1486 | BaseOffset + Record[0]); |
| 1487 | break; |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | return false; |
| 1492 | } |
| 1493 | |
| 1494 | std::pair<SourceLocation, StringRef> ASTReader::getModuleImportLoc(int ID) { |
| 1495 | if (ID == 0) |
| 1496 | return std::make_pair(SourceLocation(), ""); |
| 1497 | |
| 1498 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
| 1499 | Error("source location entry ID out-of-range for AST file"); |
| 1500 | return std::make_pair(SourceLocation(), ""); |
| 1501 | } |
| 1502 | |
| 1503 | // Find which module file this entry lands in. |
| 1504 | ModuleFile *M = GlobalSLocEntryMap.find(-ID)->second; |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 1505 | if (!M->isModule()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1506 | return std::make_pair(SourceLocation(), ""); |
| 1507 | |
| 1508 | // FIXME: Can we map this down to a particular submodule? That would be |
| 1509 | // ideal. |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1510 | return std::make_pair(M->ImportLoc, StringRef(M->ModuleName)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | /// \brief Find the location where the module F is imported. |
| 1514 | SourceLocation ASTReader::getImportLocation(ModuleFile *F) { |
| 1515 | if (F->ImportLoc.isValid()) |
| 1516 | return F->ImportLoc; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1517 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1518 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1519 | // location of its includer. |
| 1520 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1521 | // Main file is the importer. |
Yaron Keren | 8b56366 | 2015-10-03 10:46:20 +0000 | [diff] [blame] | 1522 | assert(SourceMgr.getMainFileID().isValid() && "missing main file"); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1523 | return SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1524 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1525 | return F->ImportedBy[0]->FirstLoc; |
| 1526 | } |
| 1527 | |
| 1528 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1529 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1530 | /// and then leave the cursor pointing into the block. |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1531 | bool ASTReader::ReadBlockAbbrevs(BitstreamCursor &Cursor, unsigned BlockID) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1532 | if (Cursor.EnterSubBlock(BlockID)) |
| 1533 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1534 | |
| 1535 | while (true) { |
| 1536 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
| 1537 | unsigned Code = Cursor.ReadCode(); |
| 1538 | |
| 1539 | // We expect all abbrevs to be at the start of the block. |
| 1540 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1541 | Cursor.JumpToBit(Offset); |
| 1542 | return false; |
| 1543 | } |
| 1544 | Cursor.ReadAbbrevRecord(); |
| 1545 | } |
| 1546 | } |
| 1547 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 1548 | Token ASTReader::ReadToken(ModuleFile &F, const RecordDataImpl &Record, |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1549 | unsigned &Idx) { |
| 1550 | Token Tok; |
| 1551 | Tok.startToken(); |
| 1552 | Tok.setLocation(ReadSourceLocation(F, Record, Idx)); |
| 1553 | Tok.setLength(Record[Idx++]); |
| 1554 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[Idx++])) |
| 1555 | Tok.setIdentifierInfo(II); |
| 1556 | Tok.setKind((tok::TokenKind)Record[Idx++]); |
| 1557 | Tok.setFlag((Token::TokenFlags)Record[Idx++]); |
| 1558 | return Tok; |
| 1559 | } |
| 1560 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1561 | MacroInfo *ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1562 | BitstreamCursor &Stream = F.MacroCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1563 | |
| 1564 | // Keep track of where we are in the stream, then jump back there |
| 1565 | // after reading this macro. |
| 1566 | SavedStreamPosition SavedPosition(Stream); |
| 1567 | |
| 1568 | Stream.JumpToBit(Offset); |
| 1569 | RecordData Record; |
Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame] | 1570 | SmallVector<IdentifierInfo*, 16> MacroParams; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1571 | MacroInfo *Macro = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1572 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1573 | while (true) { |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1574 | // Advance to the next record, but if we get to the end of the block, don't |
| 1575 | // pop it (removing all the abbreviations from the cursor) since we want to |
| 1576 | // be able to reseek within the block and read entries. |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1577 | unsigned Flags = BitstreamCursor::AF_DontPopBlockAtEnd; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1578 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(Flags); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1579 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1580 | switch (Entry.Kind) { |
| 1581 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1582 | case llvm::BitstreamEntry::Error: |
| 1583 | Error("malformed block record in AST file"); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1584 | return Macro; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1585 | case llvm::BitstreamEntry::EndBlock: |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1586 | return Macro; |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1587 | case llvm::BitstreamEntry::Record: |
| 1588 | // The interesting case. |
| 1589 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | // Read a record. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1593 | Record.clear(); |
| 1594 | PreprocessorRecordTypes RecType = |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1595 | (PreprocessorRecordTypes)Stream.readRecord(Entry.ID, Record); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1596 | switch (RecType) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1597 | case PP_MODULE_MACRO: |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1598 | case PP_MACRO_DIRECTIVE_HISTORY: |
| 1599 | return Macro; |
| 1600 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1601 | case PP_MACRO_OBJECT_LIKE: |
| 1602 | case PP_MACRO_FUNCTION_LIKE: { |
| 1603 | // If we already have a macro, that means that we've hit the end |
| 1604 | // of the definition of the macro we were looking for. We're |
| 1605 | // done. |
| 1606 | if (Macro) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1607 | return Macro; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1608 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1609 | unsigned NextIndex = 1; // Skip identifier ID. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1610 | SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex); |
Richard Smith | 3f6dd7a | 2017-05-12 23:40:52 +0000 | [diff] [blame] | 1611 | MacroInfo *MI = PP.AllocateMacroInfo(Loc); |
Argyrios Kyrtzidis | 7572be2 | 2013-01-07 19:16:23 +0000 | [diff] [blame] | 1612 | MI->setDefinitionEndLoc(ReadSourceLocation(F, Record, NextIndex)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1613 | MI->setIsUsed(Record[NextIndex++]); |
Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 1614 | MI->setUsedForHeaderGuard(Record[NextIndex++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1615 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1616 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
| 1617 | // Decode function-like macro info. |
| 1618 | bool isC99VarArgs = Record[NextIndex++]; |
| 1619 | bool isGNUVarArgs = Record[NextIndex++]; |
| 1620 | bool hasCommaPasting = Record[NextIndex++]; |
Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame] | 1621 | MacroParams.clear(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1622 | unsigned NumArgs = Record[NextIndex++]; |
| 1623 | for (unsigned i = 0; i != NumArgs; ++i) |
Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame] | 1624 | MacroParams.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1625 | |
| 1626 | // Install function-like macro info. |
| 1627 | MI->setIsFunctionLike(); |
| 1628 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1629 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
| 1630 | if (hasCommaPasting) MI->setHasCommaPasting(); |
Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame] | 1631 | MI->setParameterList(MacroParams, PP.getPreprocessorAllocator()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1632 | } |
| 1633 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1634 | // Remember that we saw this macro last so that we add the tokens that |
| 1635 | // form its body to it. |
| 1636 | Macro = MI; |
| 1637 | |
| 1638 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() && |
| 1639 | Record[NextIndex]) { |
| 1640 | // We have a macro definition. Register the association |
| 1641 | PreprocessedEntityID |
| 1642 | GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]); |
| 1643 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 1644 | PreprocessingRecord::PPEntityID PPID = |
| 1645 | PPRec.getPPEntityID(GlobalID - 1, /*isLoaded=*/true); |
| 1646 | MacroDefinitionRecord *PPDef = cast_or_null<MacroDefinitionRecord>( |
| 1647 | PPRec.getPreprocessedEntity(PPID)); |
Argyrios Kyrtzidis | 832de9f | 2013-02-22 18:35:59 +0000 | [diff] [blame] | 1648 | if (PPDef) |
| 1649 | PPRec.RegisterMacroDefinition(Macro, PPDef); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
| 1652 | ++NumMacrosRead; |
| 1653 | break; |
| 1654 | } |
| 1655 | |
| 1656 | case PP_TOKEN: { |
| 1657 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1658 | // erroneous, just pretend we didn't see this. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1659 | if (!Macro) break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1660 | |
John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1661 | unsigned Idx = 0; |
| 1662 | Token Tok = ReadToken(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1663 | Macro->AddTokenToBody(Tok); |
| 1664 | break; |
| 1665 | } |
| 1666 | } |
| 1667 | } |
| 1668 | } |
| 1669 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1670 | PreprocessedEntityID |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 1671 | ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M, |
| 1672 | unsigned LocalID) const { |
| 1673 | if (!M.ModuleOffsetMap.empty()) |
| 1674 | ReadModuleOffsetMap(M); |
| 1675 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1676 | ContinuousRangeMap<uint32_t, int, 2>::const_iterator |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1677 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1678 | assert(I != M.PreprocessedEntityRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1679 | && "Invalid index into preprocessed entity index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1680 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1681 | return LocalID + I->second; |
| 1682 | } |
| 1683 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1684 | unsigned HeaderFileInfoTrait::ComputeHash(internal_key_ref ikey) { |
| 1685 | return llvm::hash_combine(ikey.Size, ikey.ModTime); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1686 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1687 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1688 | HeaderFileInfoTrait::internal_key_type |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1689 | HeaderFileInfoTrait::GetInternalKey(const FileEntry *FE) { |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1690 | internal_key_type ikey = {FE->getSize(), |
| 1691 | M.HasTimestamps ? FE->getModificationTime() : 0, |
| 1692 | FE->getName(), /*Imported*/ false}; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1693 | return ikey; |
| 1694 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1695 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1696 | bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) { |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1697 | 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] | 1698 | return false; |
| 1699 | |
Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1700 | if (llvm::sys::path::is_absolute(a.Filename) && a.Filename == b.Filename) |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1701 | return true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1702 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1703 | // Determine whether the actual files are equivalent. |
Argyrios Kyrtzidis | 2a513e8 | 2013-03-04 20:33:40 +0000 | [diff] [blame] | 1704 | FileManager &FileMgr = Reader.getFileManager(); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1705 | auto GetFile = [&](const internal_key_type &Key) -> const FileEntry* { |
| 1706 | if (!Key.Imported) |
| 1707 | return FileMgr.getFile(Key.Filename); |
| 1708 | |
| 1709 | std::string Resolved = Key.Filename; |
| 1710 | Reader.ResolveImportedPath(M, Resolved); |
| 1711 | return FileMgr.getFile(Resolved); |
| 1712 | }; |
| 1713 | |
| 1714 | const FileEntry *FEA = GetFile(a); |
| 1715 | const FileEntry *FEB = GetFile(b); |
| 1716 | return FEA && FEA == FEB; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1717 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1718 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1719 | std::pair<unsigned, unsigned> |
| 1720 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1721 | using namespace llvm::support; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1722 | |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1723 | unsigned KeyLen = (unsigned) endian::readNext<uint16_t, little, unaligned>(d); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1724 | unsigned DataLen = (unsigned) *d++; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1725 | return std::make_pair(KeyLen, DataLen); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1726 | } |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1727 | |
| 1728 | HeaderFileInfoTrait::internal_key_type |
| 1729 | HeaderFileInfoTrait::ReadKey(const unsigned char *d, unsigned) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1730 | using namespace llvm::support; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1731 | |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1732 | internal_key_type ikey; |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1733 | ikey.Size = off_t(endian::readNext<uint64_t, little, unaligned>(d)); |
| 1734 | ikey.ModTime = time_t(endian::readNext<uint64_t, little, unaligned>(d)); |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1735 | ikey.Filename = (const char *)d; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1736 | ikey.Imported = true; |
Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1737 | return ikey; |
| 1738 | } |
| 1739 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1740 | HeaderFileInfoTrait::data_type |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1741 | HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1742 | unsigned DataLen) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1743 | using namespace llvm::support; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1744 | |
| 1745 | const unsigned char *End = d + DataLen; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1746 | HeaderFileInfo HFI; |
| 1747 | unsigned Flags = *d++; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1748 | // FIXME: Refactor with mergeHeaderFileInfo in HeaderSearch.cpp. |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1749 | HFI.isImport |= (Flags >> 5) & 0x01; |
| 1750 | HFI.isPragmaOnce |= (Flags >> 4) & 0x01; |
| 1751 | HFI.DirInfo = (Flags >> 1) & 0x07; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1752 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1753 | // FIXME: Find a better way to handle this. Maybe just store a |
| 1754 | // "has been included" flag? |
| 1755 | HFI.NumIncludes = std::max(endian::readNext<uint16_t, little, unaligned>(d), |
| 1756 | HFI.NumIncludes); |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1757 | HFI.ControllingMacroID = Reader.getGlobalIdentifierID( |
| 1758 | M, endian::readNext<uint32_t, little, unaligned>(d)); |
| 1759 | if (unsigned FrameworkOffset = |
| 1760 | endian::readNext<uint32_t, little, unaligned>(d)) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1761 | // The framework offset is 1 greater than the actual offset, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1762 | // since 0 is used as an indicator for "no framework name". |
| 1763 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1764 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1765 | } |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1766 | |
| 1767 | assert((End - d) % 4 == 0 && |
| 1768 | "Wrong data length in HeaderFileInfo deserialization"); |
| 1769 | while (d != End) { |
Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1770 | uint32_t LocalSMID = endian::readNext<uint32_t, little, unaligned>(d); |
Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1771 | auto HeaderRole = static_cast<ModuleMap::ModuleHeaderRole>(LocalSMID & 3); |
| 1772 | LocalSMID >>= 2; |
| 1773 | |
| 1774 | // This header is part of a module. Associate it with the module to enable |
| 1775 | // implicit module import. |
| 1776 | SubmoduleID GlobalSMID = Reader.getGlobalSubmoduleID(M, LocalSMID); |
| 1777 | Module *Mod = Reader.getSubmodule(GlobalSMID); |
| 1778 | FileManager &FileMgr = Reader.getFileManager(); |
| 1779 | ModuleMap &ModMap = |
| 1780 | Reader.getPreprocessor().getHeaderSearchInfo().getModuleMap(); |
| 1781 | |
| 1782 | std::string Filename = key.Filename; |
| 1783 | if (key.Imported) |
| 1784 | Reader.ResolveImportedPath(M, Filename); |
| 1785 | // FIXME: This is not always the right filename-as-written, but we're not |
| 1786 | // going to use this information to rebuild the module, so it doesn't make |
| 1787 | // a lot of difference. |
| 1788 | Module::Header H = { key.Filename, FileMgr.getFile(Filename) }; |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1789 | ModMap.addHeader(Mod, H, HeaderRole, /*Imported*/true); |
| 1790 | HFI.isModuleHeader |= !(HeaderRole & ModuleMap::TextualHeader); |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1791 | } |
| 1792 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1793 | // This HeaderFileInfo was externally loaded. |
| 1794 | HFI.External = true; |
Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1795 | HFI.IsValid = true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1796 | return HFI; |
| 1797 | } |
| 1798 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1799 | void ASTReader::addPendingMacro(IdentifierInfo *II, |
| 1800 | ModuleFile *M, |
| 1801 | uint64_t MacroDirectivesOffset) { |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1802 | assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard"); |
| 1803 | PendingMacroIDs[II].push_back(PendingMacroInfo(M, MacroDirectivesOffset)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | void ASTReader::ReadDefinedMacros() { |
| 1807 | // Note that we are loading defined macros. |
| 1808 | Deserializing Macros(this); |
| 1809 | |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1810 | for (ModuleFile &I : llvm::reverse(ModuleMgr)) { |
| 1811 | BitstreamCursor &MacroCursor = I.MacroCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1812 | |
| 1813 | // If there was no preprocessor block, skip this file. |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 1814 | if (MacroCursor.getBitcodeBytes().empty()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1815 | continue; |
| 1816 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1817 | BitstreamCursor Cursor = MacroCursor; |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1818 | Cursor.JumpToBit(I.MacroStartOffset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1819 | |
| 1820 | RecordData Record; |
| 1821 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1822 | llvm::BitstreamEntry E = Cursor.advanceSkippingSubblocks(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1823 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1824 | switch (E.Kind) { |
| 1825 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1826 | case llvm::BitstreamEntry::Error: |
| 1827 | Error("malformed block record in AST file"); |
| 1828 | return; |
| 1829 | case llvm::BitstreamEntry::EndBlock: |
| 1830 | goto NextCursor; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1831 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1832 | case llvm::BitstreamEntry::Record: |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1833 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1834 | switch (Cursor.readRecord(E.ID, Record)) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1835 | default: // Default behavior: ignore. |
| 1836 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1837 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1838 | case PP_MACRO_OBJECT_LIKE: |
Sean Callanan | f3682a7 | 2016-05-14 06:24:14 +0000 | [diff] [blame] | 1839 | case PP_MACRO_FUNCTION_LIKE: { |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1840 | IdentifierInfo *II = getLocalIdentifier(I, Record[0]); |
Sean Callanan | f3682a7 | 2016-05-14 06:24:14 +0000 | [diff] [blame] | 1841 | if (II->isOutOfDate()) |
| 1842 | updateOutOfDateIdentifier(*II); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1843 | break; |
Sean Callanan | f3682a7 | 2016-05-14 06:24:14 +0000 | [diff] [blame] | 1844 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1845 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1846 | case PP_TOKEN: |
| 1847 | // Ignore tokens. |
| 1848 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1849 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1850 | break; |
| 1851 | } |
| 1852 | } |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1853 | NextCursor: ; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1854 | } |
| 1855 | } |
| 1856 | |
| 1857 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1858 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1859 | /// \brief Visitor class used to look up identifirs in an AST file. |
| 1860 | class IdentifierLookupVisitor { |
| 1861 | StringRef Name; |
Richard Smith | 3b63741 | 2015-07-14 18:42:41 +0000 | [diff] [blame] | 1862 | unsigned NameHash; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1863 | unsigned PriorGeneration; |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1864 | unsigned &NumIdentifierLookups; |
| 1865 | unsigned &NumIdentifierLookupHits; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1866 | IdentifierInfo *Found = nullptr; |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1867 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1868 | public: |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1869 | IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration, |
| 1870 | unsigned &NumIdentifierLookups, |
| 1871 | unsigned &NumIdentifierLookupHits) |
Richard Smith | 3b63741 | 2015-07-14 18:42:41 +0000 | [diff] [blame] | 1872 | : Name(Name), NameHash(ASTIdentifierLookupTrait::ComputeHash(Name)), |
| 1873 | PriorGeneration(PriorGeneration), |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1874 | NumIdentifierLookups(NumIdentifierLookups), |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1875 | NumIdentifierLookupHits(NumIdentifierLookupHits) {} |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 1876 | |
| 1877 | bool operator()(ModuleFile &M) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1878 | // If we've already searched this module file, skip it now. |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1879 | if (M.Generation <= PriorGeneration) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1880 | return true; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1881 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1882 | ASTIdentifierLookupTable *IdTable |
| 1883 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 1884 | if (!IdTable) |
| 1885 | return false; |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 1886 | |
| 1887 | ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), M, |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1888 | Found); |
| 1889 | ++NumIdentifierLookups; |
Richard Smith | 3b63741 | 2015-07-14 18:42:41 +0000 | [diff] [blame] | 1890 | ASTIdentifierLookupTable::iterator Pos = |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1891 | IdTable->find_hashed(Name, NameHash, &Trait); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1892 | if (Pos == IdTable->end()) |
| 1893 | return false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1894 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1895 | // Dereferencing the iterator has the effect of building the |
| 1896 | // IdentifierInfo node and populating it with the various |
| 1897 | // declarations it needs. |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1898 | ++NumIdentifierLookupHits; |
| 1899 | Found = *Pos; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1900 | return true; |
| 1901 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1902 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1903 | // \brief Retrieve the identifier info found within the module |
| 1904 | // files. |
| 1905 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 1906 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1907 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1908 | } // namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1909 | |
| 1910 | void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { |
| 1911 | // Note that we are loading an identifier. |
| 1912 | Deserializing AnIdentifier(this); |
| 1913 | |
| 1914 | unsigned PriorGeneration = 0; |
| 1915 | if (getContext().getLangOpts().Modules) |
| 1916 | PriorGeneration = IdentifierGeneration[&II]; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1917 | |
| 1918 | // If there is a global index, look there first to determine which modules |
| 1919 | // provably do not have any results for this identifier. |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1920 | GlobalModuleIndex::HitSet Hits; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1921 | GlobalModuleIndex::HitSet *HitsPtr = nullptr; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1922 | if (!loadGlobalIndex()) { |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1923 | if (GlobalIndex->lookupIdentifier(II.getName(), Hits)) { |
| 1924 | HitsPtr = &Hits; |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1925 | } |
| 1926 | } |
| 1927 | |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1928 | IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration, |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1929 | NumIdentifierLookups, |
| 1930 | NumIdentifierLookupHits); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 1931 | ModuleMgr.visit(Visitor, HitsPtr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1932 | markIdentifierUpToDate(&II); |
| 1933 | } |
| 1934 | |
| 1935 | void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { |
| 1936 | if (!II) |
| 1937 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1938 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1939 | II->setOutOfDate(false); |
| 1940 | |
| 1941 | // Update the generation for this identifier. |
| 1942 | if (getContext().getLangOpts().Modules) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1943 | IdentifierGeneration[II] = getGeneration(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1944 | } |
| 1945 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1946 | void ASTReader::resolvePendingMacro(IdentifierInfo *II, |
| 1947 | const PendingMacroInfo &PMInfo) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1948 | ModuleFile &M = *PMInfo.M; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1949 | |
| 1950 | BitstreamCursor &Cursor = M.MacroCursor; |
| 1951 | SavedStreamPosition SavedPosition(Cursor); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1952 | Cursor.JumpToBit(PMInfo.MacroDirectivesOffset); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1953 | |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1954 | struct ModuleMacroRecord { |
| 1955 | SubmoduleID SubModID; |
| 1956 | MacroInfo *MI; |
| 1957 | SmallVector<SubmoduleID, 8> Overrides; |
| 1958 | }; |
| 1959 | llvm::SmallVector<ModuleMacroRecord, 8> ModuleMacros; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1960 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1961 | // We expect to see a sequence of PP_MODULE_MACRO records listing exported |
| 1962 | // macros, followed by a PP_MACRO_DIRECTIVE_HISTORY record with the complete |
| 1963 | // macro histroy. |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1964 | RecordData Record; |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1965 | while (true) { |
| 1966 | llvm::BitstreamEntry Entry = |
| 1967 | Cursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd); |
| 1968 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| 1969 | Error("malformed block record in AST file"); |
| 1970 | return; |
| 1971 | } |
| 1972 | |
| 1973 | Record.clear(); |
Aaron Ballman | c75a192 | 2015-04-22 15:25:05 +0000 | [diff] [blame] | 1974 | switch ((PreprocessorRecordTypes)Cursor.readRecord(Entry.ID, Record)) { |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1975 | case PP_MACRO_DIRECTIVE_HISTORY: |
| 1976 | break; |
| 1977 | |
| 1978 | case PP_MODULE_MACRO: { |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1979 | ModuleMacros.push_back(ModuleMacroRecord()); |
| 1980 | auto &Info = ModuleMacros.back(); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1981 | Info.SubModID = getGlobalSubmoduleID(M, Record[0]); |
| 1982 | Info.MI = getMacro(getGlobalMacroID(M, Record[1])); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1983 | for (int I = 2, N = Record.size(); I != N; ++I) |
| 1984 | Info.Overrides.push_back(getGlobalSubmoduleID(M, Record[I])); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1985 | continue; |
| 1986 | } |
| 1987 | |
| 1988 | default: |
| 1989 | Error("malformed block record in AST file"); |
| 1990 | return; |
| 1991 | } |
| 1992 | |
| 1993 | // We found the macro directive history; that's the last record |
| 1994 | // for this macro. |
| 1995 | break; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1998 | // Module macros are listed in reverse dependency order. |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1999 | { |
| 2000 | std::reverse(ModuleMacros.begin(), ModuleMacros.end()); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 2001 | llvm::SmallVector<ModuleMacro*, 8> Overrides; |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2002 | for (auto &MMR : ModuleMacros) { |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 2003 | Overrides.clear(); |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2004 | for (unsigned ModID : MMR.Overrides) { |
Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2005 | Module *Mod = getSubmodule(ModID); |
| 2006 | auto *Macro = PP.getModuleMacro(Mod, II); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 2007 | assert(Macro && "missing definition for overridden macro"); |
Richard Smith | 5dbef92 | 2015-04-22 02:09:43 +0000 | [diff] [blame] | 2008 | Overrides.push_back(Macro); |
Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 2009 | } |
| 2010 | |
| 2011 | bool Inserted = false; |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2012 | Module *Owner = getSubmodule(MMR.SubModID); |
Richard Smith | 20e883e | 2015-04-29 23:20:19 +0000 | [diff] [blame] | 2013 | PP.addModuleMacro(Owner, II, MMR.MI, Overrides, Inserted); |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2014 | } |
| 2015 | } |
| 2016 | |
| 2017 | // Don't read the directive history for a module; we don't have anywhere |
| 2018 | // to put it. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2019 | if (M.isModule()) |
Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2020 | return; |
| 2021 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2022 | // Deserialize the macro directives history in reverse source-order. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 2023 | MacroDirective *Latest = nullptr, *Earliest = nullptr; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2024 | unsigned Idx = 0, N = Record.size(); |
| 2025 | while (Idx < N) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 2026 | MacroDirective *MD = nullptr; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2027 | SourceLocation Loc = ReadSourceLocation(M, Record, Idx); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2028 | MacroDirective::Kind K = (MacroDirective::Kind)Record[Idx++]; |
| 2029 | switch (K) { |
| 2030 | case MacroDirective::MD_Define: { |
Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2031 | MacroInfo *MI = getMacro(getGlobalMacroID(M, Record[Idx++])); |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 2032 | MD = PP.AllocateDefMacroDirective(MI, Loc); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2033 | break; |
| 2034 | } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 2035 | case MacroDirective::MD_Undefine: |
Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 2036 | MD = PP.AllocateUndefMacroDirective(Loc); |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2037 | break; |
Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 2038 | case MacroDirective::MD_Visibility: |
Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2039 | bool isPublic = Record[Idx++]; |
| 2040 | MD = PP.AllocateVisibilityMacroDirective(Loc, isPublic); |
| 2041 | break; |
| 2042 | } |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2043 | |
| 2044 | if (!Latest) |
| 2045 | Latest = MD; |
| 2046 | if (Earliest) |
| 2047 | Earliest->setPrevious(MD); |
| 2048 | Earliest = MD; |
| 2049 | } |
| 2050 | |
Richard Smith | d6e8c0d | 2015-05-04 19:58:00 +0000 | [diff] [blame] | 2051 | if (Latest) |
Nico Weber | fd87070 | 2016-12-09 17:32:52 +0000 | [diff] [blame] | 2052 | PP.setLoadedMacroDirective(II, Earliest, Latest); |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2053 | } |
| 2054 | |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 2055 | ASTReader::InputFileInfo |
| 2056 | ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) { |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2057 | // Go find this input file. |
| 2058 | BitstreamCursor &Cursor = F.InputFilesCursor; |
| 2059 | SavedStreamPosition SavedPosition(Cursor); |
| 2060 | Cursor.JumpToBit(F.InputFileOffsets[ID-1]); |
| 2061 | |
| 2062 | unsigned Code = Cursor.ReadCode(); |
| 2063 | RecordData Record; |
| 2064 | StringRef Blob; |
| 2065 | |
| 2066 | unsigned Result = Cursor.readRecord(Code, Record, &Blob); |
| 2067 | assert(static_cast<InputFileRecordTypes>(Result) == INPUT_FILE && |
| 2068 | "invalid record type for input file"); |
| 2069 | (void)Result; |
| 2070 | |
| 2071 | assert(Record[0] == ID && "Bogus stored ID or offset"); |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2072 | InputFileInfo R; |
| 2073 | R.StoredSize = static_cast<off_t>(Record[1]); |
| 2074 | R.StoredTime = static_cast<time_t>(Record[2]); |
| 2075 | R.Overridden = static_cast<bool>(Record[3]); |
| 2076 | R.Transient = static_cast<bool>(Record[4]); |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 2077 | R.TopLevelModuleMap = static_cast<bool>(Record[5]); |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2078 | R.Filename = Blob; |
| 2079 | ResolveImportedPath(F, R.Filename); |
Hans Wennborg | 7394514 | 2014-03-14 17:45:06 +0000 | [diff] [blame] | 2080 | return R; |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2081 | } |
| 2082 | |
Manman Ren | c8c9415 | 2016-10-21 23:35:03 +0000 | [diff] [blame] | 2083 | static unsigned moduleKindForDiagnostic(ModuleKind Kind); |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2084 | InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2085 | // If this ID is bogus, just return an empty input file. |
| 2086 | if (ID == 0 || ID > F.InputFilesLoaded.size()) |
| 2087 | return InputFile(); |
| 2088 | |
| 2089 | // If we've already loaded this input file, return it. |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2090 | if (F.InputFilesLoaded[ID-1].getFile()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2091 | return F.InputFilesLoaded[ID-1]; |
| 2092 | |
Argyrios Kyrtzidis | 9308f0a | 2014-01-08 19:13:34 +0000 | [diff] [blame] | 2093 | if (F.InputFilesLoaded[ID-1].isNotFound()) |
| 2094 | return InputFile(); |
| 2095 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2096 | // Go find this input file. |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2097 | BitstreamCursor &Cursor = F.InputFilesCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2098 | SavedStreamPosition SavedPosition(Cursor); |
| 2099 | Cursor.JumpToBit(F.InputFileOffsets[ID-1]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2100 | |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 2101 | InputFileInfo FI = readInputFileInfo(F, ID); |
| 2102 | off_t StoredSize = FI.StoredSize; |
| 2103 | time_t StoredTime = FI.StoredTime; |
| 2104 | bool Overridden = FI.Overridden; |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2105 | bool Transient = FI.Transient; |
Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 2106 | StringRef Filename = FI.Filename; |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2107 | |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2108 | const FileEntry *File = FileMgr.getFile(Filename, /*OpenFile=*/false); |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2109 | // If we didn't find the file, resolve it relative to the |
| 2110 | // original directory from which this AST file was created. |
Manuel Klimek | 1b29b4f | 2017-07-25 10:22:06 +0000 | [diff] [blame] | 2111 | if (File == nullptr && !F.OriginalDir.empty() && !F.BaseDirectory.empty() && |
| 2112 | F.OriginalDir != F.BaseDirectory) { |
| 2113 | std::string Resolved = resolveFileRelativeToOriginalDir( |
| 2114 | Filename, F.OriginalDir, F.BaseDirectory); |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2115 | if (!Resolved.empty()) |
| 2116 | File = FileMgr.getFile(Resolved); |
| 2117 | } |
| 2118 | |
| 2119 | // For an overridden file, create a virtual file with the stored |
| 2120 | // size/timestamp. |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2121 | if ((Overridden || Transient) && File == nullptr) |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2122 | File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime); |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2123 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 2124 | if (File == nullptr) { |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2125 | if (Complain) { |
| 2126 | std::string ErrorStr = "could not find file '"; |
| 2127 | ErrorStr += Filename; |
Richard Smith | 6814221 | 2015-10-13 01:26:26 +0000 | [diff] [blame] | 2128 | ErrorStr += "' referenced by AST file '"; |
| 2129 | ErrorStr += F.FileName; |
| 2130 | ErrorStr += "'"; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2131 | Error(ErrorStr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2132 | } |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2133 | // Record that we didn't find the file. |
| 2134 | F.InputFilesLoaded[ID-1] = InputFile::getNotFound(); |
| 2135 | return InputFile(); |
| 2136 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2137 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2138 | // Check if there was a request to override the contents of the file |
| 2139 | // that was part of the precompiled header. Overridding such a file |
| 2140 | // can lead to problems when lexing using the source locations from the |
| 2141 | // PCH. |
| 2142 | SourceManager &SM = getSourceManager(); |
Richard Smith | 64daf7b | 2015-12-01 03:32:49 +0000 | [diff] [blame] | 2143 | // FIXME: Reject if the overrides are different. |
| 2144 | if ((!Overridden && !Transient) && SM.isFileOverridden(File)) { |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2145 | if (Complain) |
| 2146 | Error(diag::err_fe_pch_file_overridden, Filename); |
| 2147 | // After emitting the diagnostic, recover by disabling the override so |
| 2148 | // that the original file will be used. |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2149 | // |
| 2150 | // FIXME: This recovery is just as broken as the original state; there may |
| 2151 | // be another precompiled module that's using the overridden contents, or |
| 2152 | // we might be half way through parsing it. Instead, we should treat the |
| 2153 | // overridden contents as belonging to a separate FileEntry. |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2154 | SM.disableFileContentsOverride(File); |
| 2155 | // The FileEntry is a virtual file entry with the size of the contents |
| 2156 | // that would override the original contents. Set it to the original's |
| 2157 | // size/time. |
| 2158 | FileMgr.modifyFileEntry(const_cast<FileEntry*>(File), |
| 2159 | StoredSize, StoredTime); |
| 2160 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2161 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2162 | bool IsOutOfDate = false; |
| 2163 | |
| 2164 | // For an overridden file, there is nothing to validate. |
Richard Smith | 96fdab6 | 2014-10-28 16:24:08 +0000 | [diff] [blame] | 2165 | if (!Overridden && // |
| 2166 | (StoredSize != File->getSize() || |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 2167 | (StoredTime && StoredTime != File->getModificationTime() && |
| 2168 | !DisableValidation) |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2169 | )) { |
| 2170 | if (Complain) { |
| 2171 | // Build a list of the PCH imports that got us here (in reverse). |
| 2172 | SmallVector<ModuleFile *, 4> ImportStack(1, &F); |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 2173 | while (!ImportStack.back()->ImportedBy.empty()) |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2174 | ImportStack.push_back(ImportStack.back()->ImportedBy[0]); |
Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 2175 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2176 | // The top-level PCH is stale. |
| 2177 | StringRef TopLevelPCHName(ImportStack.back()->FileName); |
Manman Ren | c8c9415 | 2016-10-21 23:35:03 +0000 | [diff] [blame] | 2178 | unsigned DiagnosticKind = moduleKindForDiagnostic(ImportStack.back()->Kind); |
| 2179 | if (DiagnosticKind == 0) |
| 2180 | Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName); |
| 2181 | else if (DiagnosticKind == 1) |
| 2182 | Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName); |
| 2183 | else |
| 2184 | Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName); |
Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 2185 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2186 | // Print the import stack. |
| 2187 | if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) { |
| 2188 | Diag(diag::note_pch_required_by) |
| 2189 | << Filename << ImportStack[0]->FileName; |
| 2190 | for (unsigned I = 1; I < ImportStack.size(); ++I) |
Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 2191 | Diag(diag::note_pch_required_by) |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2192 | << ImportStack[I-1]->FileName << ImportStack[I]->FileName; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 2193 | } |
| 2194 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2195 | if (!Diags.isDiagnosticInFlight()) |
| 2196 | Diag(diag::note_pch_rebuild_required) << TopLevelPCHName; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2199 | IsOutOfDate = true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2200 | } |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2201 | // FIXME: If the file is overridden and we've already opened it, |
| 2202 | // issue an error (or split it into a separate FileEntry). |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2203 | |
Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2204 | InputFile IF = InputFile(File, Overridden || Transient, IsOutOfDate); |
Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2205 | |
| 2206 | // Note that we've loaded this input file. |
| 2207 | F.InputFilesLoaded[ID-1] = IF; |
| 2208 | return IF; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2209 | } |
| 2210 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2211 | /// \brief If we are loading a relocatable PCH or module file, and the filename |
| 2212 | /// is not an absolute path, add the system or module root to the beginning of |
| 2213 | /// the file name. |
| 2214 | void ASTReader::ResolveImportedPath(ModuleFile &M, std::string &Filename) { |
| 2215 | // Resolve relative to the base directory, if we have one. |
| 2216 | if (!M.BaseDirectory.empty()) |
| 2217 | return ResolveImportedPath(Filename, M.BaseDirectory); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2218 | } |
| 2219 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2220 | void ASTReader::ResolveImportedPath(std::string &Filename, StringRef Prefix) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2221 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
| 2222 | return; |
| 2223 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2224 | SmallString<128> Buffer; |
| 2225 | llvm::sys::path::append(Buffer, Prefix, Filename); |
| 2226 | Filename.assign(Buffer.begin(), Buffer.end()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2227 | } |
| 2228 | |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2229 | static bool isDiagnosedResult(ASTReader::ASTReadResult ARR, unsigned Caps) { |
| 2230 | switch (ARR) { |
| 2231 | case ASTReader::Failure: return true; |
| 2232 | case ASTReader::Missing: return !(Caps & ASTReader::ARR_Missing); |
| 2233 | case ASTReader::OutOfDate: return !(Caps & ASTReader::ARR_OutOfDate); |
| 2234 | case ASTReader::VersionMismatch: return !(Caps & ASTReader::ARR_VersionMismatch); |
| 2235 | case ASTReader::ConfigurationMismatch: |
| 2236 | return !(Caps & ASTReader::ARR_ConfigurationMismatch); |
| 2237 | case ASTReader::HadErrors: return true; |
| 2238 | case ASTReader::Success: return false; |
| 2239 | } |
| 2240 | |
| 2241 | llvm_unreachable("unknown ASTReadResult"); |
| 2242 | } |
| 2243 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2244 | ASTReader::ASTReadResult ASTReader::ReadOptionsBlock( |
| 2245 | BitstreamCursor &Stream, unsigned ClientLoadCapabilities, |
| 2246 | bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener, |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2247 | std::string &SuggestedPredefines) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2248 | if (Stream.EnterSubBlock(OPTIONS_BLOCK_ID)) |
| 2249 | return Failure; |
| 2250 | |
| 2251 | // Read all of the records in the options block. |
| 2252 | RecordData Record; |
| 2253 | ASTReadResult Result = Success; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2254 | while (true) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2255 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2256 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2257 | switch (Entry.Kind) { |
| 2258 | case llvm::BitstreamEntry::Error: |
| 2259 | case llvm::BitstreamEntry::SubBlock: |
| 2260 | return Failure; |
| 2261 | |
| 2262 | case llvm::BitstreamEntry::EndBlock: |
| 2263 | return Result; |
| 2264 | |
| 2265 | case llvm::BitstreamEntry::Record: |
| 2266 | // The interesting case. |
| 2267 | break; |
| 2268 | } |
| 2269 | |
| 2270 | // Read and process a record. |
| 2271 | Record.clear(); |
| 2272 | switch ((OptionsRecordTypes)Stream.readRecord(Entry.ID, Record)) { |
| 2273 | case LANGUAGE_OPTIONS: { |
| 2274 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2275 | if (ParseLanguageOptions(Record, Complain, Listener, |
| 2276 | AllowCompatibleConfigurationMismatch)) |
| 2277 | Result = ConfigurationMismatch; |
| 2278 | break; |
| 2279 | } |
| 2280 | |
| 2281 | case TARGET_OPTIONS: { |
| 2282 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2283 | if (ParseTargetOptions(Record, Complain, Listener, |
| 2284 | AllowCompatibleConfigurationMismatch)) |
| 2285 | Result = ConfigurationMismatch; |
| 2286 | break; |
| 2287 | } |
| 2288 | |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2289 | case FILE_SYSTEM_OPTIONS: { |
| 2290 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2291 | if (!AllowCompatibleConfigurationMismatch && |
| 2292 | ParseFileSystemOptions(Record, Complain, Listener)) |
| 2293 | Result = ConfigurationMismatch; |
| 2294 | break; |
| 2295 | } |
| 2296 | |
| 2297 | case HEADER_SEARCH_OPTIONS: { |
| 2298 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2299 | if (!AllowCompatibleConfigurationMismatch && |
| 2300 | ParseHeaderSearchOptions(Record, Complain, Listener)) |
| 2301 | Result = ConfigurationMismatch; |
| 2302 | break; |
| 2303 | } |
| 2304 | |
| 2305 | case PREPROCESSOR_OPTIONS: |
| 2306 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2307 | if (!AllowCompatibleConfigurationMismatch && |
| 2308 | ParsePreprocessorOptions(Record, Complain, Listener, |
| 2309 | SuggestedPredefines)) |
| 2310 | Result = ConfigurationMismatch; |
| 2311 | break; |
| 2312 | } |
| 2313 | } |
| 2314 | } |
| 2315 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2316 | ASTReader::ASTReadResult |
| 2317 | ASTReader::ReadControlBlock(ModuleFile &F, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2318 | SmallVectorImpl<ImportedModule> &Loaded, |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2319 | const ModuleFile *ImportedBy, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2320 | unsigned ClientLoadCapabilities) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2321 | BitstreamCursor &Stream = F.Stream; |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2322 | ASTReadResult Result = Success; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2323 | |
| 2324 | if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
| 2325 | Error("malformed block record in AST file"); |
| 2326 | return Failure; |
| 2327 | } |
| 2328 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2329 | // Lambda to read the unhashed control block the first time it's called. |
| 2330 | // |
| 2331 | // For PCM files, the unhashed control block cannot be read until after the |
| 2332 | // MODULE_NAME record. However, PCH files have no MODULE_NAME, and yet still |
| 2333 | // need to look ahead before reading the IMPORTS record. For consistency, |
| 2334 | // this block is always read somehow (see BitstreamEntry::EndBlock). |
| 2335 | bool HasReadUnhashedControlBlock = false; |
| 2336 | auto readUnhashedControlBlockOnce = [&]() { |
| 2337 | if (!HasReadUnhashedControlBlock) { |
| 2338 | HasReadUnhashedControlBlock = true; |
| 2339 | if (ASTReadResult Result = |
| 2340 | readUnhashedControlBlock(F, ImportedBy, ClientLoadCapabilities)) |
| 2341 | return Result; |
| 2342 | } |
| 2343 | return Success; |
| 2344 | }; |
| 2345 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2346 | // Read all of the records and blocks in the control block. |
| 2347 | RecordData Record; |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2348 | unsigned NumInputs = 0; |
| 2349 | unsigned NumUserInputs = 0; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2350 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2351 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2352 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2353 | switch (Entry.Kind) { |
| 2354 | case llvm::BitstreamEntry::Error: |
| 2355 | Error("malformed block record in AST file"); |
| 2356 | return Failure; |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2357 | case llvm::BitstreamEntry::EndBlock: { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2358 | // Validate the module before returning. This call catches an AST with |
| 2359 | // no module name and no imports. |
| 2360 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2361 | return Result; |
| 2362 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2363 | // Validate input files. |
| 2364 | const HeaderSearchOptions &HSOpts = |
| 2365 | PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2366 | |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2367 | // All user input files reside at the index range [0, NumUserInputs), and |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2368 | // system input files reside at [NumUserInputs, NumInputs). For explicitly |
| 2369 | // loaded module files, ignore missing inputs. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2370 | if (!DisableValidation && F.Kind != MK_ExplicitModule && |
| 2371 | F.Kind != MK_PrebuiltModule) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2372 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2373 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2374 | // If we are reading a module, we will create a verification timestamp, |
| 2375 | // so we verify all input files. Otherwise, verify only user input |
| 2376 | // files. |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2377 | |
| 2378 | unsigned N = NumUserInputs; |
| 2379 | if (ValidateSystemInputs || |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 2380 | (HSOpts.ModulesValidateOncePerBuildSession && |
Ben Langmuir | acb803e | 2014-11-10 22:13:10 +0000 | [diff] [blame] | 2381 | F.InputFilesValidationTimestamp <= HSOpts.BuildSessionTimestamp && |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 2382 | F.Kind == MK_ImplicitModule)) |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2383 | N = NumInputs; |
| 2384 | |
Ben Langmuir | 3d4417c | 2014-02-07 17:31:11 +0000 | [diff] [blame] | 2385 | for (unsigned I = 0; I < N; ++I) { |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2386 | InputFile IF = getInputFile(F, I+1, Complain); |
| 2387 | if (!IF.getFile() || IF.isOutOfDate()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2388 | return OutOfDate; |
Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2389 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2390 | } |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2391 | |
Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 2392 | if (Listener) |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 2393 | Listener->visitModuleFile(F.FileName, F.Kind); |
Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 2394 | |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2395 | if (Listener && Listener->needsInputFileVisitation()) { |
| 2396 | unsigned N = Listener->needsSystemInputFileVisitation() ? NumInputs |
| 2397 | : NumUserInputs; |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 2398 | for (unsigned I = 0; I < N; ++I) { |
| 2399 | bool IsSystem = I >= NumUserInputs; |
| 2400 | InputFileInfo FI = readInputFileInfo(F, I+1); |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 2401 | Listener->visitInputFile(FI.Filename, IsSystem, FI.Overridden, |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2402 | F.Kind == MK_ExplicitModule || |
| 2403 | F.Kind == MK_PrebuiltModule); |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 2404 | } |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2405 | } |
| 2406 | |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2407 | return Result; |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2408 | } |
| 2409 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2410 | case llvm::BitstreamEntry::SubBlock: |
| 2411 | switch (Entry.ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2412 | case INPUT_FILES_BLOCK_ID: |
| 2413 | F.InputFilesCursor = Stream; |
| 2414 | if (Stream.SkipBlock() || // Skip with the main cursor |
| 2415 | // Read the abbreviations |
| 2416 | ReadBlockAbbrevs(F.InputFilesCursor, INPUT_FILES_BLOCK_ID)) { |
| 2417 | Error("malformed block record in AST file"); |
| 2418 | return Failure; |
| 2419 | } |
| 2420 | continue; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2421 | |
| 2422 | case OPTIONS_BLOCK_ID: |
| 2423 | // If we're reading the first module for this group, check its options |
| 2424 | // are compatible with ours. For modules it imports, no further checking |
| 2425 | // is required, because we checked them when we built it. |
| 2426 | if (Listener && !ImportedBy) { |
| 2427 | // Should we allow the configuration of the module file to differ from |
| 2428 | // the configuration of the current translation unit in a compatible |
| 2429 | // way? |
| 2430 | // |
| 2431 | // FIXME: Allow this for files explicitly specified with -include-pch. |
| 2432 | bool AllowCompatibleConfigurationMismatch = |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2433 | F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2434 | |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2435 | Result = ReadOptionsBlock(Stream, ClientLoadCapabilities, |
| 2436 | AllowCompatibleConfigurationMismatch, |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2437 | *Listener, SuggestedPredefines); |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2438 | if (Result == Failure) { |
| 2439 | Error("malformed block record in AST file"); |
| 2440 | return Result; |
| 2441 | } |
| 2442 | |
Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2443 | if (DisableValidation || |
| 2444 | (AllowConfigurationMismatch && Result == ConfigurationMismatch)) |
| 2445 | Result = Success; |
| 2446 | |
Ben Langmuir | 9b1e442e | 2016-02-11 18:54:02 +0000 | [diff] [blame] | 2447 | // If we can't load the module, exit early since we likely |
| 2448 | // will rebuild the module anyway. The stream may be in the |
| 2449 | // middle of a block. |
| 2450 | if (Result != Success) |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2451 | return Result; |
| 2452 | } else if (Stream.SkipBlock()) { |
| 2453 | Error("malformed block record in AST file"); |
| 2454 | return Failure; |
| 2455 | } |
| 2456 | continue; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2457 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2458 | default: |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2459 | if (Stream.SkipBlock()) { |
| 2460 | Error("malformed block record in AST file"); |
| 2461 | return Failure; |
| 2462 | } |
| 2463 | continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2464 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2465 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2466 | case llvm::BitstreamEntry::Record: |
| 2467 | // The interesting case. |
| 2468 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2469 | } |
| 2470 | |
| 2471 | // Read and process a record. |
| 2472 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2473 | StringRef Blob; |
| 2474 | switch ((ControlRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2475 | case METADATA: { |
| 2476 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 2477 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 2478 | Diag(Record[0] < VERSION_MAJOR? diag::err_pch_version_too_old |
| 2479 | : diag::err_pch_version_too_new); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2480 | return VersionMismatch; |
| 2481 | } |
| 2482 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 2483 | bool hasErrors = Record[6]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2484 | if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) { |
| 2485 | Diag(diag::err_pch_with_compiler_errors); |
| 2486 | return HadErrors; |
| 2487 | } |
Argyrios Kyrtzidis | 70ec1c7 | 2016-07-13 20:35:26 +0000 | [diff] [blame] | 2488 | if (hasErrors) { |
| 2489 | Diags.ErrorOccurred = true; |
| 2490 | Diags.UncompilableErrorOccurred = true; |
| 2491 | Diags.UnrecoverableErrorOccurred = true; |
| 2492 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2493 | |
| 2494 | F.RelocatablePCH = Record[4]; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2495 | // Relative paths in a relocatable PCH are relative to our sysroot. |
| 2496 | if (F.RelocatablePCH) |
| 2497 | F.BaseDirectory = isysroot.empty() ? "/" : isysroot; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2498 | |
Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 2499 | F.HasTimestamps = Record[5]; |
| 2500 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2501 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2502 | StringRef ASTBranch = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2503 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2504 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 2505 | Diag(diag::err_pch_different_branch) << ASTBranch << CurBranch; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2506 | return VersionMismatch; |
| 2507 | } |
| 2508 | break; |
| 2509 | } |
| 2510 | |
| 2511 | case IMPORTS: { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2512 | // Validate the AST before processing any imports (otherwise, untangling |
| 2513 | // them can be error-prone and expensive). A module will have a name and |
| 2514 | // will already have been validated, but this catches the PCH case. |
| 2515 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2516 | return Result; |
| 2517 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2518 | // Load each of the imported PCH files. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2519 | unsigned Idx = 0, N = Record.size(); |
| 2520 | while (Idx < N) { |
| 2521 | // Read information about the AST file. |
| 2522 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 2523 | // The import location will be the local one for now; we will adjust |
| 2524 | // all import locations of module imports after the global source |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2525 | // location info are setup, in ReadAST. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2526 | SourceLocation ImportLoc = |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2527 | ReadUntranslatedSourceLocation(Record[Idx++]); |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 2528 | off_t StoredSize = (off_t)Record[Idx++]; |
| 2529 | time_t StoredModTime = (time_t)Record[Idx++]; |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2530 | ASTFileSignature StoredSignature = { |
| 2531 | {{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++], |
| 2532 | (uint32_t)Record[Idx++], (uint32_t)Record[Idx++], |
| 2533 | (uint32_t)Record[Idx++]}}}; |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 2534 | |
| 2535 | std::string ImportedName = ReadString(Record, Idx); |
| 2536 | std::string ImportedFile; |
| 2537 | |
| 2538 | // For prebuilt and explicit modules first consult the file map for |
| 2539 | // an override. Note that here we don't search prebuilt module |
| 2540 | // directories, only the explicit name to file mappings. Also, we will |
| 2541 | // still verify the size/signature making sure it is essentially the |
| 2542 | // same file but perhaps in a different location. |
| 2543 | if (ImportedKind == MK_PrebuiltModule || ImportedKind == MK_ExplicitModule) |
| 2544 | ImportedFile = PP.getHeaderSearchInfo().getPrebuiltModuleFileName( |
| 2545 | ImportedName, /*FileMapOnly*/ true); |
| 2546 | |
| 2547 | if (ImportedFile.empty()) |
| 2548 | ImportedFile = ReadPath(F, Record, Idx); |
| 2549 | else |
| 2550 | SkipPath(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2551 | |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2552 | // If our client can't cope with us being out of date, we can't cope with |
| 2553 | // our dependency being missing. |
| 2554 | unsigned Capabilities = ClientLoadCapabilities; |
| 2555 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 2556 | Capabilities &= ~ARR_Missing; |
| 2557 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2558 | // Load the AST file. |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2559 | auto Result = ReadASTCore(ImportedFile, ImportedKind, ImportLoc, &F, |
| 2560 | Loaded, StoredSize, StoredModTime, |
| 2561 | StoredSignature, Capabilities); |
| 2562 | |
| 2563 | // If we diagnosed a problem, produce a backtrace. |
| 2564 | if (isDiagnosedResult(Result, Capabilities)) |
| 2565 | Diag(diag::note_module_file_imported_by) |
| 2566 | << F.FileName << !F.ModuleName.empty() << F.ModuleName; |
| 2567 | |
| 2568 | switch (Result) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2569 | case Failure: return Failure; |
| 2570 | // 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] | 2571 | case Missing: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2572 | case OutOfDate: return OutOfDate; |
| 2573 | case VersionMismatch: return VersionMismatch; |
| 2574 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 2575 | case HadErrors: return HadErrors; |
| 2576 | case Success: break; |
| 2577 | } |
| 2578 | } |
| 2579 | break; |
| 2580 | } |
| 2581 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2582 | case ORIGINAL_FILE: |
| 2583 | F.OriginalSourceFileID = FileID::get(Record[0]); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2584 | F.ActualOriginalSourceFileName = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2585 | F.OriginalSourceFileName = F.ActualOriginalSourceFileName; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2586 | ResolveImportedPath(F, F.OriginalSourceFileName); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2587 | break; |
| 2588 | |
| 2589 | case ORIGINAL_FILE_ID: |
| 2590 | F.OriginalSourceFileID = FileID::get(Record[0]); |
| 2591 | break; |
| 2592 | |
| 2593 | case ORIGINAL_PCH_DIR: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2594 | F.OriginalDir = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2595 | break; |
| 2596 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2597 | case MODULE_NAME: |
| 2598 | F.ModuleName = Blob; |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 2599 | if (Listener) |
| 2600 | Listener->ReadModuleName(F.ModuleName); |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2601 | |
| 2602 | // Validate the AST as soon as we have a name so we can exit early on |
| 2603 | // failure. |
| 2604 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2605 | return Result; |
| 2606 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2607 | break; |
| 2608 | |
Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2609 | case MODULE_DIRECTORY: { |
| 2610 | assert(!F.ModuleName.empty() && |
| 2611 | "MODULE_DIRECTORY found before MODULE_NAME"); |
| 2612 | // If we've already loaded a module map file covering this module, we may |
| 2613 | // have a better path for it (relative to the current build). |
| 2614 | Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName); |
| 2615 | if (M && M->Directory) { |
| 2616 | // If we're implicitly loading a module, the base directory can't |
| 2617 | // change between the build and use. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2618 | if (F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) { |
Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2619 | const DirectoryEntry *BuildDir = |
| 2620 | PP.getFileManager().getDirectory(Blob); |
| 2621 | if (!BuildDir || BuildDir != M->Directory) { |
| 2622 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 2623 | Diag(diag::err_imported_module_relocated) |
| 2624 | << F.ModuleName << Blob << M->Directory->getName(); |
| 2625 | return OutOfDate; |
| 2626 | } |
| 2627 | } |
| 2628 | F.BaseDirectory = M->Directory->getName(); |
| 2629 | } else { |
| 2630 | F.BaseDirectory = Blob; |
| 2631 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2632 | break; |
Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2633 | } |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2634 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2635 | case MODULE_MAP_FILE: |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 2636 | if (ASTReadResult Result = |
| 2637 | ReadModuleMapFileBlock(Record, F, ImportedBy, ClientLoadCapabilities)) |
| 2638 | return Result; |
Ben Langmuir | 264ea15 | 2014-11-08 00:06:39 +0000 | [diff] [blame] | 2639 | break; |
| 2640 | |
Justin Bogner | ca9c0cc | 2015-06-21 20:32:36 +0000 | [diff] [blame] | 2641 | case INPUT_FILE_OFFSETS: |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2642 | NumInputs = Record[0]; |
| 2643 | NumUserInputs = Record[1]; |
Justin Bogner | 4c18324 | 2015-06-21 20:32:40 +0000 | [diff] [blame] | 2644 | F.InputFileOffsets = |
| 2645 | (const llvm::support::unaligned_uint64_t *)Blob.data(); |
Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2646 | F.InputFilesLoaded.resize(NumInputs); |
Argyrios Kyrtzidis | a38cb20 | 2017-01-30 06:05:58 +0000 | [diff] [blame] | 2647 | F.NumUserInputFiles = NumUserInputs; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2648 | break; |
| 2649 | } |
| 2650 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2651 | } |
| 2652 | |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2653 | ASTReader::ASTReadResult |
| 2654 | ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2655 | BitstreamCursor &Stream = F.Stream; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2656 | |
| 2657 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
| 2658 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2659 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2660 | } |
| 2661 | |
| 2662 | // Read all of the records and blocks for the AST file. |
| 2663 | RecordData Record; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2664 | while (true) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2665 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2666 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2667 | switch (Entry.Kind) { |
| 2668 | case llvm::BitstreamEntry::Error: |
| 2669 | Error("error at end of module block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2670 | return Failure; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 2671 | case llvm::BitstreamEntry::EndBlock: |
Richard Smith | c0fbba7 | 2013-04-03 22:49:41 +0000 | [diff] [blame] | 2672 | // Outside of C++, we do not store a lookup map for the translation unit. |
| 2673 | // Instead, mark it as needing a lookup map to be built if this module |
| 2674 | // contains any declarations lexically within it (which it always does!). |
| 2675 | // This usually has no cost, since we very rarely need the lookup map for |
| 2676 | // the translation unit outside C++. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2677 | if (ASTContext *Ctx = ContextObj) { |
| 2678 | DeclContext *DC = Ctx->getTranslationUnitDecl(); |
| 2679 | if (DC->hasExternalLexicalStorage() && !Ctx->getLangOpts().CPlusPlus) |
| 2680 | DC->setMustBuildLookupTable(); |
| 2681 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2682 | |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2683 | return Success; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2684 | case llvm::BitstreamEntry::SubBlock: |
| 2685 | switch (Entry.ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2686 | case DECLTYPES_BLOCK_ID: |
| 2687 | // We lazily load the decls block, but we want to set up the |
| 2688 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 2689 | // cursor to it, enter the block and read the abbrevs in that block. |
| 2690 | // With the main cursor, we just skip over it. |
| 2691 | F.DeclsCursor = Stream; |
| 2692 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 2693 | // Read the abbrevs. |
| 2694 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
| 2695 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2696 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2697 | } |
| 2698 | break; |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 2699 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2700 | case PREPROCESSOR_BLOCK_ID: |
| 2701 | F.MacroCursor = Stream; |
| 2702 | if (!PP.getExternalSource()) |
| 2703 | PP.setExternalSource(this); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2704 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2705 | if (Stream.SkipBlock() || |
| 2706 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
| 2707 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2708 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2709 | } |
| 2710 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
| 2711 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2712 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2713 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 2714 | F.PreprocessorDetailCursor = Stream; |
| 2715 | if (Stream.SkipBlock() || |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2716 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2717 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2718 | Error("malformed preprocessor detail record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2719 | return Failure; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2720 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2721 | F.PreprocessorDetailStartOffset |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2722 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2723 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2724 | if (!PP.getPreprocessingRecord()) |
| 2725 | PP.createPreprocessingRecord(); |
| 2726 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2727 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2728 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2729 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2730 | case SOURCE_MANAGER_BLOCK_ID: |
| 2731 | if (ReadSourceManagerBlock(F)) |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2732 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2733 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2734 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2735 | case SUBMODULE_BLOCK_ID: |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2736 | if (ASTReadResult Result = |
| 2737 | ReadSubmoduleBlock(F, ClientLoadCapabilities)) |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2738 | return Result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2739 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2740 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2741 | case COMMENTS_BLOCK_ID: { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2742 | BitstreamCursor C = Stream; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2743 | if (Stream.SkipBlock() || |
| 2744 | ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) { |
| 2745 | Error("malformed comments block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2746 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2747 | } |
| 2748 | CommentsCursors.push_back(std::make_pair(C, &F)); |
| 2749 | break; |
| 2750 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2751 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2752 | default: |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2753 | if (Stream.SkipBlock()) { |
| 2754 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2755 | return Failure; |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2756 | } |
| 2757 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2758 | } |
| 2759 | continue; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2760 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2761 | case llvm::BitstreamEntry::Record: |
| 2762 | // The interesting case. |
| 2763 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | // Read and process a record. |
| 2767 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2768 | StringRef Blob; |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2769 | auto RecordType = |
| 2770 | (ASTRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob); |
| 2771 | |
| 2772 | // If we're not loading an AST context, we don't care about most records. |
| 2773 | if (!ContextObj) { |
| 2774 | switch (RecordType) { |
| 2775 | case IDENTIFIER_TABLE: |
| 2776 | case IDENTIFIER_OFFSET: |
| 2777 | case INTERESTING_IDENTIFIERS: |
| 2778 | case STATISTICS: |
| 2779 | case PP_CONDITIONAL_STACK: |
| 2780 | case PP_COUNTER_VALUE: |
| 2781 | case SOURCE_LOCATION_OFFSETS: |
| 2782 | case MODULE_OFFSET_MAP: |
| 2783 | case SOURCE_MANAGER_LINE_TABLE: |
| 2784 | case SOURCE_LOCATION_PRELOADS: |
| 2785 | case PPD_ENTITIES_OFFSETS: |
| 2786 | case HEADER_SEARCH_TABLE: |
| 2787 | case IMPORTED_MODULES: |
| 2788 | case MACRO_OFFSET: |
| 2789 | break; |
| 2790 | default: |
| 2791 | continue; |
| 2792 | } |
| 2793 | } |
| 2794 | |
| 2795 | switch (RecordType) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2796 | default: // Default behavior: ignore. |
| 2797 | break; |
| 2798 | |
| 2799 | case TYPE_OFFSET: { |
| 2800 | if (F.LocalNumTypes != 0) { |
| 2801 | Error("duplicate TYPE_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2802 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2803 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2804 | F.TypeOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2805 | F.LocalNumTypes = Record[0]; |
| 2806 | unsigned LocalBaseTypeIndex = Record[1]; |
| 2807 | F.BaseTypeIndex = getTotalNumTypes(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2808 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2809 | if (F.LocalNumTypes > 0) { |
| 2810 | // Introduce the global -> local mapping for types within this module. |
| 2811 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2812 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2813 | // Introduce the local -> global mapping for types within this module. |
| 2814 | F.TypeRemap.insertOrReplace( |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2815 | std::make_pair(LocalBaseTypeIndex, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2816 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2817 | |
| 2818 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2819 | } |
| 2820 | break; |
| 2821 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2822 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2823 | case DECL_OFFSET: { |
| 2824 | if (F.LocalNumDecls != 0) { |
| 2825 | Error("duplicate DECL_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2826 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2827 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2828 | F.DeclOffsets = (const DeclOffset *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2829 | F.LocalNumDecls = Record[0]; |
| 2830 | unsigned LocalBaseDeclID = Record[1]; |
| 2831 | F.BaseDeclID = getTotalNumDecls(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2832 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2833 | if (F.LocalNumDecls > 0) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2834 | // Introduce the global -> local mapping for declarations within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2835 | // module. |
| 2836 | GlobalDeclMap.insert( |
| 2837 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2838 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2839 | // Introduce the local -> global mapping for declarations within this |
| 2840 | // module. |
| 2841 | F.DeclRemap.insertOrReplace( |
| 2842 | std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2843 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2844 | // Introduce the global -> local mapping for declarations within this |
| 2845 | // module. |
| 2846 | F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID; |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 2847 | |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2848 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 2849 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2850 | break; |
| 2851 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2852 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2853 | case TU_UPDATE_LEXICAL: { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2854 | DeclContext *TU = ContextObj->getTranslationUnitDecl(); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2855 | LexicalContents Contents( |
| 2856 | reinterpret_cast<const llvm::support::unaligned_uint32_t *>( |
| 2857 | Blob.data()), |
| 2858 | static_cast<unsigned int>(Blob.size() / 4)); |
| 2859 | TULexicalDecls.push_back(std::make_pair(&F, Contents)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2860 | TU->setHasExternalLexicalStorage(true); |
| 2861 | break; |
| 2862 | } |
| 2863 | |
| 2864 | case UPDATE_VISIBLE: { |
| 2865 | unsigned Idx = 0; |
| 2866 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 2867 | auto *Data = (const unsigned char*)Blob.data(); |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 2868 | PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&F, Data}); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 2869 | // If we've already loaded the decl, perform the updates when we finish |
| 2870 | // loading this block. |
| 2871 | if (Decl *D = GetExistingDecl(ID)) |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 2872 | PendingUpdateRecords.push_back( |
| 2873 | PendingUpdateRecord(ID, D, /*JustLoaded=*/false)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2874 | break; |
| 2875 | } |
| 2876 | |
| 2877 | case IDENTIFIER_TABLE: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2878 | F.IdentifierTableData = Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2879 | if (Record[0]) { |
Justin Bogner | da4e650 | 2014-04-14 16:34:29 +0000 | [diff] [blame] | 2880 | F.IdentifierLookupTable = ASTIdentifierLookupTable::Create( |
| 2881 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2882 | (const unsigned char *)F.IdentifierTableData + sizeof(uint32_t), |
| 2883 | (const unsigned char *)F.IdentifierTableData, |
| 2884 | ASTIdentifierLookupTrait(*this, F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2885 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2886 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
| 2887 | } |
| 2888 | break; |
| 2889 | |
| 2890 | case IDENTIFIER_OFFSET: { |
| 2891 | if (F.LocalNumIdentifiers != 0) { |
| 2892 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2893 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2894 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2895 | F.IdentifierOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2896 | F.LocalNumIdentifiers = Record[0]; |
| 2897 | unsigned LocalBaseIdentifierID = Record[1]; |
| 2898 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2899 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2900 | if (F.LocalNumIdentifiers > 0) { |
| 2901 | // Introduce the global -> local mapping for identifiers within this |
| 2902 | // module. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2903 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2904 | &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2905 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2906 | // Introduce the local -> global mapping for identifiers within this |
| 2907 | // module. |
| 2908 | F.IdentifierRemap.insertOrReplace( |
| 2909 | std::make_pair(LocalBaseIdentifierID, |
| 2910 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 2911 | |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2912 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 2913 | + F.LocalNumIdentifiers); |
| 2914 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2915 | break; |
| 2916 | } |
| 2917 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 2918 | case INTERESTING_IDENTIFIERS: |
| 2919 | F.PreloadIdentifierOffsets.assign(Record.begin(), Record.end()); |
| 2920 | break; |
| 2921 | |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2922 | case EAGERLY_DESERIALIZED_DECLS: |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 2923 | // FIXME: Skip reading this record if our ASTConsumer doesn't care |
| 2924 | // about "interesting" decls (for instance, if we're building a module). |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2925 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2926 | EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2927 | break; |
| 2928 | |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2929 | case MODULAR_CODEGEN_DECLS: |
| 2930 | // FIXME: Skip reading this record if our ASTConsumer doesn't care about |
| 2931 | // them (ie: if we're not codegenerating this module). |
| 2932 | if (F.Kind == MK_MainFile) |
| 2933 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2934 | EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2935 | break; |
| 2936 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2937 | case SPECIAL_TYPES: |
Douglas Gregor | 44180f8 | 2013-02-01 23:45:03 +0000 | [diff] [blame] | 2938 | if (SpecialTypes.empty()) { |
| 2939 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2940 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
| 2941 | break; |
| 2942 | } |
| 2943 | |
| 2944 | if (SpecialTypes.size() != Record.size()) { |
| 2945 | Error("invalid special-types record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2946 | return Failure; |
Douglas Gregor | 44180f8 | 2013-02-01 23:45:03 +0000 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 2950 | serialization::TypeID ID = getGlobalTypeID(F, Record[I]); |
| 2951 | if (!SpecialTypes[I]) |
| 2952 | SpecialTypes[I] = ID; |
| 2953 | // FIXME: If ID && SpecialTypes[I] != ID, do we need a separate |
| 2954 | // merge step? |
| 2955 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2956 | break; |
| 2957 | |
| 2958 | case STATISTICS: |
| 2959 | TotalNumStatements += Record[0]; |
| 2960 | TotalNumMacros += Record[1]; |
| 2961 | TotalLexicalDeclContexts += Record[2]; |
| 2962 | TotalVisibleDeclContexts += Record[3]; |
| 2963 | break; |
| 2964 | |
| 2965 | case UNUSED_FILESCOPED_DECLS: |
| 2966 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2967 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2968 | break; |
| 2969 | |
| 2970 | case DELEGATING_CTORS: |
| 2971 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2972 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2973 | break; |
| 2974 | |
| 2975 | case WEAK_UNDECLARED_IDENTIFIERS: |
| 2976 | if (Record.size() % 4 != 0) { |
| 2977 | Error("invalid weak identifiers record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2978 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2979 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2980 | |
| 2981 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2982 | // files. This isn't the way to do it :) |
| 2983 | WeakUndeclaredIdentifiers.clear(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2984 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2985 | // Translate the weak, undeclared identifiers into global IDs. |
| 2986 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 2987 | WeakUndeclaredIdentifiers.push_back( |
| 2988 | getGlobalIdentifierID(F, Record[I++])); |
| 2989 | WeakUndeclaredIdentifiers.push_back( |
| 2990 | getGlobalIdentifierID(F, Record[I++])); |
| 2991 | WeakUndeclaredIdentifiers.push_back( |
| 2992 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 2993 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 2994 | } |
| 2995 | break; |
| 2996 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2997 | case SELECTOR_OFFSETS: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2998 | F.SelectorOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2999 | F.LocalNumSelectors = Record[0]; |
| 3000 | unsigned LocalBaseSelectorID = Record[1]; |
| 3001 | F.BaseSelectorID = getTotalNumSelectors(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3002 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3003 | if (F.LocalNumSelectors > 0) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3004 | // Introduce the global -> local mapping for selectors within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3005 | // module. |
| 3006 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3007 | |
| 3008 | // Introduce the local -> global mapping for selectors within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3009 | // module. |
| 3010 | F.SelectorRemap.insertOrReplace( |
| 3011 | std::make_pair(LocalBaseSelectorID, |
| 3012 | F.BaseSelectorID - LocalBaseSelectorID)); |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3013 | |
| 3014 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3015 | } |
| 3016 | break; |
| 3017 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3018 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3019 | case METHOD_POOL: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3020 | F.SelectorLookupTableData = (const unsigned char *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3021 | if (Record[0]) |
| 3022 | F.SelectorLookupTable |
| 3023 | = ASTSelectorLookupTable::Create( |
| 3024 | F.SelectorLookupTableData + Record[0], |
| 3025 | F.SelectorLookupTableData, |
| 3026 | ASTSelectorLookupTrait(*this, F)); |
| 3027 | TotalNumMethodPoolEntries += Record[1]; |
| 3028 | break; |
| 3029 | |
| 3030 | case REFERENCED_SELECTOR_POOL: |
| 3031 | if (!Record.empty()) { |
| 3032 | 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] | 3033 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3034 | Record[Idx++])); |
| 3035 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 3036 | getRawEncoding()); |
| 3037 | } |
| 3038 | } |
| 3039 | break; |
| 3040 | |
Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 3041 | case PP_CONDITIONAL_STACK: |
| 3042 | if (!Record.empty()) { |
Erik Verbruggen | 4d1eb2d | 2017-11-03 09:40:07 +0000 | [diff] [blame] | 3043 | unsigned Idx = 0, End = Record.size() - 1; |
| 3044 | bool ReachedEOFWhileSkipping = Record[Idx++]; |
| 3045 | llvm::Optional<Preprocessor::PreambleSkipInfo> SkipInfo; |
| 3046 | if (ReachedEOFWhileSkipping) { |
| 3047 | SourceLocation HashToken = ReadSourceLocation(F, Record, Idx); |
| 3048 | SourceLocation IfTokenLoc = ReadSourceLocation(F, Record, Idx); |
| 3049 | bool FoundNonSkipPortion = Record[Idx++]; |
| 3050 | bool FoundElse = Record[Idx++]; |
| 3051 | SourceLocation ElseLoc = ReadSourceLocation(F, Record, Idx); |
| 3052 | SkipInfo.emplace(HashToken, IfTokenLoc, FoundNonSkipPortion, |
| 3053 | FoundElse, ElseLoc); |
| 3054 | } |
Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 3055 | SmallVector<PPConditionalInfo, 4> ConditionalStack; |
Erik Verbruggen | 4d1eb2d | 2017-11-03 09:40:07 +0000 | [diff] [blame] | 3056 | while (Idx < End) { |
Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 3057 | auto Loc = ReadSourceLocation(F, Record, Idx); |
| 3058 | bool WasSkipping = Record[Idx++]; |
| 3059 | bool FoundNonSkip = Record[Idx++]; |
| 3060 | bool FoundElse = Record[Idx++]; |
| 3061 | ConditionalStack.push_back( |
| 3062 | {Loc, WasSkipping, FoundNonSkip, FoundElse}); |
| 3063 | } |
Erik Verbruggen | 4d1eb2d | 2017-11-03 09:40:07 +0000 | [diff] [blame] | 3064 | PP.setReplayablePreambleConditionalStack(ConditionalStack, SkipInfo); |
Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 3065 | } |
| 3066 | break; |
| 3067 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3068 | case PP_COUNTER_VALUE: |
| 3069 | if (!Record.empty() && Listener) |
| 3070 | Listener->ReadCounter(F, Record[0]); |
| 3071 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3072 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3073 | case FILE_SORTED_DECLS: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3074 | F.FileSortedDecls = (const DeclID *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3075 | F.NumFileSortedDecls = Record[0]; |
| 3076 | break; |
| 3077 | |
| 3078 | case SOURCE_LOCATION_OFFSETS: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3079 | F.SLocEntryOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3080 | F.LocalNumSLocEntries = Record[0]; |
| 3081 | unsigned SLocSpaceSize = Record[1]; |
Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 3082 | std::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3083 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3084 | SLocSpaceSize); |
Richard Smith | 78d81ec | 2015-08-12 22:25:24 +0000 | [diff] [blame] | 3085 | if (!F.SLocEntryBaseID) { |
| 3086 | Error("ran out of source locations"); |
| 3087 | break; |
| 3088 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3089 | // Make our entry in the range map. BaseID is negative and growing, so |
| 3090 | // we invert it. Because we invert it, though, we need the other end of |
| 3091 | // the range. |
| 3092 | unsigned RangeStart = |
| 3093 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 3094 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 3095 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 3096 | |
| 3097 | // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. |
| 3098 | assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); |
| 3099 | GlobalSLocOffsetMap.insert( |
| 3100 | std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset |
| 3101 | - SLocSpaceSize,&F)); |
| 3102 | |
| 3103 | // Initialize the remapping table. |
| 3104 | // Invalid stays invalid. |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 3105 | F.SLocRemap.insertOrReplace(std::make_pair(0U, 0)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3106 | // This module. Base was 2 when being compiled. |
Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 3107 | F.SLocRemap.insertOrReplace(std::make_pair(2U, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3108 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3109 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3110 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
| 3111 | break; |
| 3112 | } |
| 3113 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3114 | case MODULE_OFFSET_MAP: |
| 3115 | F.ModuleOffsetMap = Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3116 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3117 | |
| 3118 | case SOURCE_MANAGER_LINE_TABLE: |
| 3119 | if (ParseLineTable(F, Record)) |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3120 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3121 | break; |
| 3122 | |
| 3123 | case SOURCE_LOCATION_PRELOADS: { |
| 3124 | // Need to transform from the local view (1-based IDs) to the global view, |
| 3125 | // which is based off F.SLocEntryBaseID. |
| 3126 | if (!F.PreloadSLocEntries.empty()) { |
| 3127 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3128 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3129 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3130 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3131 | F.PreloadSLocEntries.swap(Record); |
| 3132 | break; |
| 3133 | } |
| 3134 | |
| 3135 | case EXT_VECTOR_DECLS: |
| 3136 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3137 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 3138 | break; |
| 3139 | |
| 3140 | case VTABLE_USES: |
| 3141 | if (Record.size() % 3 != 0) { |
| 3142 | Error("Invalid VTABLE_USES record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3143 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3144 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3145 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3146 | // Later tables overwrite earlier ones. |
| 3147 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 3148 | // the right way to do this. |
| 3149 | VTableUses.clear(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3150 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3151 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 3152 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 3153 | VTableUses.push_back( |
| 3154 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 3155 | VTableUses.push_back(Record[Idx++]); |
| 3156 | } |
| 3157 | break; |
| 3158 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3159 | case PENDING_IMPLICIT_INSTANTIATIONS: |
| 3160 | if (PendingInstantiations.size() % 2 != 0) { |
| 3161 | Error("Invalid existing PendingInstantiations"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3162 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | if (Record.size() % 2 != 0) { |
| 3166 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3167 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3168 | } |
| 3169 | |
| 3170 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 3171 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 3172 | PendingInstantiations.push_back( |
| 3173 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3174 | } |
| 3175 | break; |
| 3176 | |
| 3177 | case SEMA_DECL_REFS: |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 3178 | if (Record.size() != 3) { |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 3179 | Error("Invalid SEMA_DECL_REFS block"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3180 | return Failure; |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 3181 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3182 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3183 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
| 3184 | break; |
| 3185 | |
| 3186 | case PPD_ENTITIES_OFFSETS: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3187 | F.PreprocessedEntityOffsets = (const PPEntityOffset *)Blob.data(); |
| 3188 | assert(Blob.size() % sizeof(PPEntityOffset) == 0); |
| 3189 | F.NumPreprocessedEntities = Blob.size() / sizeof(PPEntityOffset); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3190 | |
| 3191 | unsigned LocalBasePreprocessedEntityID = Record[0]; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3192 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3193 | unsigned StartingID; |
| 3194 | if (!PP.getPreprocessingRecord()) |
| 3195 | PP.createPreprocessingRecord(); |
| 3196 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 3197 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3198 | StartingID |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3199 | = PP.getPreprocessingRecord() |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3200 | ->allocateLoadedEntities(F.NumPreprocessedEntities); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3201 | F.BasePreprocessedEntityID = StartingID; |
| 3202 | |
| 3203 | if (F.NumPreprocessedEntities > 0) { |
| 3204 | // Introduce the global -> local mapping for preprocessed entities in |
| 3205 | // this module. |
| 3206 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3207 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3208 | // Introduce the local -> global mapping for preprocessed entities in |
| 3209 | // this module. |
| 3210 | F.PreprocessedEntityRemap.insertOrReplace( |
| 3211 | std::make_pair(LocalBasePreprocessedEntityID, |
| 3212 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 3213 | } |
| 3214 | |
| 3215 | break; |
| 3216 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3217 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 3218 | case DECL_UPDATE_OFFSETS: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3219 | if (Record.size() % 2 != 0) { |
| 3220 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3221 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3222 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3223 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) { |
| 3224 | GlobalDeclID ID = getGlobalDeclID(F, Record[I]); |
| 3225 | DeclUpdateOffsets[ID].push_back(std::make_pair(&F, Record[I + 1])); |
| 3226 | |
| 3227 | // If we've already loaded the decl, perform the updates when we finish |
| 3228 | // loading this block. |
| 3229 | if (Decl *D = GetExistingDecl(ID)) |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3230 | PendingUpdateRecords.push_back( |
| 3231 | PendingUpdateRecord(ID, D, /*JustLoaded=*/false)); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3232 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3233 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3234 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 3235 | case OBJC_CATEGORIES_MAP: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3236 | if (F.LocalNumObjCCategoriesInMap != 0) { |
| 3237 | Error("duplicate OBJC_CATEGORIES_MAP record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3238 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3239 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3240 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3241 | F.LocalNumObjCCategoriesInMap = Record[0]; |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3242 | F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3243 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3244 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3245 | case OBJC_CATEGORIES: |
| 3246 | F.ObjCCategories.swap(Record); |
| 3247 | break; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 3248 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3249 | case CUDA_SPECIAL_DECL_REFS: |
| 3250 | // Later tables overwrite earlier ones. |
| 3251 | // FIXME: Modules will have trouble with this. |
| 3252 | CUDASpecialDeclRefs.clear(); |
| 3253 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3254 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
| 3255 | break; |
| 3256 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 3257 | case HEADER_SEARCH_TABLE: |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3258 | F.HeaderFileInfoTableData = Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3259 | F.LocalNumHeaderFileInfos = Record[1]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3260 | if (Record[0]) { |
| 3261 | F.HeaderFileInfoTable |
| 3262 | = HeaderFileInfoLookupTable::Create( |
| 3263 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 3264 | (const unsigned char *)F.HeaderFileInfoTableData, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3265 | HeaderFileInfoTrait(*this, F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3266 | &PP.getHeaderSearchInfo(), |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3267 | Blob.data() + Record[2])); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3268 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3269 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 3270 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 3271 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
| 3272 | } |
| 3273 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3274 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3275 | case FP_PRAGMA_OPTIONS: |
| 3276 | // Later tables overwrite earlier ones. |
| 3277 | FPPragmaOptions.swap(Record); |
| 3278 | break; |
| 3279 | |
| 3280 | case OPENCL_EXTENSIONS: |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3281 | for (unsigned I = 0, E = Record.size(); I != E; ) { |
| 3282 | auto Name = ReadString(Record, I); |
| 3283 | auto &Opt = OpenCLExtensions.OptMap[Name]; |
Yaxun Liu | cc2741c | 2016-12-18 06:35:06 +0000 | [diff] [blame] | 3284 | Opt.Supported = Record[I++] != 0; |
| 3285 | Opt.Enabled = Record[I++] != 0; |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3286 | Opt.Avail = Record[I++]; |
| 3287 | Opt.Core = Record[I++]; |
| 3288 | } |
| 3289 | break; |
| 3290 | |
| 3291 | case OPENCL_EXTENSION_TYPES: |
| 3292 | for (unsigned I = 0, E = Record.size(); I != E;) { |
| 3293 | auto TypeID = static_cast<::TypeID>(Record[I++]); |
| 3294 | auto *Type = GetType(TypeID).getTypePtr(); |
| 3295 | auto NumExt = static_cast<unsigned>(Record[I++]); |
| 3296 | for (unsigned II = 0; II != NumExt; ++II) { |
| 3297 | auto Ext = ReadString(Record, I); |
| 3298 | OpenCLTypeExtMap[Type].insert(Ext); |
| 3299 | } |
| 3300 | } |
| 3301 | break; |
| 3302 | |
| 3303 | case OPENCL_EXTENSION_DECLS: |
| 3304 | for (unsigned I = 0, E = Record.size(); I != E;) { |
| 3305 | auto DeclID = static_cast<::DeclID>(Record[I++]); |
| 3306 | auto *Decl = GetDecl(DeclID); |
| 3307 | auto NumExt = static_cast<unsigned>(Record[I++]); |
| 3308 | for (unsigned II = 0; II != NumExt; ++II) { |
| 3309 | auto Ext = ReadString(Record, I); |
| 3310 | OpenCLDeclExtMap[Decl].insert(Ext); |
| 3311 | } |
| 3312 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3313 | break; |
| 3314 | |
| 3315 | case TENTATIVE_DEFINITIONS: |
| 3316 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3317 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
| 3318 | break; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3319 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3320 | case KNOWN_NAMESPACES: |
| 3321 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3322 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
| 3323 | break; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3324 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3325 | case UNDEFINED_BUT_USED: |
| 3326 | if (UndefinedButUsed.size() % 2 != 0) { |
| 3327 | Error("Invalid existing UndefinedButUsed"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3328 | return Failure; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | if (Record.size() % 2 != 0) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3332 | Error("invalid undefined-but-used record"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3333 | return Failure; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3334 | } |
| 3335 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3336 | UndefinedButUsed.push_back(getGlobalDeclID(F, Record[I++])); |
| 3337 | UndefinedButUsed.push_back( |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3338 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3339 | } |
| 3340 | break; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 3341 | |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 3342 | case DELETE_EXPRS_TO_ANALYZE: |
| 3343 | for (unsigned I = 0, N = Record.size(); I != N;) { |
| 3344 | DelayedDeleteExprs.push_back(getGlobalDeclID(F, Record[I++])); |
| 3345 | const uint64_t Count = Record[I++]; |
| 3346 | DelayedDeleteExprs.push_back(Count); |
| 3347 | for (uint64_t C = 0; C < Count; ++C) { |
| 3348 | DelayedDeleteExprs.push_back(ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3349 | bool IsArrayForm = Record[I++] == 1; |
| 3350 | DelayedDeleteExprs.push_back(IsArrayForm); |
| 3351 | } |
| 3352 | } |
| 3353 | break; |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3354 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 3355 | case IMPORTED_MODULES: |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 3356 | if (!F.isModule()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3357 | // If we aren't loading a module (which has its own exports), make |
| 3358 | // all of the imported modules visible. |
| 3359 | // FIXME: Deal with macros-only imports. |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 3360 | for (unsigned I = 0, N = Record.size(); I != N; /**/) { |
| 3361 | unsigned GlobalID = getGlobalSubmoduleID(F, Record[I++]); |
| 3362 | SourceLocation Loc = ReadSourceLocation(F, Record, I); |
Graydon Hoare | 9c98244 | 2017-01-18 20:36:59 +0000 | [diff] [blame] | 3363 | if (GlobalID) { |
Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 3364 | ImportedModules.push_back(ImportedSubmodule(GlobalID, Loc)); |
Graydon Hoare | 9c98244 | 2017-01-18 20:36:59 +0000 | [diff] [blame] | 3365 | if (DeserializationListener) |
| 3366 | DeserializationListener->ModuleImportRead(GlobalID, Loc); |
| 3367 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3368 | } |
| 3369 | } |
| 3370 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3371 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3372 | case MACRO_OFFSET: { |
| 3373 | if (F.LocalNumMacros != 0) { |
| 3374 | Error("duplicate MACRO_OFFSET record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3375 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3376 | } |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3377 | F.MacroOffsets = (const uint32_t *)Blob.data(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3378 | F.LocalNumMacros = Record[0]; |
| 3379 | unsigned LocalBaseMacroID = Record[1]; |
| 3380 | F.BaseMacroID = getTotalNumMacros(); |
| 3381 | |
| 3382 | if (F.LocalNumMacros > 0) { |
| 3383 | // Introduce the global -> local mapping for macros within this module. |
| 3384 | GlobalMacroMap.insert(std::make_pair(getTotalNumMacros() + 1, &F)); |
| 3385 | |
| 3386 | // Introduce the local -> global mapping for macros within this module. |
| 3387 | F.MacroRemap.insertOrReplace( |
| 3388 | std::make_pair(LocalBaseMacroID, |
| 3389 | F.BaseMacroID - LocalBaseMacroID)); |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3390 | |
| 3391 | MacrosLoaded.resize(MacrosLoaded.size() + F.LocalNumMacros); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3392 | } |
| 3393 | break; |
| 3394 | } |
| 3395 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 3396 | case LATE_PARSED_TEMPLATE: |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3397 | LateParsedTemplates.append(Record.begin(), Record.end()); |
| 3398 | break; |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 3399 | |
| 3400 | case OPTIMIZE_PRAGMA_OPTIONS: |
| 3401 | if (Record.size() != 1) { |
| 3402 | Error("invalid pragma optimize record"); |
| 3403 | return Failure; |
| 3404 | } |
| 3405 | OptimizeOffPragmaLocation = ReadSourceLocation(F, Record[0]); |
| 3406 | break; |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 3407 | |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 3408 | case MSSTRUCT_PRAGMA_OPTIONS: |
| 3409 | if (Record.size() != 1) { |
| 3410 | Error("invalid pragma ms_struct record"); |
| 3411 | return Failure; |
| 3412 | } |
| 3413 | PragmaMSStructState = Record[0]; |
| 3414 | break; |
| 3415 | |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 3416 | case POINTERS_TO_MEMBERS_PRAGMA_OPTIONS: |
| 3417 | if (Record.size() != 2) { |
| 3418 | Error("invalid pragma ms_struct record"); |
| 3419 | return Failure; |
| 3420 | } |
| 3421 | PragmaMSPointersToMembersState = Record[0]; |
| 3422 | PointersToMembersPragmaLocation = ReadSourceLocation(F, Record[1]); |
| 3423 | break; |
| 3424 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 3425 | case UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES: |
| 3426 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3427 | UnusedLocalTypedefNameCandidates.push_back( |
| 3428 | getGlobalDeclID(F, Record[I])); |
| 3429 | break; |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 3430 | |
| 3431 | case CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH: |
| 3432 | if (Record.size() != 1) { |
| 3433 | Error("invalid cuda pragma options record"); |
| 3434 | return Failure; |
| 3435 | } |
| 3436 | ForceCUDAHostDeviceDepth = Record[0]; |
| 3437 | break; |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 3438 | |
| 3439 | case PACK_PRAGMA_OPTIONS: { |
| 3440 | if (Record.size() < 3) { |
| 3441 | Error("invalid pragma pack record"); |
| 3442 | return Failure; |
| 3443 | } |
| 3444 | PragmaPackCurrentValue = Record[0]; |
| 3445 | PragmaPackCurrentLocation = ReadSourceLocation(F, Record[1]); |
| 3446 | unsigned NumStackEntries = Record[2]; |
| 3447 | unsigned Idx = 3; |
| 3448 | // Reset the stack when importing a new module. |
| 3449 | PragmaPackStack.clear(); |
| 3450 | for (unsigned I = 0; I < NumStackEntries; ++I) { |
| 3451 | PragmaPackStackEntry Entry; |
| 3452 | Entry.Value = Record[Idx++]; |
| 3453 | Entry.Location = ReadSourceLocation(F, Record[Idx++]); |
Alex Lorenz | 45b4014 | 2017-07-28 14:41:21 +0000 | [diff] [blame] | 3454 | Entry.PushLocation = ReadSourceLocation(F, Record[Idx++]); |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 3455 | PragmaPackStrings.push_back(ReadString(Record, Idx)); |
| 3456 | Entry.SlotLabel = PragmaPackStrings.back(); |
| 3457 | PragmaPackStack.push_back(Entry); |
| 3458 | } |
| 3459 | break; |
| 3460 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3461 | } |
| 3462 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3463 | } |
| 3464 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3465 | void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const { |
| 3466 | assert(!F.ModuleOffsetMap.empty() && "no module offset map to read"); |
| 3467 | |
| 3468 | // Additional remapping information. |
| 3469 | const unsigned char *Data = (const unsigned char*)F.ModuleOffsetMap.data(); |
| 3470 | const unsigned char *DataEnd = Data + F.ModuleOffsetMap.size(); |
| 3471 | F.ModuleOffsetMap = StringRef(); |
| 3472 | |
| 3473 | // If we see this entry before SOURCE_LOCATION_OFFSETS, add placeholders. |
| 3474 | if (F.SLocRemap.find(0) == F.SLocRemap.end()) { |
| 3475 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 3476 | F.SLocRemap.insert(std::make_pair(2U, 1)); |
| 3477 | } |
| 3478 | |
| 3479 | // Continuous range maps we may be updating in our module. |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 3480 | using RemapBuilder = ContinuousRangeMap<uint32_t, int, 2>::Builder; |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3481 | RemapBuilder SLocRemap(F.SLocRemap); |
| 3482 | RemapBuilder IdentifierRemap(F.IdentifierRemap); |
| 3483 | RemapBuilder MacroRemap(F.MacroRemap); |
| 3484 | RemapBuilder PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 3485 | RemapBuilder SubmoduleRemap(F.SubmoduleRemap); |
| 3486 | RemapBuilder SelectorRemap(F.SelectorRemap); |
| 3487 | RemapBuilder DeclRemap(F.DeclRemap); |
| 3488 | RemapBuilder TypeRemap(F.TypeRemap); |
| 3489 | |
| 3490 | while (Data < DataEnd) { |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 3491 | // FIXME: Looking up dependency modules by filename is horrible. Let's |
| 3492 | // start fixing this with prebuilt and explicit modules and see how it |
| 3493 | // goes... |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3494 | using namespace llvm::support; |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 3495 | ModuleKind Kind = static_cast<ModuleKind>( |
| 3496 | endian::readNext<uint8_t, little, unaligned>(Data)); |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3497 | uint16_t Len = endian::readNext<uint16_t, little, unaligned>(Data); |
| 3498 | StringRef Name = StringRef((const char*)Data, Len); |
| 3499 | Data += Len; |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 3500 | ModuleFile *OM = (Kind == MK_PrebuiltModule || Kind == MK_ExplicitModule |
| 3501 | ? ModuleMgr.lookupByModuleName(Name) |
| 3502 | : ModuleMgr.lookupByFileName(Name)); |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3503 | if (!OM) { |
| 3504 | std::string Msg = |
| 3505 | "SourceLocation remap refers to unknown module, cannot find "; |
| 3506 | Msg.append(Name); |
| 3507 | Error(Msg); |
| 3508 | return; |
| 3509 | } |
| 3510 | |
| 3511 | uint32_t SLocOffset = |
| 3512 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3513 | uint32_t IdentifierIDOffset = |
| 3514 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3515 | uint32_t MacroIDOffset = |
| 3516 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3517 | uint32_t PreprocessedEntityIDOffset = |
| 3518 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3519 | uint32_t SubmoduleIDOffset = |
| 3520 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3521 | uint32_t SelectorIDOffset = |
| 3522 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3523 | uint32_t DeclIDOffset = |
| 3524 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3525 | uint32_t TypeIndexOffset = |
| 3526 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3527 | |
| 3528 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 3529 | |
| 3530 | auto mapOffset = [&](uint32_t Offset, uint32_t BaseOffset, |
| 3531 | RemapBuilder &Remap) { |
| 3532 | if (Offset != None) |
| 3533 | Remap.insert(std::make_pair(Offset, |
| 3534 | static_cast<int>(BaseOffset - Offset))); |
| 3535 | }; |
| 3536 | mapOffset(SLocOffset, OM->SLocEntryBaseOffset, SLocRemap); |
| 3537 | mapOffset(IdentifierIDOffset, OM->BaseIdentifierID, IdentifierRemap); |
| 3538 | mapOffset(MacroIDOffset, OM->BaseMacroID, MacroRemap); |
| 3539 | mapOffset(PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID, |
| 3540 | PreprocessedEntityRemap); |
| 3541 | mapOffset(SubmoduleIDOffset, OM->BaseSubmoduleID, SubmoduleRemap); |
| 3542 | mapOffset(SelectorIDOffset, OM->BaseSelectorID, SelectorRemap); |
| 3543 | mapOffset(DeclIDOffset, OM->BaseDeclID, DeclRemap); |
| 3544 | mapOffset(TypeIndexOffset, OM->BaseTypeIndex, TypeRemap); |
| 3545 | |
| 3546 | // Global -> local mappings. |
| 3547 | F.GlobalToLocalDeclIDs[OM] = DeclIDOffset; |
| 3548 | } |
| 3549 | } |
| 3550 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3551 | ASTReader::ASTReadResult |
| 3552 | ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, |
| 3553 | const ModuleFile *ImportedBy, |
| 3554 | unsigned ClientLoadCapabilities) { |
| 3555 | unsigned Idx = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3556 | F.ModuleMapPath = ReadPath(F, Record, Idx); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3557 | |
| 3558 | // Try to resolve ModuleName in the current header search context and |
| 3559 | // verify that it is found in the same module map file as we saved. If the |
| 3560 | // top-level AST file is a main file, skip this check because there is no |
| 3561 | // usable header search context. |
| 3562 | assert(!F.ModuleName.empty() && |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3563 | "MODULE_NAME should come before MODULE_MAP_FILE"); |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 3564 | if (F.Kind == MK_ImplicitModule && ModuleMgr.begin()->Kind != MK_MainFile) { |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3565 | // An implicitly-loaded module file should have its module listed in some |
| 3566 | // module map file that we've already loaded. |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3567 | Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName); |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3568 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
| 3569 | const FileEntry *ModMap = M ? Map.getModuleMapFileForUniquing(M) : nullptr; |
| 3570 | if (!ModMap) { |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3571 | assert(ImportedBy && "top-level import should be verified"); |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3572 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) { |
Bruno Cardoso Lopes | a66a325 | 2017-11-17 03:24:11 +0000 | [diff] [blame] | 3573 | if (auto *ASTFE = M ? M->getASTFile() : nullptr) { |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3574 | // This module was defined by an imported (explicit) module. |
| 3575 | Diag(diag::err_module_file_conflict) << F.ModuleName << F.FileName |
| 3576 | << ASTFE->getName(); |
Bruno Cardoso Lopes | a66a325 | 2017-11-17 03:24:11 +0000 | [diff] [blame] | 3577 | } else { |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3578 | // This module was built with a different module map. |
| 3579 | Diag(diag::err_imported_module_not_found) |
| 3580 | << F.ModuleName << F.FileName << ImportedBy->FileName |
| 3581 | << F.ModuleMapPath; |
Bruno Cardoso Lopes | a66a325 | 2017-11-17 03:24:11 +0000 | [diff] [blame] | 3582 | // In case it was imported by a PCH, there's a chance the user is |
| 3583 | // just missing to include the search path to the directory containing |
| 3584 | // the modulemap. |
| 3585 | if (ImportedBy->Kind == MK_PCH) |
| 3586 | Diag(diag::note_imported_by_pch_module_not_found) |
| 3587 | << llvm::sys::path::parent_path(F.ModuleMapPath); |
| 3588 | } |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3589 | } |
| 3590 | return OutOfDate; |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3591 | } |
| 3592 | |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3593 | assert(M->Name == F.ModuleName && "found module with different name"); |
| 3594 | |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3595 | // Check the primary module map file. |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3596 | const FileEntry *StoredModMap = FileMgr.getFile(F.ModuleMapPath); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3597 | if (StoredModMap == nullptr || StoredModMap != ModMap) { |
| 3598 | assert(ModMap && "found module is missing module map file"); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3599 | assert(ImportedBy && "top-level import should be verified"); |
| 3600 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3601 | Diag(diag::err_imported_module_modmap_changed) |
| 3602 | << F.ModuleName << ImportedBy->FileName |
| 3603 | << ModMap->getName() << F.ModuleMapPath; |
| 3604 | return OutOfDate; |
| 3605 | } |
| 3606 | |
| 3607 | llvm::SmallPtrSet<const FileEntry *, 1> AdditionalStoredMaps; |
| 3608 | for (unsigned I = 0, N = Record[Idx++]; I < N; ++I) { |
| 3609 | // FIXME: we should use input files rather than storing names. |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3610 | std::string Filename = ReadPath(F, Record, Idx); |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3611 | const FileEntry *F = |
| 3612 | FileMgr.getFile(Filename, false, false); |
| 3613 | if (F == nullptr) { |
| 3614 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3615 | Error("could not find file '" + Filename +"' referenced by AST file"); |
| 3616 | return OutOfDate; |
| 3617 | } |
| 3618 | AdditionalStoredMaps.insert(F); |
| 3619 | } |
| 3620 | |
| 3621 | // Check any additional module map files (e.g. module.private.modulemap) |
| 3622 | // that are not in the pcm. |
| 3623 | if (auto *AdditionalModuleMaps = Map.getAdditionalModuleMapFiles(M)) { |
| 3624 | for (const FileEntry *ModMap : *AdditionalModuleMaps) { |
| 3625 | // Remove files that match |
| 3626 | // Note: SmallPtrSet::erase is really remove |
| 3627 | if (!AdditionalStoredMaps.erase(ModMap)) { |
| 3628 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3629 | Diag(diag::err_module_different_modmap) |
| 3630 | << F.ModuleName << /*new*/0 << ModMap->getName(); |
| 3631 | return OutOfDate; |
| 3632 | } |
| 3633 | } |
| 3634 | } |
| 3635 | |
| 3636 | // Check any additional module map files that are in the pcm, but not |
| 3637 | // found in header search. Cases that match are already removed. |
| 3638 | for (const FileEntry *ModMap : AdditionalStoredMaps) { |
| 3639 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3640 | Diag(diag::err_module_different_modmap) |
| 3641 | << F.ModuleName << /*not new*/1 << ModMap->getName(); |
| 3642 | return OutOfDate; |
| 3643 | } |
| 3644 | } |
| 3645 | |
| 3646 | if (Listener) |
| 3647 | Listener->ReadModuleMapFile(F.ModuleMapPath); |
| 3648 | return Success; |
| 3649 | } |
| 3650 | |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3651 | /// \brief Move the given method to the back of the global list of methods. |
| 3652 | static void moveMethodToBackOfGlobalList(Sema &S, ObjCMethodDecl *Method) { |
| 3653 | // Find the entry for this selector in the method pool. |
| 3654 | Sema::GlobalMethodPool::iterator Known |
| 3655 | = S.MethodPool.find(Method->getSelector()); |
| 3656 | if (Known == S.MethodPool.end()) |
| 3657 | return; |
| 3658 | |
| 3659 | // Retrieve the appropriate method list. |
| 3660 | ObjCMethodList &Start = Method->isInstanceMethod()? Known->second.first |
| 3661 | : Known->second.second; |
| 3662 | bool Found = false; |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3663 | for (ObjCMethodList *List = &Start; List; List = List->getNext()) { |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3664 | if (!Found) { |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3665 | if (List->getMethod() == Method) { |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3666 | Found = true; |
| 3667 | } else { |
| 3668 | // Keep searching. |
| 3669 | continue; |
| 3670 | } |
| 3671 | } |
| 3672 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3673 | if (List->getNext()) |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3674 | List->setMethod(List->getNext()->getMethod()); |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3675 | else |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3676 | List->setMethod(Method); |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3677 | } |
| 3678 | } |
| 3679 | |
Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 3680 | void ASTReader::makeNamesVisible(const HiddenNames &Names, Module *Owner) { |
Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 3681 | assert(Owner->NameVisibility != Module::Hidden && "nothing to make visible?"); |
Richard Smith | 20e883e | 2015-04-29 23:20:19 +0000 | [diff] [blame] | 3682 | for (Decl *D : Names) { |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 3683 | bool wasHidden = D->isHidden(); |
| 3684 | D->setVisibleDespiteOwningModule(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3685 | |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3686 | if (wasHidden && SemaObj) { |
| 3687 | if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D)) { |
| 3688 | moveMethodToBackOfGlobalList(*SemaObj, Method); |
Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3689 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3690 | } |
| 3691 | } |
| 3692 | } |
| 3693 | |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3694 | void ASTReader::makeModuleVisible(Module *Mod, |
Argyrios Kyrtzidis | 125df05 | 2013-02-01 16:36:12 +0000 | [diff] [blame] | 3695 | Module::NameVisibilityKind NameVisibility, |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 3696 | SourceLocation ImportLoc) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3697 | llvm::SmallPtrSet<Module *, 4> Visited; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3698 | SmallVector<Module *, 4> Stack; |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3699 | Stack.push_back(Mod); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3700 | while (!Stack.empty()) { |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3701 | Mod = Stack.pop_back_val(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3702 | |
| 3703 | if (NameVisibility <= Mod->NameVisibility) { |
Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3704 | // This module already has this level of visibility (or greater), so |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3705 | // there is nothing more to do. |
| 3706 | continue; |
| 3707 | } |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3708 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3709 | if (!Mod->isAvailable()) { |
| 3710 | // Modules that aren't available cannot be made visible. |
| 3711 | continue; |
| 3712 | } |
| 3713 | |
| 3714 | // Update the module's name visibility. |
| 3715 | Mod->NameVisibility = NameVisibility; |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3716 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3717 | // If we've already deserialized any names from this module, |
| 3718 | // mark them as visible. |
| 3719 | HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod); |
| 3720 | if (Hidden != HiddenNamesMap.end()) { |
Richard Smith | 57721ac | 2014-07-21 04:10:40 +0000 | [diff] [blame] | 3721 | auto HiddenNames = std::move(*Hidden); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3722 | HiddenNamesMap.erase(Hidden); |
Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 3723 | makeNamesVisible(HiddenNames.second, HiddenNames.first); |
Richard Smith | 57721ac | 2014-07-21 04:10:40 +0000 | [diff] [blame] | 3724 | assert(HiddenNamesMap.find(Mod) == HiddenNamesMap.end() && |
| 3725 | "making names visible added hidden names"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3726 | } |
Dmitri Gribenko | e9bcf5b | 2013-11-04 21:51:33 +0000 | [diff] [blame] | 3727 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3728 | // Push any exported modules onto the stack to be marked as visible. |
Argyrios Kyrtzidis | 8739f7b | 2013-02-19 19:34:40 +0000 | [diff] [blame] | 3729 | SmallVector<Module *, 16> Exports; |
| 3730 | Mod->getExportedModules(Exports); |
| 3731 | for (SmallVectorImpl<Module *>::iterator |
| 3732 | I = Exports.begin(), E = Exports.end(); I != E; ++I) { |
| 3733 | Module *Exported = *I; |
David Blaikie | 82e95a3 | 2014-11-19 07:49:47 +0000 | [diff] [blame] | 3734 | if (Visited.insert(Exported).second) |
Argyrios Kyrtzidis | 8739f7b | 2013-02-19 19:34:40 +0000 | [diff] [blame] | 3735 | Stack.push_back(Exported); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3736 | } |
| 3737 | } |
| 3738 | } |
| 3739 | |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 3740 | /// We've merged the definition \p MergedDef into the existing definition |
| 3741 | /// \p Def. Ensure that \p Def is made visible whenever \p MergedDef is made |
| 3742 | /// visible. |
| 3743 | void ASTReader::mergeDefinitionVisibility(NamedDecl *Def, |
| 3744 | NamedDecl *MergedDef) { |
Benjamin Kramer | a72a70a | 2016-10-17 13:00:44 +0000 | [diff] [blame] | 3745 | // FIXME: This doesn't correctly handle the case where MergedDef is visible |
| 3746 | // in modules other than its owning module. We should instead give the |
| 3747 | // ASTContext a list of merged definitions for Def. |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 3748 | if (Def->isHidden()) { |
| 3749 | // If MergedDef is visible or becomes visible, make the definition visible. |
Benjamin Kramer | a72a70a | 2016-10-17 13:00:44 +0000 | [diff] [blame] | 3750 | if (!MergedDef->isHidden()) |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 3751 | Def->setVisibleDespiteOwningModule(); |
Benjamin Kramer | a72a70a | 2016-10-17 13:00:44 +0000 | [diff] [blame] | 3752 | else if (getContext().getLangOpts().ModulesLocalVisibility) { |
| 3753 | getContext().mergeDefinitionIntoModule( |
| 3754 | Def, MergedDef->getImportedOwningModule(), |
| 3755 | /*NotifyListeners*/ false); |
| 3756 | PendingMergedDefinitionsToDeduplicate.insert(Def); |
| 3757 | } else { |
| 3758 | auto SubmoduleID = MergedDef->getOwningModuleID(); |
| 3759 | assert(SubmoduleID && "hidden definition in no module"); |
| 3760 | HiddenNamesMap[getSubmodule(SubmoduleID)].push_back(Def); |
| 3761 | } |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 3762 | } |
| 3763 | } |
| 3764 | |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3765 | bool ASTReader::loadGlobalIndex() { |
| 3766 | if (GlobalIndex) |
| 3767 | return false; |
| 3768 | |
| 3769 | if (TriedLoadingGlobalIndex || !UseGlobalIndex || |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3770 | !PP.getLangOpts().Modules) |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3771 | return true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3772 | |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3773 | // Try to load the global index. |
| 3774 | TriedLoadingGlobalIndex = true; |
| 3775 | StringRef ModuleCachePath |
| 3776 | = getPreprocessor().getHeaderSearchInfo().getModuleCachePath(); |
| 3777 | std::pair<GlobalModuleIndex *, GlobalModuleIndex::ErrorCode> Result |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3778 | = GlobalModuleIndex::readIndex(ModuleCachePath); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3779 | if (!Result.first) |
| 3780 | return true; |
| 3781 | |
| 3782 | GlobalIndex.reset(Result.first); |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 3783 | ModuleMgr.setGlobalIndex(GlobalIndex.get()); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3784 | return false; |
| 3785 | } |
| 3786 | |
| 3787 | bool ASTReader::isGlobalIndexUnavailable() const { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3788 | return PP.getLangOpts().Modules && UseGlobalIndex && |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3789 | !hasGlobalIndex() && TriedLoadingGlobalIndex; |
| 3790 | } |
| 3791 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3792 | static void updateModuleTimestamp(ModuleFile &MF) { |
| 3793 | // Overwrite the timestamp file contents so that file's mtime changes. |
| 3794 | std::string TimestampFilename = MF.getTimestampFilename(); |
Rafael Espindola | dae941a | 2014-08-25 18:17:04 +0000 | [diff] [blame] | 3795 | std::error_code EC; |
| 3796 | llvm::raw_fd_ostream OS(TimestampFilename, EC, llvm::sys::fs::F_Text); |
| 3797 | if (EC) |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3798 | return; |
| 3799 | OS << "Timestamp file\n"; |
Alex Lorenz | 0bafa02 | 2017-06-02 10:36:56 +0000 | [diff] [blame] | 3800 | OS.close(); |
| 3801 | OS.clear_error(); // Avoid triggering a fatal error. |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3802 | } |
| 3803 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3804 | /// \brief Given a cursor at the start of an AST file, scan ahead and drop the |
| 3805 | /// cursor into the start of the given block ID, returning false on success and |
| 3806 | /// true on failure. |
| 3807 | static bool SkipCursorToBlock(BitstreamCursor &Cursor, unsigned BlockID) { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3808 | while (true) { |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3809 | llvm::BitstreamEntry Entry = Cursor.advance(); |
| 3810 | switch (Entry.Kind) { |
| 3811 | case llvm::BitstreamEntry::Error: |
| 3812 | case llvm::BitstreamEntry::EndBlock: |
| 3813 | return true; |
| 3814 | |
| 3815 | case llvm::BitstreamEntry::Record: |
| 3816 | // Ignore top-level records. |
| 3817 | Cursor.skipRecord(Entry.ID); |
| 3818 | break; |
| 3819 | |
| 3820 | case llvm::BitstreamEntry::SubBlock: |
| 3821 | if (Entry.ID == BlockID) { |
| 3822 | if (Cursor.EnterSubBlock(BlockID)) |
| 3823 | return true; |
| 3824 | // Found it! |
| 3825 | return false; |
| 3826 | } |
| 3827 | |
| 3828 | if (Cursor.SkipBlock()) |
| 3829 | return true; |
| 3830 | } |
| 3831 | } |
| 3832 | } |
| 3833 | |
Benjamin Kramer | 0772c42 | 2016-02-13 13:42:54 +0000 | [diff] [blame] | 3834 | ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3835 | ModuleKind Type, |
| 3836 | SourceLocation ImportLoc, |
Graydon Hoare | e7196af | 2016-12-09 21:45:49 +0000 | [diff] [blame] | 3837 | unsigned ClientLoadCapabilities, |
| 3838 | SmallVectorImpl<ImportedSubmodule> *Imported) { |
Argyrios Kyrtzidis | dc9fdaf | 2013-05-24 05:44:08 +0000 | [diff] [blame] | 3839 | llvm::SaveAndRestore<SourceLocation> |
| 3840 | SetCurImportLocRAII(CurrentImportLoc, ImportLoc); |
| 3841 | |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 3842 | // Defer any pending actions until we get to the end of reading the AST file. |
| 3843 | Deserializing AnASTFile(this); |
| 3844 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3845 | // Bump the generation number. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3846 | unsigned PreviousGeneration = 0; |
| 3847 | if (ContextObj) |
| 3848 | PreviousGeneration = incrementGeneration(*ContextObj); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3849 | |
| 3850 | unsigned NumModules = ModuleMgr.size(); |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3851 | SmallVector<ImportedModule, 4> Loaded; |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 3852 | switch (ASTReadResult ReadResult = |
| 3853 | ReadASTCore(FileName, Type, ImportLoc, |
| 3854 | /*ImportedBy=*/nullptr, Loaded, 0, 0, |
| 3855 | ASTFileSignature(), ClientLoadCapabilities)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3856 | case Failure: |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3857 | case Missing: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3858 | case OutOfDate: |
| 3859 | case VersionMismatch: |
| 3860 | case ConfigurationMismatch: |
Ben Langmuir | 9801b25 | 2014-06-20 00:24:56 +0000 | [diff] [blame] | 3861 | case HadErrors: { |
| 3862 | llvm::SmallPtrSet<ModuleFile *, 4> LoadedSet; |
| 3863 | for (const ImportedModule &IM : Loaded) |
| 3864 | LoadedSet.insert(IM.Mod); |
| 3865 | |
Duncan P. N. Exon Smith | 8e6bc197 | 2017-01-28 23:02:12 +0000 | [diff] [blame] | 3866 | ModuleMgr.removeModules(ModuleMgr.begin() + NumModules, LoadedSet, |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3867 | PP.getLangOpts().Modules |
Duncan P. N. Exon Smith | 8e6bc197 | 2017-01-28 23:02:12 +0000 | [diff] [blame] | 3868 | ? &PP.getHeaderSearchInfo().getModuleMap() |
| 3869 | : nullptr); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3870 | |
| 3871 | // If we find that any modules are unusable, the global index is going |
| 3872 | // to be out-of-date. Just remove it. |
| 3873 | GlobalIndex.reset(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3874 | ModuleMgr.setGlobalIndex(nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3875 | return ReadResult; |
Ben Langmuir | 9801b25 | 2014-06-20 00:24:56 +0000 | [diff] [blame] | 3876 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3877 | case Success: |
| 3878 | break; |
| 3879 | } |
| 3880 | |
| 3881 | // Here comes stuff that we only do once the entire chain is loaded. |
| 3882 | |
| 3883 | // Load the AST blocks of all of the modules that we loaded. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3884 | for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(), |
| 3885 | MEnd = Loaded.end(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3886 | M != MEnd; ++M) { |
| 3887 | ModuleFile &F = *M->Mod; |
| 3888 | |
| 3889 | // Read the AST block. |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3890 | if (ASTReadResult Result = ReadASTBlock(F, ClientLoadCapabilities)) |
| 3891 | return Result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3892 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3893 | // Read the extension blocks. |
| 3894 | while (!SkipCursorToBlock(F.Stream, EXTENSION_BLOCK_ID)) { |
| 3895 | if (ASTReadResult Result = ReadExtensionBlock(F)) |
| 3896 | return Result; |
| 3897 | } |
| 3898 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3899 | // 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] | 3900 | // bits of all files we've seen. |
| 3901 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 3902 | TotalModulesSizeInBits += F.SizeInBits; |
| 3903 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3904 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3905 | // Preload SLocEntries. |
| 3906 | for (unsigned I = 0, N = F.PreloadSLocEntries.size(); I != N; ++I) { |
| 3907 | int Index = int(F.PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
| 3908 | // Load it through the SourceManager and don't call ReadSLocEntry() |
| 3909 | // directly because the entry may have already been loaded in which case |
| 3910 | // calling ReadSLocEntry() directly would trigger an assertion in |
| 3911 | // SourceManager. |
| 3912 | SourceMgr.getLoadedSLocEntryByID(Index); |
| 3913 | } |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3914 | |
Richard Smith | ea74148 | 2017-05-01 22:10:47 +0000 | [diff] [blame] | 3915 | // Map the original source file ID into the ID space of the current |
| 3916 | // compilation. |
| 3917 | if (F.OriginalSourceFileID.isValid()) { |
| 3918 | F.OriginalSourceFileID = FileID::get( |
| 3919 | F.SLocEntryBaseID + F.OriginalSourceFileID.getOpaqueValue() - 1); |
| 3920 | } |
| 3921 | |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3922 | // Preload all the pending interesting identifiers by marking them out of |
| 3923 | // date. |
| 3924 | for (auto Offset : F.PreloadIdentifierOffsets) { |
| 3925 | const unsigned char *Data = reinterpret_cast<const unsigned char *>( |
| 3926 | F.IdentifierTableData + Offset); |
| 3927 | |
| 3928 | ASTIdentifierLookupTrait Trait(*this, F); |
| 3929 | auto KeyDataLen = Trait.ReadKeyDataLength(Data); |
| 3930 | auto Key = Trait.ReadKey(Data, KeyDataLen.first); |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 3931 | auto &II = PP.getIdentifierTable().getOwn(Key); |
| 3932 | II.setOutOfDate(true); |
| 3933 | |
| 3934 | // Mark this identifier as being from an AST file so that we can track |
| 3935 | // whether we need to serialize it. |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 3936 | markIdentifierFromAST(*this, II); |
Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 3937 | |
| 3938 | // Associate the ID with the identifier so that the writer can reuse it. |
| 3939 | auto ID = Trait.ReadIdentifierID(Data + KeyDataLen.first); |
| 3940 | SetIdentifierInfo(ID, &II); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3941 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3942 | } |
| 3943 | |
Douglas Gregor | 603cd86 | 2013-03-22 18:50:14 +0000 | [diff] [blame] | 3944 | // Setup the import locations and notify the module manager that we've |
| 3945 | // committed to these module files. |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3946 | for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(), |
| 3947 | MEnd = Loaded.end(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3948 | M != MEnd; ++M) { |
| 3949 | ModuleFile &F = *M->Mod; |
Douglas Gregor | 603cd86 | 2013-03-22 18:50:14 +0000 | [diff] [blame] | 3950 | |
| 3951 | ModuleMgr.moduleFileAccepted(&F); |
| 3952 | |
| 3953 | // Set the import location. |
Argyrios Kyrtzidis | 71c1af8 | 2013-02-01 16:36:14 +0000 | [diff] [blame] | 3954 | F.DirectImportLoc = ImportLoc; |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 3955 | // FIXME: We assume that locations from PCH / preamble do not need |
| 3956 | // any translation. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3957 | if (!M->ImportedBy) |
| 3958 | F.ImportLoc = M->ImportLoc; |
| 3959 | else |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 3960 | F.ImportLoc = TranslateSourceLocation(*M->ImportedBy, M->ImportLoc); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3961 | } |
| 3962 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3963 | if (!PP.getLangOpts().CPlusPlus || |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 3964 | (Type != MK_ImplicitModule && Type != MK_ExplicitModule && |
| 3965 | Type != MK_PrebuiltModule)) { |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3966 | // Mark all of the identifiers in the identifier table as being out of date, |
| 3967 | // so that various accessors know to check the loaded modules when the |
| 3968 | // identifier is used. |
| 3969 | // |
| 3970 | // For C++ modules, we don't need information on many identifiers (just |
| 3971 | // those that provide macros or are poisoned), so we mark all of |
| 3972 | // the interesting ones via PreloadIdentifierOffsets. |
| 3973 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 3974 | IdEnd = PP.getIdentifierTable().end(); |
| 3975 | Id != IdEnd; ++Id) |
| 3976 | Id->second->setOutOfDate(true); |
| 3977 | } |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 3978 | // Mark selectors as out of date. |
| 3979 | for (auto Sel : SelectorGeneration) |
| 3980 | SelectorOutOfDate[Sel.first] = true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3981 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3982 | // Resolve any unresolved module exports. |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3983 | for (unsigned I = 0, N = UnresolvedModuleRefs.size(); I != N; ++I) { |
| 3984 | UnresolvedModuleRef &Unresolved = UnresolvedModuleRefs[I]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3985 | SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID); |
| 3986 | Module *ResolvedMod = getSubmodule(GlobalID); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 3987 | |
| 3988 | switch (Unresolved.Kind) { |
| 3989 | case UnresolvedModuleRef::Conflict: |
| 3990 | if (ResolvedMod) { |
| 3991 | Module::Conflict Conflict; |
| 3992 | Conflict.Other = ResolvedMod; |
| 3993 | Conflict.Message = Unresolved.String.str(); |
| 3994 | Unresolved.Mod->Conflicts.push_back(Conflict); |
| 3995 | } |
| 3996 | continue; |
| 3997 | |
| 3998 | case UnresolvedModuleRef::Import: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3999 | if (ResolvedMod) |
Richard Smith | 38477db | 2015-05-02 00:45:56 +0000 | [diff] [blame] | 4000 | Unresolved.Mod->Imports.insert(ResolvedMod); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4001 | continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4002 | |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4003 | case UnresolvedModuleRef::Export: |
| 4004 | if (ResolvedMod || Unresolved.IsWildcard) |
| 4005 | Unresolved.Mod->Exports.push_back( |
| 4006 | Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard)); |
| 4007 | continue; |
| 4008 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4009 | } |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4010 | UnresolvedModuleRefs.clear(); |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 4011 | |
Graydon Hoare | e7196af | 2016-12-09 21:45:49 +0000 | [diff] [blame] | 4012 | if (Imported) |
| 4013 | Imported->append(ImportedModules.begin(), |
| 4014 | ImportedModules.end()); |
| 4015 | |
Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 4016 | // FIXME: How do we load the 'use'd modules? They may not be submodules. |
| 4017 | // Might be unnecessary as use declarations are only used to build the |
| 4018 | // module itself. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4019 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4020 | if (ContextObj) |
| 4021 | InitializeContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4022 | |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 4023 | if (SemaObj) |
| 4024 | UpdateSema(); |
| 4025 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4026 | if (DeserializationListener) |
| 4027 | DeserializationListener->ReaderInitialized(this); |
| 4028 | |
| 4029 | ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule(); |
Yaron Keren | 8b56366 | 2015-10-03 10:46:20 +0000 | [diff] [blame] | 4030 | if (PrimaryModule.OriginalSourceFileID.isValid()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4031 | // If this AST file is a precompiled preamble, then set the |
| 4032 | // preamble file ID of the source manager to the file source file |
| 4033 | // from which the preamble was built. |
| 4034 | if (Type == MK_Preamble) { |
| 4035 | SourceMgr.setPreambleFileID(PrimaryModule.OriginalSourceFileID); |
| 4036 | } else if (Type == MK_MainFile) { |
| 4037 | SourceMgr.setMainFileID(PrimaryModule.OriginalSourceFileID); |
| 4038 | } |
| 4039 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4040 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4041 | // For any Objective-C class definitions we have already loaded, make sure |
| 4042 | // that we load any additional categories. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4043 | if (ContextObj) { |
| 4044 | for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) { |
| 4045 | loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(), |
| 4046 | ObjCClassesLoaded[I], |
| 4047 | PreviousGeneration); |
| 4048 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4049 | } |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 4050 | |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 4051 | if (PP.getHeaderSearchInfo() |
| 4052 | .getHeaderSearchOpts() |
| 4053 | .ModulesValidateOncePerBuildSession) { |
| 4054 | // Now we are certain that the module and all modules it depends on are |
| 4055 | // up to date. Create or update timestamp files for modules that are |
| 4056 | // located in the module cache (not for PCH files that could be anywhere |
| 4057 | // in the filesystem). |
| 4058 | for (unsigned I = 0, N = Loaded.size(); I != N; ++I) { |
| 4059 | ImportedModule &M = Loaded[I]; |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 4060 | if (M.Mod->Kind == MK_ImplicitModule) { |
Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 4061 | updateModuleTimestamp(*M.Mod); |
| 4062 | } |
| 4063 | } |
| 4064 | } |
| 4065 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4066 | return Success; |
| 4067 | } |
| 4068 | |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4069 | static ASTFileSignature readASTFileSignature(StringRef PCH); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4070 | |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4071 | /// \brief Whether \p Stream starts with the AST/PCH file magic number 'CPCH'. |
| 4072 | static bool startsWithASTFileMagic(BitstreamCursor &Stream) { |
Peter Collingbourne | 028eb5a | 2016-11-02 00:08:19 +0000 | [diff] [blame] | 4073 | return Stream.canSkipToPos(4) && |
| 4074 | Stream.Read(8) == 'C' && |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4075 | Stream.Read(8) == 'P' && |
| 4076 | Stream.Read(8) == 'C' && |
| 4077 | Stream.Read(8) == 'H'; |
| 4078 | } |
| 4079 | |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4080 | static unsigned moduleKindForDiagnostic(ModuleKind Kind) { |
| 4081 | switch (Kind) { |
| 4082 | case MK_PCH: |
| 4083 | return 0; // PCH |
| 4084 | case MK_ImplicitModule: |
| 4085 | case MK_ExplicitModule: |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 4086 | case MK_PrebuiltModule: |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4087 | return 1; // module |
| 4088 | case MK_MainFile: |
| 4089 | case MK_Preamble: |
| 4090 | return 2; // main source file |
| 4091 | } |
| 4092 | llvm_unreachable("unknown module kind"); |
| 4093 | } |
| 4094 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4095 | ASTReader::ASTReadResult |
| 4096 | ASTReader::ReadASTCore(StringRef FileName, |
| 4097 | ModuleKind Type, |
| 4098 | SourceLocation ImportLoc, |
| 4099 | ModuleFile *ImportedBy, |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4100 | SmallVectorImpl<ImportedModule> &Loaded, |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4101 | off_t ExpectedSize, time_t ExpectedModTime, |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4102 | ASTFileSignature ExpectedSignature, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4103 | unsigned ClientLoadCapabilities) { |
| 4104 | ModuleFile *M; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4105 | std::string ErrorStr; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4106 | ModuleManager::AddModuleResult AddResult |
| 4107 | = ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy, |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 4108 | getGeneration(), ExpectedSize, ExpectedModTime, |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4109 | ExpectedSignature, readASTFileSignature, |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4110 | M, ErrorStr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4111 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4112 | switch (AddResult) { |
| 4113 | case ModuleManager::AlreadyLoaded: |
| 4114 | return Success; |
| 4115 | |
| 4116 | case ModuleManager::NewlyLoaded: |
| 4117 | // Load module file below. |
| 4118 | break; |
| 4119 | |
| 4120 | case ModuleManager::Missing: |
Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 4121 | // The module file was missing; if the client can handle that, return |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4122 | // it. |
| 4123 | if (ClientLoadCapabilities & ARR_Missing) |
| 4124 | return Missing; |
| 4125 | |
| 4126 | // Otherwise, return an error. |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4127 | Diag(diag::err_module_file_not_found) << moduleKindForDiagnostic(Type) |
Adrian Prantl | b3b5a73 | 2016-08-29 20:46:59 +0000 | [diff] [blame] | 4128 | << FileName << !ErrorStr.empty() |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4129 | << ErrorStr; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4130 | return Failure; |
| 4131 | |
| 4132 | case ModuleManager::OutOfDate: |
| 4133 | // We couldn't load the module file because it is out-of-date. If the |
| 4134 | // client can handle out-of-date, return it. |
| 4135 | if (ClientLoadCapabilities & ARR_OutOfDate) |
| 4136 | return OutOfDate; |
| 4137 | |
| 4138 | // Otherwise, return an error. |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4139 | Diag(diag::err_module_file_out_of_date) << moduleKindForDiagnostic(Type) |
Adrian Prantl | 9a06a88 | 2016-08-29 20:46:56 +0000 | [diff] [blame] | 4140 | << FileName << !ErrorStr.empty() |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4141 | << ErrorStr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4142 | return Failure; |
| 4143 | } |
| 4144 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4145 | assert(M && "Missing module file"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4146 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4147 | ModuleFile &F = *M; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4148 | BitstreamCursor &Stream = F.Stream; |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4149 | Stream = BitstreamCursor(PCHContainerRdr.ExtractPCH(*F.Buffer)); |
Adrian Prantl | cbc368c | 2015-02-25 02:44:04 +0000 | [diff] [blame] | 4150 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4151 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4152 | // Sniff for the signature. |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4153 | if (!startsWithASTFileMagic(Stream)) { |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4154 | Diag(diag::err_module_file_invalid) << moduleKindForDiagnostic(Type) |
| 4155 | << FileName; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4156 | return Failure; |
| 4157 | } |
| 4158 | |
| 4159 | // This is used for compatibility with older PCH formats. |
| 4160 | bool HaveReadControlBlock = false; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4161 | while (true) { |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4162 | llvm::BitstreamEntry Entry = Stream.advance(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4163 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4164 | switch (Entry.Kind) { |
| 4165 | case llvm::BitstreamEntry::Error: |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4166 | case llvm::BitstreamEntry::Record: |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4167 | case llvm::BitstreamEntry::EndBlock: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4168 | Error("invalid record at top-level of AST file"); |
| 4169 | return Failure; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4170 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4171 | case llvm::BitstreamEntry::SubBlock: |
| 4172 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4173 | } |
| 4174 | |
Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4175 | switch (Entry.ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4176 | case CONTROL_BLOCK_ID: |
| 4177 | HaveReadControlBlock = true; |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4178 | switch (ReadControlBlock(F, Loaded, ImportedBy, ClientLoadCapabilities)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4179 | case Success: |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4180 | // Check that we didn't try to load a non-module AST file as a module. |
| 4181 | // |
| 4182 | // FIXME: Should we also perform the converse check? Loading a module as |
| 4183 | // a PCH file sort of works, but it's a bit wonky. |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 4184 | if ((Type == MK_ImplicitModule || Type == MK_ExplicitModule || |
| 4185 | Type == MK_PrebuiltModule) && |
Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4186 | F.ModuleName.empty()) { |
| 4187 | auto Result = (Type == MK_ImplicitModule) ? OutOfDate : Failure; |
| 4188 | if (Result != OutOfDate || |
| 4189 | (ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 4190 | Diag(diag::err_module_file_not_module) << FileName; |
| 4191 | return Result; |
| 4192 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4193 | break; |
| 4194 | |
| 4195 | case Failure: return Failure; |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4196 | case Missing: return Missing; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4197 | case OutOfDate: return OutOfDate; |
| 4198 | case VersionMismatch: return VersionMismatch; |
| 4199 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 4200 | case HadErrors: return HadErrors; |
| 4201 | } |
| 4202 | break; |
Richard Smith | f8c3255 | 2015-09-02 17:45:54 +0000 | [diff] [blame] | 4203 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4204 | case AST_BLOCK_ID: |
| 4205 | if (!HaveReadControlBlock) { |
| 4206 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 4207 | Diag(diag::err_pch_version_too_old); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4208 | return VersionMismatch; |
| 4209 | } |
| 4210 | |
| 4211 | // Record that we've loaded this module. |
| 4212 | Loaded.push_back(ImportedModule(M, ImportedBy, ImportLoc)); |
| 4213 | return Success; |
| 4214 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4215 | case UNHASHED_CONTROL_BLOCK_ID: |
| 4216 | // This block is handled using look-ahead during ReadControlBlock. We |
| 4217 | // shouldn't get here! |
| 4218 | Error("malformed block record in AST file"); |
| 4219 | return Failure; |
| 4220 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4221 | default: |
| 4222 | if (Stream.SkipBlock()) { |
| 4223 | Error("malformed block record in AST file"); |
| 4224 | return Failure; |
| 4225 | } |
| 4226 | break; |
| 4227 | } |
| 4228 | } |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4229 | |
| 4230 | return Success; |
| 4231 | } |
| 4232 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4233 | ASTReader::ASTReadResult |
| 4234 | ASTReader::readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy, |
| 4235 | unsigned ClientLoadCapabilities) { |
| 4236 | const HeaderSearchOptions &HSOpts = |
| 4237 | PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 4238 | bool AllowCompatibleConfigurationMismatch = |
| 4239 | F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule; |
| 4240 | |
| 4241 | ASTReadResult Result = readUnhashedControlBlockImpl( |
| 4242 | &F, F.Data, ClientLoadCapabilities, AllowCompatibleConfigurationMismatch, |
| 4243 | Listener.get(), |
| 4244 | WasImportedBy ? false : HSOpts.ModulesValidateDiagnosticOptions); |
| 4245 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4246 | // If F was directly imported by another module, it's implicitly validated by |
| 4247 | // the importing module. |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4248 | if (DisableValidation || WasImportedBy || |
| 4249 | (AllowConfigurationMismatch && Result == ConfigurationMismatch)) |
| 4250 | return Success; |
| 4251 | |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4252 | if (Result == Failure) { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4253 | Error("malformed block record in AST file"); |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4254 | return Failure; |
| 4255 | } |
| 4256 | |
| 4257 | if (Result == OutOfDate && F.Kind == MK_ImplicitModule) { |
| 4258 | // If this module has already been finalized in the PCMCache, we're stuck |
| 4259 | // with it; we can only load a single version of each module. |
| 4260 | // |
| 4261 | // This can happen when a module is imported in two contexts: in one, as a |
| 4262 | // user module; in another, as a system module (due to an import from |
| 4263 | // another module marked with the [system] flag). It usually indicates a |
| 4264 | // bug in the module map: this module should also be marked with [system]. |
| 4265 | // |
| 4266 | // If -Wno-system-headers (the default), and the first import is as a |
| 4267 | // system module, then validation will fail during the as-user import, |
| 4268 | // since -Werror flags won't have been validated. However, it's reasonable |
| 4269 | // to treat this consistently as a system module. |
| 4270 | // |
| 4271 | // If -Wsystem-headers, the PCM on disk was built with |
| 4272 | // -Wno-system-headers, and the first import is as a user module, then |
| 4273 | // validation will fail during the as-system import since the PCM on disk |
| 4274 | // doesn't guarantee that -Werror was respected. However, the -Werror |
| 4275 | // flags were checked during the initial as-user import. |
| 4276 | if (PCMCache.isBufferFinal(F.FileName)) { |
| 4277 | Diag(diag::warn_module_system_bit_conflict) << F.FileName; |
| 4278 | return Success; |
| 4279 | } |
| 4280 | } |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4281 | |
| 4282 | return Result; |
| 4283 | } |
| 4284 | |
| 4285 | ASTReader::ASTReadResult ASTReader::readUnhashedControlBlockImpl( |
| 4286 | ModuleFile *F, llvm::StringRef StreamData, unsigned ClientLoadCapabilities, |
| 4287 | bool AllowCompatibleConfigurationMismatch, ASTReaderListener *Listener, |
| 4288 | bool ValidateDiagnosticOptions) { |
| 4289 | // Initialize a stream. |
| 4290 | BitstreamCursor Stream(StreamData); |
| 4291 | |
| 4292 | // Sniff for the signature. |
| 4293 | if (!startsWithASTFileMagic(Stream)) |
| 4294 | return Failure; |
| 4295 | |
| 4296 | // Scan for the UNHASHED_CONTROL_BLOCK_ID block. |
| 4297 | if (SkipCursorToBlock(Stream, UNHASHED_CONTROL_BLOCK_ID)) |
| 4298 | return Failure; |
| 4299 | |
| 4300 | // Read all of the records in the options block. |
| 4301 | RecordData Record; |
| 4302 | ASTReadResult Result = Success; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 4303 | while (true) { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4304 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4305 | |
| 4306 | switch (Entry.Kind) { |
| 4307 | case llvm::BitstreamEntry::Error: |
| 4308 | case llvm::BitstreamEntry::SubBlock: |
| 4309 | return Failure; |
| 4310 | |
| 4311 | case llvm::BitstreamEntry::EndBlock: |
| 4312 | return Result; |
| 4313 | |
| 4314 | case llvm::BitstreamEntry::Record: |
| 4315 | // The interesting case. |
| 4316 | break; |
| 4317 | } |
| 4318 | |
| 4319 | // Read and process a record. |
| 4320 | Record.clear(); |
| 4321 | switch ( |
| 4322 | (UnhashedControlBlockRecordTypes)Stream.readRecord(Entry.ID, Record)) { |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 4323 | case SIGNATURE: |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4324 | if (F) |
| 4325 | std::copy(Record.begin(), Record.end(), F->Signature.data()); |
| 4326 | break; |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4327 | case DIAGNOSTIC_OPTIONS: { |
| 4328 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
| 4329 | if (Listener && ValidateDiagnosticOptions && |
| 4330 | !AllowCompatibleConfigurationMismatch && |
| 4331 | ParseDiagnosticOptions(Record, Complain, *Listener)) |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4332 | Result = OutOfDate; // Don't return early. Read the signature. |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4333 | break; |
| 4334 | } |
| 4335 | case DIAG_PRAGMA_MAPPINGS: |
| 4336 | if (!F) |
| 4337 | break; |
| 4338 | if (F->PragmaDiagMappings.empty()) |
| 4339 | F->PragmaDiagMappings.swap(Record); |
| 4340 | else |
| 4341 | F->PragmaDiagMappings.insert(F->PragmaDiagMappings.end(), |
| 4342 | Record.begin(), Record.end()); |
| 4343 | break; |
| 4344 | } |
| 4345 | } |
| 4346 | } |
| 4347 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4348 | /// Parse a record and blob containing module file extension metadata. |
| 4349 | static bool parseModuleFileExtensionMetadata( |
| 4350 | const SmallVectorImpl<uint64_t> &Record, |
| 4351 | StringRef Blob, |
| 4352 | ModuleFileExtensionMetadata &Metadata) { |
| 4353 | if (Record.size() < 4) return true; |
| 4354 | |
| 4355 | Metadata.MajorVersion = Record[0]; |
| 4356 | Metadata.MinorVersion = Record[1]; |
| 4357 | |
| 4358 | unsigned BlockNameLen = Record[2]; |
| 4359 | unsigned UserInfoLen = Record[3]; |
| 4360 | |
| 4361 | if (BlockNameLen + UserInfoLen > Blob.size()) return true; |
| 4362 | |
| 4363 | Metadata.BlockName = std::string(Blob.data(), Blob.data() + BlockNameLen); |
| 4364 | Metadata.UserInfo = std::string(Blob.data() + BlockNameLen, |
| 4365 | Blob.data() + BlockNameLen + UserInfoLen); |
| 4366 | return false; |
| 4367 | } |
| 4368 | |
| 4369 | ASTReader::ASTReadResult ASTReader::ReadExtensionBlock(ModuleFile &F) { |
| 4370 | BitstreamCursor &Stream = F.Stream; |
| 4371 | |
| 4372 | RecordData Record; |
| 4373 | while (true) { |
| 4374 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4375 | switch (Entry.Kind) { |
| 4376 | case llvm::BitstreamEntry::SubBlock: |
| 4377 | if (Stream.SkipBlock()) |
| 4378 | return Failure; |
| 4379 | |
| 4380 | continue; |
| 4381 | |
| 4382 | case llvm::BitstreamEntry::EndBlock: |
| 4383 | return Success; |
| 4384 | |
| 4385 | case llvm::BitstreamEntry::Error: |
| 4386 | return HadErrors; |
| 4387 | |
| 4388 | case llvm::BitstreamEntry::Record: |
| 4389 | break; |
| 4390 | } |
| 4391 | |
| 4392 | Record.clear(); |
| 4393 | StringRef Blob; |
| 4394 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
| 4395 | switch (RecCode) { |
| 4396 | case EXTENSION_METADATA: { |
| 4397 | ModuleFileExtensionMetadata Metadata; |
| 4398 | if (parseModuleFileExtensionMetadata(Record, Blob, Metadata)) |
| 4399 | return Failure; |
| 4400 | |
| 4401 | // Find a module file extension with this block name. |
| 4402 | auto Known = ModuleFileExtensions.find(Metadata.BlockName); |
| 4403 | if (Known == ModuleFileExtensions.end()) break; |
| 4404 | |
| 4405 | // Form a reader. |
| 4406 | if (auto Reader = Known->second->createExtensionReader(Metadata, *this, |
| 4407 | F, Stream)) { |
| 4408 | F.ExtensionReaders.push_back(std::move(Reader)); |
| 4409 | } |
| 4410 | |
| 4411 | break; |
| 4412 | } |
| 4413 | } |
| 4414 | } |
| 4415 | |
| 4416 | return Success; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4417 | } |
| 4418 | |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4419 | void ASTReader::InitializeContext() { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4420 | assert(ContextObj && "no context to initialize"); |
| 4421 | ASTContext &Context = *ContextObj; |
| 4422 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4423 | // If there's a listener, notify them that we "read" the translation unit. |
| 4424 | if (DeserializationListener) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4425 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4426 | Context.getTranslationUnitDecl()); |
| 4427 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4428 | // FIXME: Find a better way to deal with collisions between these |
| 4429 | // built-in types. Right now, we just ignore the problem. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4430 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4431 | // Load the special types. |
| 4432 | if (SpecialTypes.size() >= NumSpecialTypeIDs) { |
| 4433 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 4434 | if (!Context.CFConstantStringTypeDecl) |
| 4435 | Context.setCFConstantStringType(GetType(String)); |
| 4436 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4437 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4438 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 4439 | QualType FileType = GetType(File); |
| 4440 | if (FileType.isNull()) { |
| 4441 | Error("FILE type is NULL"); |
| 4442 | return; |
| 4443 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4444 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4445 | if (!Context.FILEDecl) { |
| 4446 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 4447 | Context.setFILEDecl(Typedef->getDecl()); |
| 4448 | else { |
| 4449 | const TagType *Tag = FileType->getAs<TagType>(); |
| 4450 | if (!Tag) { |
| 4451 | Error("Invalid FILE type in AST file"); |
| 4452 | return; |
| 4453 | } |
| 4454 | Context.setFILEDecl(Tag->getDecl()); |
| 4455 | } |
| 4456 | } |
| 4457 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4458 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4459 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) { |
| 4460 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 4461 | if (Jmp_bufType.isNull()) { |
| 4462 | Error("jmp_buf type is NULL"); |
| 4463 | return; |
| 4464 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4465 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4466 | if (!Context.jmp_bufDecl) { |
| 4467 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 4468 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 4469 | else { |
| 4470 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 4471 | if (!Tag) { |
| 4472 | Error("Invalid jmp_buf type in AST file"); |
| 4473 | return; |
| 4474 | } |
| 4475 | Context.setjmp_bufDecl(Tag->getDecl()); |
| 4476 | } |
| 4477 | } |
| 4478 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4479 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4480 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) { |
| 4481 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 4482 | if (Sigjmp_bufType.isNull()) { |
| 4483 | Error("sigjmp_buf type is NULL"); |
| 4484 | return; |
| 4485 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4486 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4487 | if (!Context.sigjmp_bufDecl) { |
| 4488 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 4489 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 4490 | else { |
| 4491 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 4492 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 4493 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 4494 | } |
| 4495 | } |
| 4496 | } |
| 4497 | |
| 4498 | if (unsigned ObjCIdRedef |
| 4499 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 4500 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 4501 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 4502 | } |
| 4503 | |
| 4504 | if (unsigned ObjCClassRedef |
| 4505 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 4506 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 4507 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 4508 | } |
| 4509 | |
| 4510 | if (unsigned ObjCSelRedef |
| 4511 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 4512 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 4513 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 4514 | } |
| 4515 | |
| 4516 | if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) { |
| 4517 | QualType Ucontext_tType = GetType(Ucontext_t); |
| 4518 | if (Ucontext_tType.isNull()) { |
| 4519 | Error("ucontext_t type is NULL"); |
| 4520 | return; |
| 4521 | } |
| 4522 | |
| 4523 | if (!Context.ucontext_tDecl) { |
| 4524 | if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>()) |
| 4525 | Context.setucontext_tDecl(Typedef->getDecl()); |
| 4526 | else { |
| 4527 | const TagType *Tag = Ucontext_tType->getAs<TagType>(); |
| 4528 | assert(Tag && "Invalid ucontext_t type in AST file"); |
| 4529 | Context.setucontext_tDecl(Tag->getDecl()); |
| 4530 | } |
| 4531 | } |
| 4532 | } |
| 4533 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4534 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4535 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
| 4536 | |
| 4537 | // If there were any CUDA special declarations, deserialize them. |
| 4538 | if (!CUDASpecialDeclRefs.empty()) { |
| 4539 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 4540 | Context.setcudaConfigureCallDecl( |
| 4541 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 4542 | } |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4543 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4544 | // 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] | 4545 | // FIXME: This does not make macro-only imports visible again. |
Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4546 | for (auto &Import : ImportedModules) { |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4547 | if (Module *Imported = getSubmodule(Import.ID)) { |
Argyrios Kyrtzidis | 125df05 | 2013-02-01 16:36:12 +0000 | [diff] [blame] | 4548 | makeModuleVisible(Imported, Module::AllVisible, |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4549 | /*ImportLoc=*/Import.ImportLoc); |
Ben Langmuir | 6d25fdc | 2016-02-11 17:04:42 +0000 | [diff] [blame] | 4550 | if (Import.ImportLoc.isValid()) |
| 4551 | PP.makeModuleVisible(Imported, Import.ImportLoc); |
| 4552 | // FIXME: should we tell Sema to make the module visible too? |
Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4553 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4554 | } |
| 4555 | ImportedModules.clear(); |
| 4556 | } |
| 4557 | |
| 4558 | void ASTReader::finalizeForWriting() { |
Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 4559 | // Nothing to do for now. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4560 | } |
| 4561 | |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4562 | /// \brief Reads and return the signature record from \p PCH's control block, or |
| 4563 | /// else returns 0. |
| 4564 | static ASTFileSignature readASTFileSignature(StringRef PCH) { |
| 4565 | BitstreamCursor Stream(PCH); |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4566 | if (!startsWithASTFileMagic(Stream)) |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4567 | return ASTFileSignature(); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4568 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4569 | // Scan for the UNHASHED_CONTROL_BLOCK_ID block. |
| 4570 | if (SkipCursorToBlock(Stream, UNHASHED_CONTROL_BLOCK_ID)) |
| 4571 | return ASTFileSignature(); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4572 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4573 | // Scan for SIGNATURE inside the diagnostic options block. |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4574 | ASTReader::RecordData Record; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4575 | while (true) { |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4576 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
Simon Pilgrim | 0b33f11 | 2016-11-16 16:11:08 +0000 | [diff] [blame] | 4577 | if (Entry.Kind != llvm::BitstreamEntry::Record) |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4578 | return ASTFileSignature(); |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4579 | |
| 4580 | Record.clear(); |
| 4581 | StringRef Blob; |
| 4582 | if (SIGNATURE == Stream.readRecord(Entry.ID, Record, &Blob)) |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4583 | return {{{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2], |
| 4584 | (uint32_t)Record[3], (uint32_t)Record[4]}}}; |
Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4585 | } |
| 4586 | } |
| 4587 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4588 | /// \brief Retrieve the name of the original source file name |
| 4589 | /// directly from the AST file, without actually loading the AST |
| 4590 | /// file. |
Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame] | 4591 | std::string ASTReader::getOriginalSourceFile( |
| 4592 | const std::string &ASTFileName, FileManager &FileMgr, |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 4593 | const PCHContainerReader &PCHContainerRdr, DiagnosticsEngine &Diags) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4594 | // Open the AST file. |
Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 4595 | auto Buffer = FileMgr.getBufferForFile(ASTFileName); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4596 | if (!Buffer) { |
Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 4597 | Diags.Report(diag::err_fe_unable_to_read_pch_file) |
| 4598 | << ASTFileName << Buffer.getError().message(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4599 | return std::string(); |
| 4600 | } |
| 4601 | |
| 4602 | // Initialize the stream |
Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4603 | BitstreamCursor Stream(PCHContainerRdr.ExtractPCH(**Buffer)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4604 | |
| 4605 | // Sniff for the signature. |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4606 | if (!startsWithASTFileMagic(Stream)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4607 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
| 4608 | return std::string(); |
| 4609 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4610 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4611 | // Scan for the CONTROL_BLOCK_ID block. |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4612 | if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4613 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
| 4614 | return std::string(); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4615 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4616 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4617 | // Scan for ORIGINAL_FILE inside the control block. |
| 4618 | RecordData Record; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4619 | while (true) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4620 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4621 | if (Entry.Kind == llvm::BitstreamEntry::EndBlock) |
| 4622 | return std::string(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4623 | |
Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4624 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| 4625 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
| 4626 | return std::string(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4627 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4628 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4629 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4630 | StringRef Blob; |
| 4631 | if (Stream.readRecord(Entry.ID, Record, &Blob) == ORIGINAL_FILE) |
| 4632 | return Blob.str(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4633 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4634 | } |
| 4635 | |
| 4636 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4637 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4638 | class SimplePCHValidator : public ASTReaderListener { |
| 4639 | const LangOptions &ExistingLangOpts; |
| 4640 | const TargetOptions &ExistingTargetOpts; |
| 4641 | const PreprocessorOptions &ExistingPPOpts; |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4642 | std::string ExistingModuleCachePath; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4643 | FileManager &FileMgr; |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4644 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4645 | public: |
| 4646 | SimplePCHValidator(const LangOptions &ExistingLangOpts, |
| 4647 | const TargetOptions &ExistingTargetOpts, |
| 4648 | const PreprocessorOptions &ExistingPPOpts, |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4649 | StringRef ExistingModuleCachePath, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4650 | FileManager &FileMgr) |
| 4651 | : ExistingLangOpts(ExistingLangOpts), |
| 4652 | ExistingTargetOpts(ExistingTargetOpts), |
| 4653 | ExistingPPOpts(ExistingPPOpts), |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4654 | ExistingModuleCachePath(ExistingModuleCachePath), |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 4655 | FileMgr(FileMgr) {} |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4656 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 4657 | bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, |
| 4658 | bool AllowCompatibleDifferences) override { |
| 4659 | return checkLanguageOptions(ExistingLangOpts, LangOpts, nullptr, |
| 4660 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4661 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4662 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 4663 | bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, |
| 4664 | bool AllowCompatibleDifferences) override { |
| 4665 | return checkTargetOptions(ExistingTargetOpts, TargetOpts, nullptr, |
| 4666 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4667 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4668 | |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4669 | bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 4670 | StringRef SpecificModuleCachePath, |
| 4671 | bool Complain) override { |
| 4672 | return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 4673 | ExistingModuleCachePath, |
| 4674 | nullptr, ExistingLangOpts); |
| 4675 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4676 | |
Craig Topper | 3e89dfe | 2014-03-13 02:13:41 +0000 | [diff] [blame] | 4677 | bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 4678 | bool Complain, |
| 4679 | std::string &SuggestedPredefines) override { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4680 | return checkPreprocessorOptions(ExistingPPOpts, PPOpts, nullptr, FileMgr, |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 4681 | SuggestedPredefines, ExistingLangOpts); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4682 | } |
| 4683 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4684 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 4685 | } // namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4686 | |
Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame] | 4687 | bool ASTReader::readASTFileControlBlock( |
| 4688 | StringRef Filename, FileManager &FileMgr, |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 4689 | const PCHContainerReader &PCHContainerRdr, |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4690 | bool FindModuleFileExtensions, |
Manman Ren | 47a4445 | 2016-07-26 17:12:17 +0000 | [diff] [blame] | 4691 | ASTReaderListener &Listener, bool ValidateDiagnosticOptions) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4692 | // Open the AST file. |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 4693 | // FIXME: This allows use of the VFS; we do not allow use of the |
| 4694 | // VFS when actually loading a module. |
Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 4695 | auto Buffer = FileMgr.getBufferForFile(Filename); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4696 | if (!Buffer) { |
| 4697 | return true; |
| 4698 | } |
| 4699 | |
| 4700 | // Initialize the stream |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4701 | StringRef Bytes = PCHContainerRdr.ExtractPCH(**Buffer); |
| 4702 | BitstreamCursor Stream(Bytes); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4703 | |
| 4704 | // Sniff for the signature. |
Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4705 | if (!startsWithASTFileMagic(Stream)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4706 | return true; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4707 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4708 | // Scan for the CONTROL_BLOCK_ID block. |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4709 | if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4710 | return true; |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4711 | |
| 4712 | bool NeedsInputFiles = Listener.needsInputFileVisitation(); |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 4713 | bool NeedsSystemInputFiles = Listener.needsSystemInputFileVisitation(); |
Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4714 | bool NeedsImports = Listener.needsImportVisitation(); |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4715 | BitstreamCursor InputFilesCursor; |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4716 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4717 | RecordData Record; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4718 | std::string ModuleDir; |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4719 | bool DoneWithControlBlock = false; |
| 4720 | while (!DoneWithControlBlock) { |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4721 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4722 | |
| 4723 | switch (Entry.Kind) { |
| 4724 | case llvm::BitstreamEntry::SubBlock: { |
| 4725 | switch (Entry.ID) { |
| 4726 | case OPTIONS_BLOCK_ID: { |
| 4727 | std::string IgnoredSuggestedPredefines; |
| 4728 | if (ReadOptionsBlock(Stream, ARR_ConfigurationMismatch | ARR_OutOfDate, |
| 4729 | /*AllowCompatibleConfigurationMismatch*/ false, |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4730 | Listener, IgnoredSuggestedPredefines) != Success) |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4731 | return true; |
| 4732 | break; |
| 4733 | } |
| 4734 | |
| 4735 | case INPUT_FILES_BLOCK_ID: |
| 4736 | InputFilesCursor = Stream; |
| 4737 | if (Stream.SkipBlock() || |
| 4738 | (NeedsInputFiles && |
| 4739 | ReadBlockAbbrevs(InputFilesCursor, INPUT_FILES_BLOCK_ID))) |
| 4740 | return true; |
| 4741 | break; |
| 4742 | |
| 4743 | default: |
| 4744 | if (Stream.SkipBlock()) |
| 4745 | return true; |
| 4746 | break; |
| 4747 | } |
| 4748 | |
| 4749 | continue; |
| 4750 | } |
| 4751 | |
| 4752 | case llvm::BitstreamEntry::EndBlock: |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4753 | DoneWithControlBlock = true; |
| 4754 | break; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4755 | |
| 4756 | case llvm::BitstreamEntry::Error: |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4757 | return true; |
Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4758 | |
| 4759 | case llvm::BitstreamEntry::Record: |
| 4760 | break; |
| 4761 | } |
| 4762 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4763 | if (DoneWithControlBlock) break; |
| 4764 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4765 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4766 | StringRef Blob; |
| 4767 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4768 | switch ((ControlRecordTypes)RecCode) { |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 4769 | case METADATA: |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4770 | if (Record[0] != VERSION_MAJOR) |
| 4771 | return true; |
Douglas Gregor | bf7fc9c | 2013-03-27 16:47:18 +0000 | [diff] [blame] | 4772 | if (Listener.ReadFullVersionInformation(Blob)) |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4773 | return true; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4774 | break; |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 4775 | case MODULE_NAME: |
| 4776 | Listener.ReadModuleName(Blob); |
| 4777 | break; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4778 | case MODULE_DIRECTORY: |
| 4779 | ModuleDir = Blob; |
| 4780 | break; |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 4781 | case MODULE_MAP_FILE: { |
| 4782 | unsigned Idx = 0; |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4783 | auto Path = ReadString(Record, Idx); |
| 4784 | ResolveImportedPath(Path, ModuleDir); |
| 4785 | Listener.ReadModuleMapFile(Path); |
Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 4786 | break; |
Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 4787 | } |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4788 | case INPUT_FILE_OFFSETS: { |
| 4789 | if (!NeedsInputFiles) |
| 4790 | break; |
| 4791 | |
| 4792 | unsigned NumInputFiles = Record[0]; |
| 4793 | unsigned NumUserFiles = Record[1]; |
Richard Smith | ec21650 | 2015-02-13 19:48:37 +0000 | [diff] [blame] | 4794 | const uint64_t *InputFileOffs = (const uint64_t *)Blob.data(); |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4795 | for (unsigned I = 0; I != NumInputFiles; ++I) { |
| 4796 | // Go find this input file. |
| 4797 | bool isSystemFile = I >= NumUserFiles; |
Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 4798 | |
| 4799 | if (isSystemFile && !NeedsSystemInputFiles) |
| 4800 | break; // the rest are system input files |
| 4801 | |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4802 | BitstreamCursor &Cursor = InputFilesCursor; |
| 4803 | SavedStreamPosition SavedPosition(Cursor); |
| 4804 | Cursor.JumpToBit(InputFileOffs[I]); |
| 4805 | |
| 4806 | unsigned Code = Cursor.ReadCode(); |
| 4807 | RecordData Record; |
| 4808 | StringRef Blob; |
| 4809 | bool shouldContinue = false; |
| 4810 | switch ((InputFileRecordTypes)Cursor.readRecord(Code, Record, &Blob)) { |
| 4811 | case INPUT_FILE: |
Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 4812 | bool Overridden = static_cast<bool>(Record[3]); |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4813 | std::string Filename = Blob; |
| 4814 | ResolveImportedPath(Filename, ModuleDir); |
Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 4815 | shouldContinue = Listener.visitInputFile( |
| 4816 | Filename, isSystemFile, Overridden, /*IsExplicitModule*/false); |
Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4817 | break; |
| 4818 | } |
| 4819 | if (!shouldContinue) |
| 4820 | break; |
| 4821 | } |
| 4822 | break; |
| 4823 | } |
| 4824 | |
Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4825 | case IMPORTS: { |
| 4826 | if (!NeedsImports) |
| 4827 | break; |
| 4828 | |
| 4829 | unsigned Idx = 0, N = Record.size(); |
| 4830 | while (Idx < N) { |
| 4831 | // Read information about the AST file. |
Richard Smith | 79c98cc | 2014-10-27 23:25:15 +0000 | [diff] [blame] | 4832 | Idx += 5; // ImportLoc, Size, ModTime, Signature |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 4833 | SkipString(Record, Idx); // Module name; FIXME: pass to listener? |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4834 | std::string Filename = ReadString(Record, Idx); |
| 4835 | ResolveImportedPath(Filename, ModuleDir); |
| 4836 | Listener.visitImport(Filename); |
Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4837 | } |
| 4838 | break; |
| 4839 | } |
| 4840 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4841 | default: |
| 4842 | // No other validation to perform. |
| 4843 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4844 | } |
| 4845 | } |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4846 | |
| 4847 | // Look for module file extension blocks, if requested. |
| 4848 | if (FindModuleFileExtensions) { |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4849 | BitstreamCursor SavedStream = Stream; |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4850 | while (!SkipCursorToBlock(Stream, EXTENSION_BLOCK_ID)) { |
| 4851 | bool DoneWithExtensionBlock = false; |
| 4852 | while (!DoneWithExtensionBlock) { |
| 4853 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4854 | |
| 4855 | switch (Entry.Kind) { |
| 4856 | case llvm::BitstreamEntry::SubBlock: |
| 4857 | if (Stream.SkipBlock()) |
| 4858 | return true; |
| 4859 | |
| 4860 | continue; |
| 4861 | |
| 4862 | case llvm::BitstreamEntry::EndBlock: |
| 4863 | DoneWithExtensionBlock = true; |
| 4864 | continue; |
| 4865 | |
| 4866 | case llvm::BitstreamEntry::Error: |
| 4867 | return true; |
| 4868 | |
| 4869 | case llvm::BitstreamEntry::Record: |
| 4870 | break; |
| 4871 | } |
| 4872 | |
| 4873 | Record.clear(); |
| 4874 | StringRef Blob; |
| 4875 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
| 4876 | switch (RecCode) { |
| 4877 | case EXTENSION_METADATA: { |
| 4878 | ModuleFileExtensionMetadata Metadata; |
| 4879 | if (parseModuleFileExtensionMetadata(Record, Blob, Metadata)) |
| 4880 | return true; |
| 4881 | |
| 4882 | Listener.readModuleFileExtension(Metadata); |
| 4883 | break; |
| 4884 | } |
| 4885 | } |
| 4886 | } |
| 4887 | } |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4888 | Stream = SavedStream; |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4889 | } |
| 4890 | |
Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4891 | // Scan for the UNHASHED_CONTROL_BLOCK_ID block. |
| 4892 | if (readUnhashedControlBlockImpl( |
| 4893 | nullptr, Bytes, ARR_ConfigurationMismatch | ARR_OutOfDate, |
| 4894 | /*AllowCompatibleConfigurationMismatch*/ false, &Listener, |
| 4895 | ValidateDiagnosticOptions) != Success) |
| 4896 | return true; |
| 4897 | |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4898 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4899 | } |
| 4900 | |
Benjamin Kramer | f6021ec | 2017-03-21 21:35:04 +0000 | [diff] [blame] | 4901 | bool ASTReader::isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, |
| 4902 | const PCHContainerReader &PCHContainerRdr, |
| 4903 | const LangOptions &LangOpts, |
| 4904 | const TargetOptions &TargetOpts, |
| 4905 | const PreprocessorOptions &PPOpts, |
| 4906 | StringRef ExistingModuleCachePath) { |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4907 | SimplePCHValidator validator(LangOpts, TargetOpts, PPOpts, |
| 4908 | ExistingModuleCachePath, FileMgr); |
Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 4909 | return !readASTFileControlBlock(Filename, FileMgr, PCHContainerRdr, |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4910 | /*FindModuleFileExtensions=*/false, |
Manman Ren | 47a4445 | 2016-07-26 17:12:17 +0000 | [diff] [blame] | 4911 | validator, |
| 4912 | /*ValidateDiagnosticOptions=*/true); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4913 | } |
| 4914 | |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4915 | ASTReader::ASTReadResult |
| 4916 | ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4917 | // Enter the submodule block. |
| 4918 | if (F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) { |
| 4919 | Error("malformed submodule block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4920 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4921 | } |
| 4922 | |
| 4923 | ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap(); |
| 4924 | bool First = true; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4925 | Module *CurrentModule = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4926 | RecordData Record; |
| 4927 | while (true) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4928 | llvm::BitstreamEntry Entry = F.Stream.advanceSkippingSubblocks(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4929 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4930 | switch (Entry.Kind) { |
| 4931 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 4932 | case llvm::BitstreamEntry::Error: |
| 4933 | Error("malformed block record in AST file"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4934 | return Failure; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4935 | case llvm::BitstreamEntry::EndBlock: |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4936 | return Success; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4937 | case llvm::BitstreamEntry::Record: |
| 4938 | // The interesting case. |
| 4939 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4940 | } |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4941 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4942 | // Read a record. |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4943 | StringRef Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4944 | Record.clear(); |
Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4945 | auto Kind = F.Stream.readRecord(Entry.ID, Record, &Blob); |
| 4946 | |
| 4947 | if ((Kind == SUBMODULE_METADATA) != First) { |
| 4948 | Error("submodule metadata record should be at beginning of block"); |
| 4949 | return Failure; |
| 4950 | } |
| 4951 | First = false; |
| 4952 | |
| 4953 | // Submodule information is only valid if we have a current module. |
| 4954 | // FIXME: Should we error on these cases? |
| 4955 | if (!CurrentModule && Kind != SUBMODULE_METADATA && |
| 4956 | Kind != SUBMODULE_DEFINITION) |
| 4957 | continue; |
| 4958 | |
| 4959 | switch (Kind) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4960 | default: // Default behavior: ignore. |
| 4961 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4962 | |
Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4963 | case SUBMODULE_DEFINITION: { |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4964 | if (Record.size() < 8) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4965 | Error("malformed module definition"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4966 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4967 | } |
Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4968 | |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4969 | StringRef Name = Blob; |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 4970 | unsigned Idx = 0; |
| 4971 | SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[Idx++]); |
| 4972 | SubmoduleID Parent = getGlobalSubmoduleID(F, Record[Idx++]); |
Richard Smith | dd8b533 | 2017-09-04 05:37:53 +0000 | [diff] [blame] | 4973 | Module::ModuleKind Kind = (Module::ModuleKind)Record[Idx++]; |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 4974 | bool IsFramework = Record[Idx++]; |
| 4975 | bool IsExplicit = Record[Idx++]; |
| 4976 | bool IsSystem = Record[Idx++]; |
| 4977 | bool IsExternC = Record[Idx++]; |
| 4978 | bool InferSubmodules = Record[Idx++]; |
| 4979 | bool InferExplicitSubmodules = Record[Idx++]; |
| 4980 | bool InferExportWildcard = Record[Idx++]; |
| 4981 | bool ConfigMacrosExhaustive = Record[Idx++]; |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 4982 | |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4983 | Module *ParentModule = nullptr; |
Ben Langmuir | 9d6448b | 2014-08-09 00:57:23 +0000 | [diff] [blame] | 4984 | if (Parent) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4985 | ParentModule = getSubmodule(Parent); |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4986 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4987 | // Retrieve this (sub)module from the module map, creating it if |
| 4988 | // necessary. |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 4989 | CurrentModule = |
| 4990 | ModMap.findOrCreateModule(Name, ParentModule, IsFramework, IsExplicit) |
| 4991 | .first; |
Ben Langmuir | 9d6448b | 2014-08-09 00:57:23 +0000 | [diff] [blame] | 4992 | |
| 4993 | // FIXME: set the definition loc for CurrentModule, or call |
| 4994 | // ModMap.setInferredModuleAllowedBy() |
| 4995 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4996 | SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS; |
| 4997 | if (GlobalIndex >= SubmodulesLoaded.size() || |
| 4998 | SubmodulesLoaded[GlobalIndex]) { |
| 4999 | Error("too many submodules"); |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 5000 | return Failure; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5001 | } |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 5002 | |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 5003 | if (!ParentModule) { |
| 5004 | if (const FileEntry *CurFile = CurrentModule->getASTFile()) { |
| 5005 | if (CurFile != F.File) { |
| 5006 | if (!Diags.isDiagnosticInFlight()) { |
| 5007 | Diag(diag::err_module_file_conflict) |
| 5008 | << CurrentModule->getTopLevelModuleName() |
| 5009 | << CurFile->getName() |
| 5010 | << F.File->getName(); |
| 5011 | } |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 5012 | return Failure; |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 5013 | } |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 5014 | } |
Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 5015 | |
| 5016 | CurrentModule->setASTFile(F.File); |
Richard Smith | ab75597 | 2017-06-05 18:10:11 +0000 | [diff] [blame] | 5017 | CurrentModule->PresumedModuleMapFile = F.ModuleMapPath; |
Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 5018 | } |
Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 5019 | |
Richard Smith | dd8b533 | 2017-09-04 05:37:53 +0000 | [diff] [blame] | 5020 | CurrentModule->Kind = Kind; |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 5021 | CurrentModule->Signature = F.Signature; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5022 | CurrentModule->IsFromModuleFile = true; |
| 5023 | CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem; |
Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 5024 | CurrentModule->IsExternC = IsExternC; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5025 | CurrentModule->InferSubmodules = InferSubmodules; |
| 5026 | CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules; |
| 5027 | CurrentModule->InferExportWildcard = InferExportWildcard; |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 5028 | CurrentModule->ConfigMacrosExhaustive = ConfigMacrosExhaustive; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5029 | if (DeserializationListener) |
| 5030 | DeserializationListener->ModuleRead(GlobalID, CurrentModule); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5031 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5032 | SubmodulesLoaded[GlobalIndex] = CurrentModule; |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5033 | |
Richard Smith | 8a3e39a | 2016-03-28 21:31:09 +0000 | [diff] [blame] | 5034 | // 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] | 5035 | CurrentModule->LinkLibraries.clear(); |
Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 5036 | CurrentModule->ConfigMacros.clear(); |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5037 | CurrentModule->UnresolvedConflicts.clear(); |
| 5038 | CurrentModule->Conflicts.clear(); |
Richard Smith | 8a3e39a | 2016-03-28 21:31:09 +0000 | [diff] [blame] | 5039 | |
| 5040 | // The module is available unless it's missing a requirement; relevant |
| 5041 | // requirements will be (re-)added by SUBMODULE_REQUIRES records. |
| 5042 | // Missing headers that were present when the module was built do not |
| 5043 | // make it unavailable -- if we got this far, this must be an explicitly |
| 5044 | // imported module file. |
| 5045 | CurrentModule->Requirements.clear(); |
| 5046 | CurrentModule->MissingHeaders.clear(); |
| 5047 | CurrentModule->IsMissingRequirement = |
| 5048 | ParentModule && ParentModule->IsMissingRequirement; |
| 5049 | CurrentModule->IsAvailable = !CurrentModule->IsMissingRequirement; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5050 | break; |
| 5051 | } |
Richard Smith | 8a3e39a | 2016-03-28 21:31:09 +0000 | [diff] [blame] | 5052 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5053 | case SUBMODULE_UMBRELLA_HEADER: { |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 5054 | std::string Filename = Blob; |
| 5055 | ResolveImportedPath(F, Filename); |
| 5056 | if (auto *Umbrella = PP.getFileManager().getFile(Filename)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5057 | if (!CurrentModule->getUmbrellaHeader()) |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 5058 | ModMap.setUmbrellaHeader(CurrentModule, Umbrella, Blob); |
| 5059 | else if (CurrentModule->getUmbrellaHeader().Entry != Umbrella) { |
Bruno Cardoso Lopes | 573b13f | 2017-03-22 00:11:21 +0000 | [diff] [blame] | 5060 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 5061 | Error("mismatched umbrella headers in submodule"); |
| 5062 | return OutOfDate; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5063 | } |
| 5064 | } |
| 5065 | break; |
| 5066 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5067 | |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 5068 | case SUBMODULE_HEADER: |
| 5069 | case SUBMODULE_EXCLUDED_HEADER: |
| 5070 | case SUBMODULE_PRIVATE_HEADER: |
| 5071 | // We lazily associate headers with their modules via the HeaderInfo table. |
Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 5072 | // FIXME: Re-evaluate this section; maybe only store InputFile IDs instead |
| 5073 | // of complete filenames or remove it entirely. |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 5074 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5075 | |
Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 5076 | case SUBMODULE_TEXTUAL_HEADER: |
| 5077 | case SUBMODULE_PRIVATE_TEXTUAL_HEADER: |
| 5078 | // FIXME: Textual headers are not marked in the HeaderInfo table. Load |
| 5079 | // them here. |
| 5080 | break; |
Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 5081 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5082 | case SUBMODULE_TOPHEADER: |
Argyrios Kyrtzidis | 3c5305c | 2013-03-13 21:13:43 +0000 | [diff] [blame] | 5083 | CurrentModule->addTopHeaderFilename(Blob); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5084 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5085 | |
| 5086 | case SUBMODULE_UMBRELLA_DIR: { |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 5087 | std::string Dirname = Blob; |
| 5088 | ResolveImportedPath(F, Dirname); |
| 5089 | if (auto *Umbrella = PP.getFileManager().getDirectory(Dirname)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5090 | if (!CurrentModule->getUmbrellaDir()) |
Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 5091 | ModMap.setUmbrellaDir(CurrentModule, Umbrella, Blob); |
| 5092 | else if (CurrentModule->getUmbrellaDir().Entry != Umbrella) { |
Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 5093 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 5094 | Error("mismatched umbrella directories in submodule"); |
| 5095 | return OutOfDate; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5096 | } |
| 5097 | } |
| 5098 | break; |
| 5099 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5100 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5101 | case SUBMODULE_METADATA: { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5102 | F.BaseSubmoduleID = getTotalNumSubmodules(); |
| 5103 | F.LocalNumSubmodules = Record[0]; |
| 5104 | unsigned LocalBaseSubmoduleID = Record[1]; |
| 5105 | if (F.LocalNumSubmodules > 0) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5106 | // Introduce the global -> local mapping for submodules within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5107 | // module. |
| 5108 | GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5109 | |
| 5110 | // Introduce the local -> global mapping for submodules within this |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5111 | // module. |
| 5112 | F.SubmoduleRemap.insertOrReplace( |
| 5113 | std::make_pair(LocalBaseSubmoduleID, |
| 5114 | F.BaseSubmoduleID - LocalBaseSubmoduleID)); |
Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 5115 | |
Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 5116 | SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules); |
| 5117 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5118 | break; |
| 5119 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5120 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5121 | case SUBMODULE_IMPORTS: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5122 | for (unsigned Idx = 0; Idx != Record.size(); ++Idx) { |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5123 | UnresolvedModuleRef Unresolved; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5124 | Unresolved.File = &F; |
| 5125 | Unresolved.Mod = CurrentModule; |
| 5126 | Unresolved.ID = Record[Idx]; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5127 | Unresolved.Kind = UnresolvedModuleRef::Import; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5128 | Unresolved.IsWildcard = false; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5129 | UnresolvedModuleRefs.push_back(Unresolved); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5130 | } |
| 5131 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5132 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5133 | case SUBMODULE_EXPORTS: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5134 | for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) { |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5135 | UnresolvedModuleRef Unresolved; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5136 | Unresolved.File = &F; |
| 5137 | Unresolved.Mod = CurrentModule; |
| 5138 | Unresolved.ID = Record[Idx]; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5139 | Unresolved.Kind = UnresolvedModuleRef::Export; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5140 | Unresolved.IsWildcard = Record[Idx + 1]; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5141 | UnresolvedModuleRefs.push_back(Unresolved); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5142 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5143 | |
| 5144 | // 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] | 5145 | // the parsed, unresolved exports around. |
| 5146 | CurrentModule->UnresolvedExports.clear(); |
| 5147 | break; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5148 | |
| 5149 | case SUBMODULE_REQUIRES: |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5150 | CurrentModule->addRequirement(Blob, Record[0], PP.getLangOpts(), |
| 5151 | PP.getTargetInfo()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5152 | break; |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5153 | |
| 5154 | case SUBMODULE_LINK_LIBRARY: |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5155 | CurrentModule->LinkLibraries.push_back( |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5156 | Module::LinkLibrary(Blob, Record[0])); |
Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5157 | break; |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 5158 | |
| 5159 | case SUBMODULE_CONFIG_MACRO: |
Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 5160 | CurrentModule->ConfigMacros.push_back(Blob.str()); |
| 5161 | break; |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5162 | |
| 5163 | case SUBMODULE_CONFLICT: { |
Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5164 | UnresolvedModuleRef Unresolved; |
| 5165 | Unresolved.File = &F; |
| 5166 | Unresolved.Mod = CurrentModule; |
| 5167 | Unresolved.ID = Record[0]; |
| 5168 | Unresolved.Kind = UnresolvedModuleRef::Conflict; |
| 5169 | Unresolved.IsWildcard = false; |
| 5170 | Unresolved.String = Blob; |
| 5171 | UnresolvedModuleRefs.push_back(Unresolved); |
| 5172 | break; |
| 5173 | } |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 5174 | |
Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame] | 5175 | case SUBMODULE_INITIALIZERS: { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5176 | if (!ContextObj) |
| 5177 | break; |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 5178 | SmallVector<uint32_t, 16> Inits; |
| 5179 | for (auto &ID : Record) |
| 5180 | Inits.push_back(getGlobalDeclID(F, ID)); |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5181 | ContextObj->addLazyModuleInitializers(CurrentModule, Inits); |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 5182 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5183 | } |
Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame] | 5184 | |
| 5185 | case SUBMODULE_EXPORT_AS: |
| 5186 | CurrentModule->ExportAsModule = Blob.str(); |
| 5187 | break; |
| 5188 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5189 | } |
| 5190 | } |
| 5191 | |
| 5192 | /// \brief Parse the record that corresponds to a LangOptions data |
| 5193 | /// structure. |
| 5194 | /// |
| 5195 | /// This routine parses the language options from the AST file and then gives |
| 5196 | /// them to the AST listener if one is set. |
| 5197 | /// |
| 5198 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
| 5199 | bool ASTReader::ParseLanguageOptions(const RecordData &Record, |
| 5200 | bool Complain, |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 5201 | ASTReaderListener &Listener, |
| 5202 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5203 | LangOptions LangOpts; |
| 5204 | unsigned Idx = 0; |
| 5205 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 5206 | LangOpts.Name = Record[Idx++]; |
| 5207 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 5208 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 5209 | #include "clang/Basic/LangOptions.def" |
Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 5210 | #define SANITIZER(NAME, ID) \ |
| 5211 | LangOpts.Sanitize.set(SanitizerKind::ID, Record[Idx++]); |
Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 5212 | #include "clang/Basic/Sanitizers.def" |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5213 | |
Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 5214 | for (unsigned N = Record[Idx++]; N; --N) |
| 5215 | LangOpts.ModuleFeatures.push_back(ReadString(Record, Idx)); |
| 5216 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5217 | ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++]; |
| 5218 | VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx); |
| 5219 | LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 5220 | |
Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 5221 | LangOpts.CurrentModule = ReadString(Record, Idx); |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 5222 | |
| 5223 | // Comment options. |
| 5224 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5225 | LangOpts.CommentOpts.BlockCommandNames.push_back( |
| 5226 | ReadString(Record, Idx)); |
| 5227 | } |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 5228 | LangOpts.CommentOpts.ParseAllComments = Record[Idx++]; |
Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 5229 | |
Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 5230 | // OpenMP offloading options. |
| 5231 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5232 | LangOpts.OMPTargetTriples.push_back(llvm::Triple(ReadString(Record, Idx))); |
| 5233 | } |
| 5234 | |
| 5235 | LangOpts.OMPHostIRFile = ReadString(Record, Idx); |
| 5236 | |
Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 5237 | return Listener.ReadLanguageOptions(LangOpts, Complain, |
| 5238 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5239 | } |
| 5240 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 5241 | bool ASTReader::ParseTargetOptions(const RecordData &Record, bool Complain, |
| 5242 | ASTReaderListener &Listener, |
| 5243 | bool AllowCompatibleDifferences) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5244 | unsigned Idx = 0; |
| 5245 | TargetOptions TargetOpts; |
| 5246 | TargetOpts.Triple = ReadString(Record, Idx); |
| 5247 | TargetOpts.CPU = ReadString(Record, Idx); |
| 5248 | TargetOpts.ABI = ReadString(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5249 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5250 | TargetOpts.FeaturesAsWritten.push_back(ReadString(Record, Idx)); |
| 5251 | } |
| 5252 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5253 | TargetOpts.Features.push_back(ReadString(Record, Idx)); |
| 5254 | } |
| 5255 | |
Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 5256 | return Listener.ReadTargetOptions(TargetOpts, Complain, |
| 5257 | AllowCompatibleDifferences); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5258 | } |
| 5259 | |
| 5260 | bool ASTReader::ParseDiagnosticOptions(const RecordData &Record, bool Complain, |
| 5261 | ASTReaderListener &Listener) { |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5262 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5263 | unsigned Idx = 0; |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5264 | #define DIAGOPT(Name, Bits, Default) DiagOpts->Name = Record[Idx++]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5265 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5266 | DiagOpts->set##Name(static_cast<Type>(Record[Idx++])); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5267 | #include "clang/Basic/DiagnosticOptions.def" |
| 5268 | |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 5269 | for (unsigned N = Record[Idx++]; N; --N) |
Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5270 | DiagOpts->Warnings.push_back(ReadString(Record, Idx)); |
Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 5271 | for (unsigned N = Record[Idx++]; N; --N) |
| 5272 | DiagOpts->Remarks.push_back(ReadString(Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5273 | |
| 5274 | return Listener.ReadDiagnosticOptions(DiagOpts, Complain); |
| 5275 | } |
| 5276 | |
| 5277 | bool ASTReader::ParseFileSystemOptions(const RecordData &Record, bool Complain, |
| 5278 | ASTReaderListener &Listener) { |
| 5279 | FileSystemOptions FSOpts; |
| 5280 | unsigned Idx = 0; |
| 5281 | FSOpts.WorkingDir = ReadString(Record, Idx); |
| 5282 | return Listener.ReadFileSystemOptions(FSOpts, Complain); |
| 5283 | } |
| 5284 | |
| 5285 | bool ASTReader::ParseHeaderSearchOptions(const RecordData &Record, |
| 5286 | bool Complain, |
| 5287 | ASTReaderListener &Listener) { |
| 5288 | HeaderSearchOptions HSOpts; |
| 5289 | unsigned Idx = 0; |
| 5290 | HSOpts.Sysroot = ReadString(Record, Idx); |
| 5291 | |
| 5292 | // Include entries. |
| 5293 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5294 | std::string Path = ReadString(Record, Idx); |
| 5295 | frontend::IncludeDirGroup Group |
| 5296 | = static_cast<frontend::IncludeDirGroup>(Record[Idx++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5297 | bool IsFramework = Record[Idx++]; |
| 5298 | bool IgnoreSysRoot = Record[Idx++]; |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 5299 | HSOpts.UserEntries.emplace_back(std::move(Path), Group, IsFramework, |
| 5300 | IgnoreSysRoot); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5301 | } |
| 5302 | |
| 5303 | // System header prefixes. |
| 5304 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5305 | std::string Prefix = ReadString(Record, Idx); |
| 5306 | bool IsSystemHeader = Record[Idx++]; |
Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 5307 | HSOpts.SystemHeaderPrefixes.emplace_back(std::move(Prefix), IsSystemHeader); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5308 | } |
| 5309 | |
| 5310 | HSOpts.ResourceDir = ReadString(Record, Idx); |
| 5311 | HSOpts.ModuleCachePath = ReadString(Record, Idx); |
Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 5312 | HSOpts.ModuleUserBuildPath = ReadString(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5313 | HSOpts.DisableModuleHash = Record[Idx++]; |
Richard Smith | 1893475 | 2017-06-06 00:32:01 +0000 | [diff] [blame] | 5314 | HSOpts.ImplicitModuleMaps = Record[Idx++]; |
| 5315 | HSOpts.ModuleMapFileHomeIsCwd = Record[Idx++]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5316 | HSOpts.UseBuiltinIncludes = Record[Idx++]; |
| 5317 | HSOpts.UseStandardSystemIncludes = Record[Idx++]; |
| 5318 | HSOpts.UseStandardCXXIncludes = Record[Idx++]; |
| 5319 | HSOpts.UseLibcxx = Record[Idx++]; |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 5320 | std::string SpecificModuleCachePath = ReadString(Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5321 | |
Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 5322 | return Listener.ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 5323 | Complain); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5324 | } |
| 5325 | |
| 5326 | bool ASTReader::ParsePreprocessorOptions(const RecordData &Record, |
| 5327 | bool Complain, |
| 5328 | ASTReaderListener &Listener, |
| 5329 | std::string &SuggestedPredefines) { |
| 5330 | PreprocessorOptions PPOpts; |
| 5331 | unsigned Idx = 0; |
| 5332 | |
| 5333 | // Macro definitions/undefs |
| 5334 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5335 | std::string Macro = ReadString(Record, Idx); |
| 5336 | bool IsUndef = Record[Idx++]; |
| 5337 | PPOpts.Macros.push_back(std::make_pair(Macro, IsUndef)); |
| 5338 | } |
| 5339 | |
| 5340 | // Includes |
| 5341 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5342 | PPOpts.Includes.push_back(ReadString(Record, Idx)); |
| 5343 | } |
| 5344 | |
| 5345 | // Macro Includes |
| 5346 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5347 | PPOpts.MacroIncludes.push_back(ReadString(Record, Idx)); |
| 5348 | } |
| 5349 | |
| 5350 | PPOpts.UsePredefines = Record[Idx++]; |
Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 5351 | PPOpts.DetailedRecord = Record[Idx++]; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5352 | PPOpts.ImplicitPCHInclude = ReadString(Record, Idx); |
| 5353 | PPOpts.ImplicitPTHInclude = ReadString(Record, Idx); |
| 5354 | PPOpts.ObjCXXARCStandardLibrary = |
| 5355 | static_cast<ObjCXXARCStandardLibraryKind>(Record[Idx++]); |
| 5356 | SuggestedPredefines.clear(); |
| 5357 | return Listener.ReadPreprocessorOptions(PPOpts, Complain, |
| 5358 | SuggestedPredefines); |
| 5359 | } |
| 5360 | |
| 5361 | std::pair<ModuleFile *, unsigned> |
| 5362 | ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { |
| 5363 | GlobalPreprocessedEntityMapType::iterator |
| 5364 | I = GlobalPreprocessedEntityMap.find(GlobalIndex); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5365 | assert(I != GlobalPreprocessedEntityMap.end() && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5366 | "Corrupted global preprocessed entity map"); |
| 5367 | ModuleFile *M = I->second; |
| 5368 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; |
| 5369 | return std::make_pair(M, LocalIndex); |
| 5370 | } |
| 5371 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5372 | llvm::iterator_range<PreprocessingRecord::iterator> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5373 | ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const { |
| 5374 | if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord()) |
| 5375 | return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID, |
| 5376 | Mod.NumPreprocessedEntities); |
| 5377 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5378 | return llvm::make_range(PreprocessingRecord::iterator(), |
| 5379 | PreprocessingRecord::iterator()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5380 | } |
| 5381 | |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5382 | llvm::iterator_range<ASTReader::ModuleDeclIterator> |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5383 | ASTReader::getModuleFileLevelDecls(ModuleFile &Mod) { |
Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5384 | return llvm::make_range( |
| 5385 | ModuleDeclIterator(this, &Mod, Mod.FileSortedDecls), |
| 5386 | ModuleDeclIterator(this, &Mod, |
| 5387 | Mod.FileSortedDecls + Mod.NumFileSortedDecls)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5388 | } |
| 5389 | |
| 5390 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { |
| 5391 | PreprocessedEntityID PPID = Index+1; |
| 5392 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 5393 | ModuleFile &M = *PPInfo.first; |
| 5394 | unsigned LocalIndex = PPInfo.second; |
| 5395 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 5396 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5397 | if (!PP.getPreprocessingRecord()) { |
| 5398 | Error("no preprocessing record"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5399 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5400 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5401 | |
| 5402 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5403 | M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset); |
| 5404 | |
| 5405 | llvm::BitstreamEntry Entry = |
| 5406 | M.PreprocessorDetailCursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd); |
| 5407 | if (Entry.Kind != llvm::BitstreamEntry::Record) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5408 | return nullptr; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5409 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5410 | // Read the record. |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 5411 | SourceRange Range(TranslateSourceLocation(M, PPOffs.getBegin()), |
| 5412 | TranslateSourceLocation(M, PPOffs.getEnd())); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5413 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5414 | StringRef Blob; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5415 | RecordData Record; |
| 5416 | PreprocessorDetailRecordTypes RecType = |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5417 | (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.readRecord( |
| 5418 | Entry.ID, Record, &Blob); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5419 | switch (RecType) { |
| 5420 | case PPD_MACRO_EXPANSION: { |
| 5421 | bool isBuiltin = Record[0]; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5422 | IdentifierInfo *Name = nullptr; |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5423 | MacroDefinitionRecord *Def = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5424 | if (isBuiltin) |
| 5425 | Name = getLocalIdentifier(M, Record[1]); |
| 5426 | else { |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5427 | PreprocessedEntityID GlobalID = |
| 5428 | getGlobalPreprocessedEntityID(M, Record[1]); |
| 5429 | Def = cast<MacroDefinitionRecord>( |
| 5430 | PPRec.getLoadedPreprocessedEntity(GlobalID - 1)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5431 | } |
| 5432 | |
| 5433 | MacroExpansion *ME; |
| 5434 | if (isBuiltin) |
| 5435 | ME = new (PPRec) MacroExpansion(Name, Range); |
| 5436 | else |
| 5437 | ME = new (PPRec) MacroExpansion(Def, Range); |
| 5438 | |
| 5439 | return ME; |
| 5440 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5441 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5442 | case PPD_MACRO_DEFINITION: { |
| 5443 | // Decode the identifier info and then check again; if the macro is |
| 5444 | // still defined and associated with the identifier, |
| 5445 | IdentifierInfo *II = getLocalIdentifier(M, Record[0]); |
Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5446 | MacroDefinitionRecord *MD = new (PPRec) MacroDefinitionRecord(II, Range); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5447 | |
| 5448 | if (DeserializationListener) |
| 5449 | DeserializationListener->MacroDefinitionRead(PPID, MD); |
| 5450 | |
| 5451 | return MD; |
| 5452 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5453 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5454 | case PPD_INCLUSION_DIRECTIVE: { |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5455 | const char *FullFileNameStart = Blob.data() + Record[0]; |
| 5456 | StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5457 | const FileEntry *File = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5458 | if (!FullFileName.empty()) |
| 5459 | File = PP.getFileManager().getFile(FullFileName); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5460 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5461 | // FIXME: Stable encoding |
| 5462 | InclusionDirective::InclusionKind Kind |
| 5463 | = static_cast<InclusionDirective::InclusionKind>(Record[2]); |
| 5464 | InclusionDirective *ID |
| 5465 | = new (PPRec) InclusionDirective(PPRec, Kind, |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5466 | StringRef(Blob.data(), Record[0]), |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5467 | Record[1], Record[3], |
| 5468 | File, |
| 5469 | Range); |
| 5470 | return ID; |
| 5471 | } |
| 5472 | } |
| 5473 | |
| 5474 | llvm_unreachable("Invalid PreprocessorDetailRecordTypes"); |
| 5475 | } |
| 5476 | |
NAKAMURA Takumi | 12ab07e | 2017-10-12 09:42:14 +0000 | [diff] [blame] | 5477 | /// \brief Find the next module that contains entities and return the ID |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5478 | /// of the first entry. |
NAKAMURA Takumi | 12ab07e | 2017-10-12 09:42:14 +0000 | [diff] [blame] | 5479 | /// |
| 5480 | /// \param SLocMapI points at a chunk of a module that contains no |
| 5481 | /// preprocessed entities or the entities it contains are not the ones we are |
| 5482 | /// looking for. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5483 | PreprocessedEntityID ASTReader::findNextPreprocessedEntity( |
| 5484 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const { |
| 5485 | ++SLocMapI; |
| 5486 | for (GlobalSLocOffsetMapType::const_iterator |
| 5487 | EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) { |
| 5488 | ModuleFile &M = *SLocMapI->second; |
| 5489 | if (M.NumPreprocessedEntities) |
| 5490 | return M.BasePreprocessedEntityID; |
| 5491 | } |
| 5492 | |
| 5493 | return getTotalNumPreprocessedEntities(); |
| 5494 | } |
| 5495 | |
| 5496 | namespace { |
| 5497 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5498 | struct PPEntityComp { |
| 5499 | const ASTReader &Reader; |
| 5500 | ModuleFile &M; |
| 5501 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5502 | PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) {} |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5503 | |
| 5504 | bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const { |
| 5505 | SourceLocation LHS = getLoc(L); |
| 5506 | SourceLocation RHS = getLoc(R); |
| 5507 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5508 | } |
| 5509 | |
| 5510 | bool operator()(const PPEntityOffset &L, SourceLocation RHS) const { |
| 5511 | SourceLocation LHS = getLoc(L); |
| 5512 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5513 | } |
| 5514 | |
| 5515 | bool operator()(SourceLocation LHS, const PPEntityOffset &R) const { |
| 5516 | SourceLocation RHS = getLoc(R); |
| 5517 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5518 | } |
| 5519 | |
| 5520 | SourceLocation getLoc(const PPEntityOffset &PPE) const { |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5521 | return Reader.TranslateSourceLocation(M, PPE.getBegin()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5522 | } |
| 5523 | }; |
| 5524 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5525 | } // namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5526 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5527 | PreprocessedEntityID ASTReader::findPreprocessedEntity(SourceLocation Loc, |
| 5528 | bool EndsAfter) const { |
| 5529 | if (SourceMgr.isLocalSourceLocation(Loc)) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5530 | return getTotalNumPreprocessedEntities(); |
| 5531 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5532 | GlobalSLocOffsetMapType::const_iterator SLocMapI = GlobalSLocOffsetMap.find( |
| 5533 | SourceManager::MaxLoadedOffset - Loc.getOffset() - 1); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5534 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 5535 | "Corrupted global sloc offset map"); |
| 5536 | |
| 5537 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 5538 | return findNextPreprocessedEntity(SLocMapI); |
| 5539 | |
| 5540 | ModuleFile &M = *SLocMapI->second; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5541 | |
| 5542 | using pp_iterator = const PPEntityOffset *; |
| 5543 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5544 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 5545 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
| 5546 | |
| 5547 | size_t Count = M.NumPreprocessedEntities; |
| 5548 | size_t Half; |
| 5549 | pp_iterator First = pp_begin; |
| 5550 | pp_iterator PPI; |
| 5551 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5552 | if (EndsAfter) { |
| 5553 | PPI = std::upper_bound(pp_begin, pp_end, Loc, |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5554 | PPEntityComp(*this, M)); |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5555 | } else { |
| 5556 | // Do a binary search manually instead of using std::lower_bound because |
| 5557 | // The end locations of entities may be unordered (when a macro expansion |
| 5558 | // is inside another macro argument), but for this case it is not important |
| 5559 | // whether we get the first macro expansion or its containing macro. |
| 5560 | while (Count > 0) { |
| 5561 | Half = Count / 2; |
| 5562 | PPI = First; |
| 5563 | std::advance(PPI, Half); |
Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5564 | if (SourceMgr.isBeforeInTranslationUnit( |
| 5565 | TranslateSourceLocation(M, PPI->getEnd()), Loc)) { |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5566 | First = PPI; |
| 5567 | ++First; |
| 5568 | Count = Count - Half - 1; |
| 5569 | } else |
| 5570 | Count = Half; |
| 5571 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5572 | } |
| 5573 | |
| 5574 | if (PPI == pp_end) |
| 5575 | return findNextPreprocessedEntity(SLocMapI); |
| 5576 | |
| 5577 | return M.BasePreprocessedEntityID + (PPI - pp_begin); |
| 5578 | } |
| 5579 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5580 | /// \brief Returns a pair of [Begin, End) indices of preallocated |
| 5581 | /// preprocessed entities that \arg Range encompasses. |
| 5582 | std::pair<unsigned, unsigned> |
| 5583 | ASTReader::findPreprocessedEntitiesInRange(SourceRange Range) { |
| 5584 | if (Range.isInvalid()) |
| 5585 | return std::make_pair(0,0); |
| 5586 | assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); |
| 5587 | |
Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5588 | PreprocessedEntityID BeginID = |
| 5589 | findPreprocessedEntity(Range.getBegin(), false); |
| 5590 | PreprocessedEntityID EndID = findPreprocessedEntity(Range.getEnd(), true); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5591 | return std::make_pair(BeginID, EndID); |
| 5592 | } |
| 5593 | |
| 5594 | /// \brief Optionally returns true or false if the preallocated preprocessed |
| 5595 | /// entity with index \arg Index came from file \arg FID. |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5596 | Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5597 | FileID FID) { |
| 5598 | if (FID.isInvalid()) |
| 5599 | return false; |
| 5600 | |
| 5601 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 5602 | ModuleFile &M = *PPInfo.first; |
| 5603 | unsigned LocalIndex = PPInfo.second; |
| 5604 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5605 | |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 5606 | SourceLocation Loc = TranslateSourceLocation(M, PPOffs.getBegin()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5607 | if (Loc.isInvalid()) |
| 5608 | return false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5609 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5610 | if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) |
| 5611 | return true; |
| 5612 | else |
| 5613 | return false; |
| 5614 | } |
| 5615 | |
| 5616 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5617 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5618 | /// \brief Visitor used to search for information about a header file. |
| 5619 | class HeaderFileInfoVisitor { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5620 | const FileEntry *FE; |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5621 | Optional<HeaderFileInfo> HFI; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5622 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5623 | public: |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5624 | explicit HeaderFileInfoVisitor(const FileEntry *FE) : FE(FE) {} |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 5625 | |
| 5626 | bool operator()(ModuleFile &M) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5627 | HeaderFileInfoLookupTable *Table |
| 5628 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 5629 | if (!Table) |
| 5630 | return false; |
| 5631 | |
| 5632 | // 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] | 5633 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5634 | if (Pos == Table->end()) |
| 5635 | return false; |
| 5636 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 5637 | HFI = *Pos; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5638 | return true; |
| 5639 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5640 | |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5641 | Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5642 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5643 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5644 | } // namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5645 | |
| 5646 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
Argyrios Kyrtzidis | 61a3896 | 2013-03-06 18:12:44 +0000 | [diff] [blame] | 5647 | HeaderFileInfoVisitor Visitor(FE); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 5648 | ModuleMgr.visit(Visitor); |
Argyrios Kyrtzidis | 1054bbf | 2013-05-08 23:46:55 +0000 | [diff] [blame] | 5649 | if (Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5650 | return *HFI; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5651 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5652 | return HeaderFileInfo(); |
| 5653 | } |
| 5654 | |
| 5655 | void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5656 | using DiagState = DiagnosticsEngine::DiagState; |
| 5657 | SmallVector<DiagState *, 32> DiagStates; |
| 5658 | |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 5659 | for (ModuleFile &F : ModuleMgr) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5660 | unsigned Idx = 0; |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5661 | auto &Record = F.PragmaDiagMappings; |
| 5662 | if (Record.empty()) |
| 5663 | continue; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5664 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5665 | DiagStates.clear(); |
| 5666 | |
| 5667 | auto ReadDiagState = |
| 5668 | [&](const DiagState &BasedOn, SourceLocation Loc, |
| 5669 | bool IncludeNonPragmaStates) -> DiagnosticsEngine::DiagState * { |
| 5670 | unsigned BackrefID = Record[Idx++]; |
| 5671 | if (BackrefID != 0) |
| 5672 | return DiagStates[BackrefID - 1]; |
| 5673 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5674 | // A new DiagState was created here. |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5675 | Diag.DiagStates.push_back(BasedOn); |
| 5676 | DiagState *NewState = &Diag.DiagStates.back(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5677 | DiagStates.push_back(NewState); |
Duncan P. N. Exon Smith | 3cb183b | 2017-03-14 19:31:27 +0000 | [diff] [blame] | 5678 | unsigned Size = Record[Idx++]; |
| 5679 | assert(Idx + Size * 2 <= Record.size() && |
| 5680 | "Invalid data, not enough diag/map pairs"); |
| 5681 | while (Size--) { |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5682 | unsigned DiagID = Record[Idx++]; |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5683 | DiagnosticMapping NewMapping = |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5684 | DiagnosticMapping::deserialize(Record[Idx++]); |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5685 | if (!NewMapping.isPragma() && !IncludeNonPragmaStates) |
| 5686 | continue; |
| 5687 | |
| 5688 | DiagnosticMapping &Mapping = NewState->getOrAddMapping(DiagID); |
| 5689 | |
| 5690 | // If this mapping was specified as a warning but the severity was |
| 5691 | // upgraded due to diagnostic settings, simulate the current diagnostic |
| 5692 | // settings (and use a warning). |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5693 | if (NewMapping.wasUpgradedFromWarning() && !Mapping.isErrorOrFatal()) { |
| 5694 | NewMapping.setSeverity(diag::Severity::Warning); |
| 5695 | NewMapping.setUpgradedFromWarning(false); |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5696 | } |
| 5697 | |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5698 | Mapping = NewMapping; |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5699 | } |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5700 | return NewState; |
| 5701 | }; |
| 5702 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5703 | // Read the first state. |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5704 | DiagState *FirstState; |
| 5705 | if (F.Kind == MK_ImplicitModule) { |
| 5706 | // Implicitly-built modules are reused with different diagnostic |
| 5707 | // settings. Use the initial diagnostic state from Diag to simulate this |
| 5708 | // compilation's diagnostic settings. |
| 5709 | FirstState = Diag.DiagStatesByLoc.FirstDiagState; |
| 5710 | DiagStates.push_back(FirstState); |
| 5711 | |
| 5712 | // Skip the initial diagnostic state from the serialized module. |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5713 | assert(Record[1] == 0 && |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5714 | "Invalid data, unexpected backref in initial state"); |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5715 | Idx = 3 + Record[2] * 2; |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5716 | assert(Idx < Record.size() && |
| 5717 | "Invalid data, not enough state change pairs in initial state"); |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5718 | } else if (F.isModule()) { |
| 5719 | // For an explicit module, preserve the flags from the module build |
| 5720 | // command line (-w, -Weverything, -Werror, ...) along with any explicit |
| 5721 | // -Wblah flags. |
| 5722 | unsigned Flags = Record[Idx++]; |
| 5723 | DiagState Initial; |
| 5724 | Initial.SuppressSystemWarnings = Flags & 1; Flags >>= 1; |
| 5725 | Initial.ErrorsAsFatal = Flags & 1; Flags >>= 1; |
| 5726 | Initial.WarningsAsErrors = Flags & 1; Flags >>= 1; |
| 5727 | Initial.EnableAllWarnings = Flags & 1; Flags >>= 1; |
| 5728 | Initial.IgnoreAllWarnings = Flags & 1; Flags >>= 1; |
| 5729 | Initial.ExtBehavior = (diag::Severity)Flags; |
| 5730 | FirstState = ReadDiagState(Initial, SourceLocation(), true); |
Richard Smith | ea74148 | 2017-05-01 22:10:47 +0000 | [diff] [blame] | 5731 | |
Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5732 | // Set up the root buffer of the module to start with the initial |
| 5733 | // diagnostic state of the module itself, to cover files that contain no |
| 5734 | // explicit transitions (for which we did not serialize anything). |
| 5735 | Diag.DiagStatesByLoc.Files[F.OriginalSourceFileID] |
| 5736 | .StateTransitions.push_back({FirstState, 0}); |
| 5737 | } else { |
| 5738 | // For prefix ASTs, start with whatever the user configured on the |
| 5739 | // command line. |
| 5740 | Idx++; // Skip flags. |
| 5741 | FirstState = ReadDiagState(*Diag.DiagStatesByLoc.CurDiagState, |
| 5742 | SourceLocation(), false); |
Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5743 | } |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5744 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5745 | // Read the state transitions. |
| 5746 | unsigned NumLocations = Record[Idx++]; |
| 5747 | while (NumLocations--) { |
| 5748 | assert(Idx < Record.size() && |
| 5749 | "Invalid data, missing pragma diagnostic states"); |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5750 | SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]); |
| 5751 | auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc); |
| 5752 | assert(IDAndOffset.second == 0 && "not a start location for a FileID"); |
| 5753 | unsigned Transitions = Record[Idx++]; |
| 5754 | |
| 5755 | // Note that we don't need to set up Parent/ParentOffset here, because |
| 5756 | // we won't be changing the diagnostic state within imported FileIDs |
| 5757 | // (other than perhaps appending to the main source file, which has no |
| 5758 | // parent). |
| 5759 | auto &F = Diag.DiagStatesByLoc.Files[IDAndOffset.first]; |
| 5760 | F.StateTransitions.reserve(F.StateTransitions.size() + Transitions); |
| 5761 | for (unsigned I = 0; I != Transitions; ++I) { |
| 5762 | unsigned Offset = Record[Idx++]; |
| 5763 | auto *State = |
| 5764 | ReadDiagState(*FirstState, Loc.getLocWithOffset(Offset), false); |
| 5765 | F.StateTransitions.push_back({State, Offset}); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5766 | } |
| 5767 | } |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5768 | |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5769 | // Read the final state. |
| 5770 | assert(Idx < Record.size() && |
| 5771 | "Invalid data, missing final pragma diagnostic state"); |
| 5772 | SourceLocation CurStateLoc = |
| 5773 | ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
| 5774 | auto *CurState = ReadDiagState(*FirstState, CurStateLoc, false); |
| 5775 | |
| 5776 | if (!F.isModule()) { |
| 5777 | Diag.DiagStatesByLoc.CurDiagState = CurState; |
| 5778 | Diag.DiagStatesByLoc.CurDiagStateLoc = CurStateLoc; |
| 5779 | |
| 5780 | // Preserve the property that the imaginary root file describes the |
| 5781 | // current state. |
Simon Pilgrim | 2251863 | 2017-10-10 13:56:17 +0000 | [diff] [blame] | 5782 | FileID NullFile; |
| 5783 | auto &T = Diag.DiagStatesByLoc.Files[NullFile].StateTransitions; |
Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5784 | if (T.empty()) |
| 5785 | T.push_back({CurState, 0}); |
| 5786 | else |
| 5787 | T[0].State = CurState; |
| 5788 | } |
| 5789 | |
Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5790 | // Don't try to read these mappings again. |
| 5791 | Record.clear(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5792 | } |
| 5793 | } |
| 5794 | |
| 5795 | /// \brief Get the correct cursor and offset for loading a type. |
| 5796 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
| 5797 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
| 5798 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
| 5799 | ModuleFile *M = I->second; |
| 5800 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
| 5801 | } |
| 5802 | |
| 5803 | /// \brief Read and return the type with the given index.. |
| 5804 | /// |
| 5805 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 5806 | /// routine actually reads the record corresponding to the type at the given |
| 5807 | /// location. It is a helper routine for GetType, which deals with reading type |
| 5808 | /// IDs. |
| 5809 | QualType ASTReader::readTypeRecord(unsigned Index) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5810 | assert(ContextObj && "reading type with no AST context"); |
| 5811 | ASTContext &Context = *ContextObj; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5812 | RecordLocation Loc = TypeCursorForIndex(Index); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5813 | BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5814 | |
| 5815 | // Keep track of where we are in the stream, then jump back there |
| 5816 | // after reading this type. |
| 5817 | SavedStreamPosition SavedPosition(DeclsCursor); |
| 5818 | |
| 5819 | ReadingKindTracker ReadingKind(Read_Type, *this); |
| 5820 | |
| 5821 | // Note that we are loading a type record. |
| 5822 | Deserializing AType(this); |
| 5823 | |
| 5824 | unsigned Idx = 0; |
| 5825 | DeclsCursor.JumpToBit(Loc.Offset); |
| 5826 | RecordData Record; |
| 5827 | unsigned Code = DeclsCursor.ReadCode(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5828 | switch ((TypeCode)DeclsCursor.readRecord(Code, Record)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5829 | case TYPE_EXT_QUAL: { |
| 5830 | if (Record.size() != 2) { |
| 5831 | Error("Incorrect encoding of extended qualifier type"); |
| 5832 | return QualType(); |
| 5833 | } |
| 5834 | QualType Base = readType(*Loc.F, Record, Idx); |
| 5835 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
| 5836 | return Context.getQualifiedType(Base, Quals); |
| 5837 | } |
| 5838 | |
| 5839 | case TYPE_COMPLEX: { |
| 5840 | if (Record.size() != 1) { |
| 5841 | Error("Incorrect encoding of complex type"); |
| 5842 | return QualType(); |
| 5843 | } |
| 5844 | QualType ElemType = readType(*Loc.F, Record, Idx); |
| 5845 | return Context.getComplexType(ElemType); |
| 5846 | } |
| 5847 | |
| 5848 | case TYPE_POINTER: { |
| 5849 | if (Record.size() != 1) { |
| 5850 | Error("Incorrect encoding of pointer type"); |
| 5851 | return QualType(); |
| 5852 | } |
| 5853 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5854 | return Context.getPointerType(PointeeType); |
| 5855 | } |
| 5856 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 5857 | case TYPE_DECAYED: { |
| 5858 | if (Record.size() != 1) { |
| 5859 | Error("Incorrect encoding of decayed type"); |
| 5860 | return QualType(); |
| 5861 | } |
| 5862 | QualType OriginalType = readType(*Loc.F, Record, Idx); |
| 5863 | QualType DT = Context.getAdjustedParameterType(OriginalType); |
| 5864 | if (!isa<DecayedType>(DT)) |
| 5865 | Error("Decayed type does not decay"); |
| 5866 | return DT; |
| 5867 | } |
| 5868 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 5869 | case TYPE_ADJUSTED: { |
| 5870 | if (Record.size() != 2) { |
| 5871 | Error("Incorrect encoding of adjusted type"); |
| 5872 | return QualType(); |
| 5873 | } |
| 5874 | QualType OriginalTy = readType(*Loc.F, Record, Idx); |
| 5875 | QualType AdjustedTy = readType(*Loc.F, Record, Idx); |
| 5876 | return Context.getAdjustedType(OriginalTy, AdjustedTy); |
| 5877 | } |
| 5878 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5879 | case TYPE_BLOCK_POINTER: { |
| 5880 | if (Record.size() != 1) { |
| 5881 | Error("Incorrect encoding of block pointer type"); |
| 5882 | return QualType(); |
| 5883 | } |
| 5884 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5885 | return Context.getBlockPointerType(PointeeType); |
| 5886 | } |
| 5887 | |
| 5888 | case TYPE_LVALUE_REFERENCE: { |
| 5889 | if (Record.size() != 2) { |
| 5890 | Error("Incorrect encoding of lvalue reference type"); |
| 5891 | return QualType(); |
| 5892 | } |
| 5893 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5894 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
| 5895 | } |
| 5896 | |
| 5897 | case TYPE_RVALUE_REFERENCE: { |
| 5898 | if (Record.size() != 1) { |
| 5899 | Error("Incorrect encoding of rvalue reference type"); |
| 5900 | return QualType(); |
| 5901 | } |
| 5902 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5903 | return Context.getRValueReferenceType(PointeeType); |
| 5904 | } |
| 5905 | |
| 5906 | case TYPE_MEMBER_POINTER: { |
| 5907 | if (Record.size() != 2) { |
| 5908 | Error("Incorrect encoding of member pointer type"); |
| 5909 | return QualType(); |
| 5910 | } |
| 5911 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5912 | QualType ClassType = readType(*Loc.F, Record, Idx); |
| 5913 | if (PointeeType.isNull() || ClassType.isNull()) |
| 5914 | return QualType(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5915 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5916 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
| 5917 | } |
| 5918 | |
| 5919 | case TYPE_CONSTANT_ARRAY: { |
| 5920 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5921 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 5922 | unsigned IndexTypeQuals = Record[2]; |
| 5923 | unsigned Idx = 3; |
| 5924 | llvm::APInt Size = ReadAPInt(Record, Idx); |
| 5925 | return Context.getConstantArrayType(ElementType, Size, |
| 5926 | ASM, IndexTypeQuals); |
| 5927 | } |
| 5928 | |
| 5929 | case TYPE_INCOMPLETE_ARRAY: { |
| 5930 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5931 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 5932 | unsigned IndexTypeQuals = Record[2]; |
| 5933 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
| 5934 | } |
| 5935 | |
| 5936 | case TYPE_VARIABLE_ARRAY: { |
| 5937 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5938 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| 5939 | unsigned IndexTypeQuals = Record[2]; |
| 5940 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 5941 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 5942 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
| 5943 | ASM, IndexTypeQuals, |
| 5944 | SourceRange(LBLoc, RBLoc)); |
| 5945 | } |
| 5946 | |
| 5947 | case TYPE_VECTOR: { |
| 5948 | if (Record.size() != 3) { |
| 5949 | Error("incorrect encoding of vector type in AST file"); |
| 5950 | return QualType(); |
| 5951 | } |
| 5952 | |
| 5953 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5954 | unsigned NumElements = Record[1]; |
| 5955 | unsigned VecKind = Record[2]; |
| 5956 | return Context.getVectorType(ElementType, NumElements, |
| 5957 | (VectorType::VectorKind)VecKind); |
| 5958 | } |
| 5959 | |
| 5960 | case TYPE_EXT_VECTOR: { |
| 5961 | if (Record.size() != 3) { |
| 5962 | Error("incorrect encoding of extended vector type in AST file"); |
| 5963 | return QualType(); |
| 5964 | } |
| 5965 | |
| 5966 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 5967 | unsigned NumElements = Record[1]; |
| 5968 | return Context.getExtVectorType(ElementType, NumElements); |
| 5969 | } |
| 5970 | |
| 5971 | case TYPE_FUNCTION_NO_PROTO: { |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5972 | if (Record.size() != 7) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5973 | Error("incorrect encoding of no-proto function type"); |
| 5974 | return QualType(); |
| 5975 | } |
| 5976 | QualType ResultType = readType(*Loc.F, Record, Idx); |
| 5977 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5978 | (CallingConv)Record[4], Record[5], Record[6]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5979 | return Context.getFunctionNoProtoType(ResultType, Info); |
| 5980 | } |
| 5981 | |
| 5982 | case TYPE_FUNCTION_PROTO: { |
| 5983 | QualType ResultType = readType(*Loc.F, Record, Idx); |
| 5984 | |
| 5985 | FunctionProtoType::ExtProtoInfo EPI; |
| 5986 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
| 5987 | /*hasregparm*/ Record[2], |
| 5988 | /*regparm*/ Record[3], |
| 5989 | static_cast<CallingConv>(Record[4]), |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5990 | /*produces*/ Record[5], |
| 5991 | /*nocallersavedregs*/ Record[6]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5992 | |
Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 5993 | unsigned Idx = 7; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5994 | |
| 5995 | EPI.Variadic = Record[Idx++]; |
| 5996 | EPI.HasTrailingReturn = Record[Idx++]; |
| 5997 | EPI.TypeQuals = Record[Idx++]; |
| 5998 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 5999 | SmallVector<QualType, 8> ExceptionStorage; |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6000 | readExceptionSpec(*Loc.F, ExceptionStorage, EPI.ExceptionSpec, Record, Idx); |
Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 6001 | |
| 6002 | unsigned NumParams = Record[Idx++]; |
| 6003 | SmallVector<QualType, 16> ParamTypes; |
| 6004 | for (unsigned I = 0; I != NumParams; ++I) |
| 6005 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
| 6006 | |
John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 6007 | SmallVector<FunctionProtoType::ExtParameterInfo, 4> ExtParameterInfos; |
| 6008 | if (Idx != Record.size()) { |
| 6009 | for (unsigned I = 0; I != NumParams; ++I) |
| 6010 | ExtParameterInfos.push_back( |
| 6011 | FunctionProtoType::ExtParameterInfo |
| 6012 | ::getFromOpaqueValue(Record[Idx++])); |
| 6013 | EPI.ExtParameterInfos = ExtParameterInfos.data(); |
| 6014 | } |
| 6015 | |
| 6016 | assert(Idx == Record.size()); |
| 6017 | |
Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 6018 | return Context.getFunctionType(ResultType, ParamTypes, EPI); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6019 | } |
| 6020 | |
| 6021 | case TYPE_UNRESOLVED_USING: { |
| 6022 | unsigned Idx = 0; |
| 6023 | return Context.getTypeDeclType( |
| 6024 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 6025 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6026 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6027 | case TYPE_TYPEDEF: { |
| 6028 | if (Record.size() != 2) { |
| 6029 | Error("incorrect encoding of typedef type"); |
| 6030 | return QualType(); |
| 6031 | } |
| 6032 | unsigned Idx = 0; |
| 6033 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
| 6034 | QualType Canonical = readType(*Loc.F, Record, Idx); |
| 6035 | if (!Canonical.isNull()) |
| 6036 | Canonical = Context.getCanonicalType(Canonical); |
| 6037 | return Context.getTypedefType(Decl, Canonical); |
| 6038 | } |
| 6039 | |
| 6040 | case TYPE_TYPEOF_EXPR: |
| 6041 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
| 6042 | |
| 6043 | case TYPE_TYPEOF: { |
| 6044 | if (Record.size() != 1) { |
| 6045 | Error("incorrect encoding of typeof(type) in AST file"); |
| 6046 | return QualType(); |
| 6047 | } |
| 6048 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 6049 | return Context.getTypeOfType(UnderlyingType); |
| 6050 | } |
| 6051 | |
| 6052 | case TYPE_DECLTYPE: { |
| 6053 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 6054 | return Context.getDecltypeType(ReadExpr(*Loc.F), UnderlyingType); |
| 6055 | } |
| 6056 | |
| 6057 | case TYPE_UNARY_TRANSFORM: { |
| 6058 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 6059 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 6060 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
| 6061 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
| 6062 | } |
| 6063 | |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 6064 | case TYPE_AUTO: { |
| 6065 | QualType Deduced = readType(*Loc.F, Record, Idx); |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 6066 | AutoTypeKeyword Keyword = (AutoTypeKeyword)Record[Idx++]; |
Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 6067 | bool IsDependent = Deduced.isNull() ? Record[Idx++] : false; |
Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 6068 | return Context.getAutoType(Deduced, Keyword, IsDependent); |
Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 6069 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6070 | |
Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 6071 | case TYPE_DEDUCED_TEMPLATE_SPECIALIZATION: { |
| 6072 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
| 6073 | QualType Deduced = readType(*Loc.F, Record, Idx); |
| 6074 | bool IsDependent = Deduced.isNull() ? Record[Idx++] : false; |
| 6075 | return Context.getDeducedTemplateSpecializationType(Name, Deduced, |
| 6076 | IsDependent); |
| 6077 | } |
| 6078 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6079 | case TYPE_RECORD: { |
| 6080 | if (Record.size() != 2) { |
| 6081 | Error("incorrect encoding of record type"); |
| 6082 | return QualType(); |
| 6083 | } |
| 6084 | unsigned Idx = 0; |
| 6085 | bool IsDependent = Record[Idx++]; |
| 6086 | RecordDecl *RD = ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx); |
| 6087 | RD = cast_or_null<RecordDecl>(RD->getCanonicalDecl()); |
| 6088 | QualType T = Context.getRecordType(RD); |
| 6089 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 6090 | return T; |
| 6091 | } |
| 6092 | |
| 6093 | case TYPE_ENUM: { |
| 6094 | if (Record.size() != 2) { |
| 6095 | Error("incorrect encoding of enum type"); |
| 6096 | return QualType(); |
| 6097 | } |
| 6098 | unsigned Idx = 0; |
| 6099 | bool IsDependent = Record[Idx++]; |
| 6100 | QualType T |
| 6101 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
| 6102 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 6103 | return T; |
| 6104 | } |
| 6105 | |
| 6106 | case TYPE_ATTRIBUTED: { |
| 6107 | if (Record.size() != 3) { |
| 6108 | Error("incorrect encoding of attributed type"); |
| 6109 | return QualType(); |
| 6110 | } |
| 6111 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 6112 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
| 6113 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| 6114 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
| 6115 | } |
| 6116 | |
| 6117 | case TYPE_PAREN: { |
| 6118 | if (Record.size() != 1) { |
| 6119 | Error("incorrect encoding of paren type"); |
| 6120 | return QualType(); |
| 6121 | } |
| 6122 | QualType InnerType = readType(*Loc.F, Record, Idx); |
| 6123 | return Context.getParenType(InnerType); |
| 6124 | } |
| 6125 | |
| 6126 | case TYPE_PACK_EXPANSION: { |
| 6127 | if (Record.size() != 2) { |
| 6128 | Error("incorrect encoding of pack expansion type"); |
| 6129 | return QualType(); |
| 6130 | } |
| 6131 | QualType Pattern = readType(*Loc.F, Record, Idx); |
| 6132 | if (Pattern.isNull()) |
| 6133 | return QualType(); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 6134 | Optional<unsigned> NumExpansions; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6135 | if (Record[1]) |
| 6136 | NumExpansions = Record[1] - 1; |
| 6137 | return Context.getPackExpansionType(Pattern, NumExpansions); |
| 6138 | } |
| 6139 | |
| 6140 | case TYPE_ELABORATED: { |
| 6141 | unsigned Idx = 0; |
| 6142 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 6143 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
| 6144 | QualType NamedType = readType(*Loc.F, Record, Idx); |
| 6145 | return Context.getElaboratedType(Keyword, NNS, NamedType); |
| 6146 | } |
| 6147 | |
| 6148 | case TYPE_OBJC_INTERFACE: { |
| 6149 | unsigned Idx = 0; |
| 6150 | ObjCInterfaceDecl *ItfD |
| 6151 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
| 6152 | return Context.getObjCInterfaceType(ItfD->getCanonicalDecl()); |
| 6153 | } |
| 6154 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6155 | case TYPE_OBJC_TYPE_PARAM: { |
| 6156 | unsigned Idx = 0; |
| 6157 | ObjCTypeParamDecl *Decl |
| 6158 | = ReadDeclAs<ObjCTypeParamDecl>(*Loc.F, Record, Idx); |
| 6159 | unsigned NumProtos = Record[Idx++]; |
| 6160 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 6161 | for (unsigned I = 0; I != NumProtos; ++I) |
| 6162 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
| 6163 | return Context.getObjCTypeParamType(Decl, Protos); |
| 6164 | } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6165 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6166 | case TYPE_OBJC_OBJECT: { |
| 6167 | unsigned Idx = 0; |
| 6168 | QualType Base = readType(*Loc.F, Record, Idx); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6169 | unsigned NumTypeArgs = Record[Idx++]; |
| 6170 | SmallVector<QualType, 4> TypeArgs; |
| 6171 | for (unsigned I = 0; I != NumTypeArgs; ++I) |
| 6172 | TypeArgs.push_back(readType(*Loc.F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6173 | unsigned NumProtos = Record[Idx++]; |
| 6174 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 6175 | for (unsigned I = 0; I != NumProtos; ++I) |
| 6176 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 6177 | bool IsKindOf = Record[Idx++]; |
| 6178 | return Context.getObjCObjectType(Base, TypeArgs, Protos, IsKindOf); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6179 | } |
| 6180 | |
| 6181 | case TYPE_OBJC_OBJECT_POINTER: { |
| 6182 | unsigned Idx = 0; |
| 6183 | QualType Pointee = readType(*Loc.F, Record, Idx); |
| 6184 | return Context.getObjCObjectPointerType(Pointee); |
| 6185 | } |
| 6186 | |
| 6187 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
| 6188 | unsigned Idx = 0; |
| 6189 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 6190 | QualType Replacement = readType(*Loc.F, Record, Idx); |
Stephan Tolksdorf | e96f8b3 | 2014-03-15 10:23:27 +0000 | [diff] [blame] | 6191 | return Context.getSubstTemplateTypeParmType( |
| 6192 | cast<TemplateTypeParmType>(Parm), |
| 6193 | Context.getCanonicalType(Replacement)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6194 | } |
| 6195 | |
| 6196 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 6197 | unsigned Idx = 0; |
| 6198 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 6199 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 6200 | return Context.getSubstTemplateTypeParmPackType( |
| 6201 | cast<TemplateTypeParmType>(Parm), |
| 6202 | ArgPack); |
| 6203 | } |
| 6204 | |
| 6205 | case TYPE_INJECTED_CLASS_NAME: { |
| 6206 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
| 6207 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
| 6208 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
| 6209 | // for AST reading, too much interdependencies. |
Richard Smith | 6377f8f | 2014-10-21 21:15:18 +0000 | [diff] [blame] | 6210 | const Type *T = nullptr; |
| 6211 | for (auto *DI = D; DI; DI = DI->getPreviousDecl()) { |
| 6212 | if (const Type *Existing = DI->getTypeForDecl()) { |
| 6213 | T = Existing; |
| 6214 | break; |
| 6215 | } |
| 6216 | } |
| 6217 | if (!T) { |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 6218 | T = new (Context, TypeAlignment) InjectedClassNameType(D, TST); |
Richard Smith | 6377f8f | 2014-10-21 21:15:18 +0000 | [diff] [blame] | 6219 | for (auto *DI = D; DI; DI = DI->getPreviousDecl()) |
| 6220 | DI->setTypeForDecl(T); |
| 6221 | } |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 6222 | return QualType(T, 0); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6223 | } |
| 6224 | |
| 6225 | case TYPE_TEMPLATE_TYPE_PARM: { |
| 6226 | unsigned Idx = 0; |
| 6227 | unsigned Depth = Record[Idx++]; |
| 6228 | unsigned Index = Record[Idx++]; |
| 6229 | bool Pack = Record[Idx++]; |
| 6230 | TemplateTypeParmDecl *D |
| 6231 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
| 6232 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
| 6233 | } |
| 6234 | |
| 6235 | case TYPE_DEPENDENT_NAME: { |
| 6236 | unsigned Idx = 0; |
| 6237 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 6238 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 6239 | const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6240 | QualType Canon = readType(*Loc.F, Record, Idx); |
| 6241 | if (!Canon.isNull()) |
| 6242 | Canon = Context.getCanonicalType(Canon); |
| 6243 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
| 6244 | } |
| 6245 | |
| 6246 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
| 6247 | unsigned Idx = 0; |
| 6248 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| 6249 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 6250 | const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6251 | unsigned NumArgs = Record[Idx++]; |
| 6252 | SmallVector<TemplateArgument, 8> Args; |
| 6253 | Args.reserve(NumArgs); |
| 6254 | while (NumArgs--) |
| 6255 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
| 6256 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 6257 | Args); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6258 | } |
| 6259 | |
| 6260 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
| 6261 | unsigned Idx = 0; |
| 6262 | |
| 6263 | // ArrayType |
| 6264 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 6265 | ArrayType::ArraySizeModifier ASM |
| 6266 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| 6267 | unsigned IndexTypeQuals = Record[Idx++]; |
| 6268 | |
| 6269 | // DependentSizedArrayType |
| 6270 | Expr *NumElts = ReadExpr(*Loc.F); |
| 6271 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
| 6272 | |
| 6273 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 6274 | IndexTypeQuals, Brackets); |
| 6275 | } |
| 6276 | |
| 6277 | case TYPE_TEMPLATE_SPECIALIZATION: { |
| 6278 | unsigned Idx = 0; |
| 6279 | bool IsDependent = Record[Idx++]; |
| 6280 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
| 6281 | SmallVector<TemplateArgument, 8> Args; |
| 6282 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
| 6283 | QualType Underlying = readType(*Loc.F, Record, Idx); |
| 6284 | QualType T; |
| 6285 | if (Underlying.isNull()) |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 6286 | T = Context.getCanonicalTemplateSpecializationType(Name, Args); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6287 | else |
David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 6288 | T = Context.getTemplateSpecializationType(Name, Args, Underlying); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6289 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 6290 | return T; |
| 6291 | } |
| 6292 | |
| 6293 | case TYPE_ATOMIC: { |
| 6294 | if (Record.size() != 1) { |
| 6295 | Error("Incorrect encoding of atomic type"); |
| 6296 | return QualType(); |
| 6297 | } |
| 6298 | QualType ValueType = readType(*Loc.F, Record, Idx); |
| 6299 | return Context.getAtomicType(ValueType); |
| 6300 | } |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6301 | |
Joey Gouly | e3c85de | 2016-12-01 11:30:49 +0000 | [diff] [blame] | 6302 | case TYPE_PIPE: { |
| 6303 | if (Record.size() != 2) { |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6304 | Error("Incorrect encoding of pipe type"); |
| 6305 | return QualType(); |
| 6306 | } |
| 6307 | |
| 6308 | // Reading the pipe element type. |
| 6309 | QualType ElementType = readType(*Loc.F, Record, Idx); |
Joey Gouly | e3c85de | 2016-12-01 11:30:49 +0000 | [diff] [blame] | 6310 | unsigned ReadOnly = Record[1]; |
| 6311 | return Context.getPipeType(ElementType, ReadOnly); |
Joey Gouly | 5788b78 | 2016-11-18 14:10:54 +0000 | [diff] [blame] | 6312 | } |
| 6313 | |
Alex Lorenz | 00aee43 | 2017-03-22 10:04:48 +0000 | [diff] [blame] | 6314 | case TYPE_DEPENDENT_SIZED_EXT_VECTOR: { |
| 6315 | unsigned Idx = 0; |
| 6316 | |
| 6317 | // DependentSizedExtVectorType |
| 6318 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 6319 | Expr *SizeExpr = ReadExpr(*Loc.F); |
| 6320 | SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx); |
| 6321 | |
| 6322 | return Context.getDependentSizedExtVectorType(ElementType, SizeExpr, |
| 6323 | AttrLoc); |
| 6324 | } |
Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 6325 | |
| 6326 | case TYPE_DEPENDENT_ADDRESS_SPACE: { |
| 6327 | unsigned Idx = 0; |
| 6328 | |
| 6329 | // DependentAddressSpaceType |
| 6330 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 6331 | Expr *AddrSpaceExpr = ReadExpr(*Loc.F); |
| 6332 | SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx); |
| 6333 | |
| 6334 | return Context.getDependentAddressSpaceType(PointeeType, AddrSpaceExpr, |
| 6335 | AttrLoc); |
| 6336 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6337 | } |
| 6338 | llvm_unreachable("Invalid TypeCode!"); |
| 6339 | } |
| 6340 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6341 | void ASTReader::readExceptionSpec(ModuleFile &ModuleFile, |
| 6342 | SmallVectorImpl<QualType> &Exceptions, |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6343 | FunctionProtoType::ExceptionSpecInfo &ESI, |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6344 | const RecordData &Record, unsigned &Idx) { |
| 6345 | ExceptionSpecificationType EST = |
| 6346 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6347 | ESI.Type = EST; |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6348 | if (EST == EST_Dynamic) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6349 | for (unsigned I = 0, N = Record[Idx++]; I != N; ++I) |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6350 | Exceptions.push_back(readType(ModuleFile, Record, Idx)); |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6351 | ESI.Exceptions = Exceptions; |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6352 | } else if (EST == EST_ComputedNoexcept) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6353 | ESI.NoexceptExpr = ReadExpr(ModuleFile); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6354 | } else if (EST == EST_Uninstantiated) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6355 | ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
| 6356 | ESI.SourceTemplate = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6357 | } else if (EST == EST_Unevaluated) { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6358 | ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6359 | } |
| 6360 | } |
| 6361 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6362 | namespace clang { |
| 6363 | |
| 6364 | class TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6365 | ModuleFile *F; |
| 6366 | ASTReader *Reader; |
| 6367 | const ASTReader::RecordData &Record; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6368 | unsigned &Idx; |
| 6369 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6370 | SourceLocation ReadSourceLocation() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6371 | return Reader->ReadSourceLocation(*F, Record, Idx); |
| 6372 | } |
| 6373 | |
| 6374 | TypeSourceInfo *GetTypeSourceInfo() { |
| 6375 | return Reader->GetTypeSourceInfo(*F, Record, Idx); |
| 6376 | } |
| 6377 | |
| 6378 | NestedNameSpecifierLoc ReadNestedNameSpecifierLoc() { |
| 6379 | return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6380 | } |
| 6381 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6382 | public: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6383 | TypeLocReader(ModuleFile &F, ASTReader &Reader, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6384 | const ASTReader::RecordData &Record, unsigned &Idx) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6385 | : F(&F), Reader(&Reader), Record(Record), Idx(Idx) {} |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6386 | |
| 6387 | // We want compile-time assurance that we've enumerated all of |
| 6388 | // these, so unfortunately we have to declare them first, then |
| 6389 | // define them out-of-line. |
| 6390 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 6391 | #define TYPELOC(CLASS, PARENT) \ |
| 6392 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
| 6393 | #include "clang/AST/TypeLocNodes.def" |
| 6394 | |
| 6395 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 6396 | void VisitArrayTypeLoc(ArrayTypeLoc); |
| 6397 | }; |
| 6398 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6399 | } // namespace clang |
| 6400 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6401 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 6402 | // nothing to do |
| 6403 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6404 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6405 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6406 | TL.setBuiltinLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6407 | if (TL.needsExtraLocalData()) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6408 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 6409 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 6410 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 6411 | TL.setModeAttr(Record[Idx++]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6412 | } |
| 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::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6416 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6417 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6418 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6419 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6420 | TL.setStarLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6421 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6422 | |
Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 6423 | void TypeLocReader::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 6424 | // nothing to do |
| 6425 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6426 | |
Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 6427 | void TypeLocReader::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 6428 | // nothing to do |
| 6429 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6430 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6431 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6432 | TL.setCaretLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6433 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6434 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6435 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6436 | TL.setAmpLoc(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::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6440 | TL.setAmpAmpLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6441 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6442 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6443 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6444 | TL.setStarLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6445 | TL.setClassTInfo(GetTypeSourceInfo()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6446 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6447 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6448 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6449 | TL.setLBracketLoc(ReadSourceLocation()); |
| 6450 | TL.setRBracketLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6451 | if (Record[Idx++]) |
| 6452 | TL.setSizeExpr(Reader->ReadExpr(*F)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6453 | else |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6454 | TL.setSizeExpr(nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6455 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6456 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6457 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 6458 | VisitArrayTypeLoc(TL); |
| 6459 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6460 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6461 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 6462 | VisitArrayTypeLoc(TL); |
| 6463 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6464 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6465 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 6466 | VisitArrayTypeLoc(TL); |
| 6467 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6468 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6469 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 6470 | DependentSizedArrayTypeLoc TL) { |
| 6471 | VisitArrayTypeLoc(TL); |
| 6472 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6473 | |
Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 6474 | void TypeLocReader::VisitDependentAddressSpaceTypeLoc( |
| 6475 | DependentAddressSpaceTypeLoc TL) { |
| 6476 | |
| 6477 | TL.setAttrNameLoc(ReadSourceLocation()); |
| 6478 | SourceRange range; |
| 6479 | range.setBegin(ReadSourceLocation()); |
| 6480 | range.setEnd(ReadSourceLocation()); |
| 6481 | TL.setAttrOperandParensRange(range); |
| 6482 | TL.setAttrExprOperand(Reader->ReadExpr(*F)); |
| 6483 | } |
| 6484 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6485 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 6486 | DependentSizedExtVectorTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6487 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6488 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6489 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6490 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6491 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6492 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6493 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6494 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6495 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6496 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6497 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6498 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6499 | TL.setLocalRangeBegin(ReadSourceLocation()); |
| 6500 | TL.setLParenLoc(ReadSourceLocation()); |
| 6501 | TL.setRParenLoc(ReadSourceLocation()); |
Malcolm Parsons | a3220ce | 2017-01-12 16:11:28 +0000 | [diff] [blame] | 6502 | TL.setExceptionSpecRange(SourceRange(Reader->ReadSourceLocation(*F, Record, Idx), |
| 6503 | Reader->ReadSourceLocation(*F, Record, Idx))); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6504 | TL.setLocalRangeEnd(ReadSourceLocation()); |
Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 6505 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6506 | TL.setParam(i, Reader->ReadDeclAs<ParmVarDecl>(*F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6507 | } |
| 6508 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6509 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6510 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 6511 | VisitFunctionTypeLoc(TL); |
| 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::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 6515 | VisitFunctionTypeLoc(TL); |
| 6516 | } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6517 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6518 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6519 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6520 | } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6521 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6522 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6523 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6524 | } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6525 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6526 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6527 | TL.setTypeofLoc(ReadSourceLocation()); |
| 6528 | TL.setLParenLoc(ReadSourceLocation()); |
| 6529 | TL.setRParenLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6530 | } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6531 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6532 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6533 | TL.setTypeofLoc(ReadSourceLocation()); |
| 6534 | TL.setLParenLoc(ReadSourceLocation()); |
| 6535 | TL.setRParenLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6536 | TL.setUnderlyingTInfo(GetTypeSourceInfo()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6537 | } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6538 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6539 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6540 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6541 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6542 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6543 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6544 | TL.setKWLoc(ReadSourceLocation()); |
| 6545 | TL.setLParenLoc(ReadSourceLocation()); |
| 6546 | TL.setRParenLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6547 | TL.setUnderlyingTInfo(GetTypeSourceInfo()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6548 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6549 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6550 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6551 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6552 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6553 | |
Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 6554 | void TypeLocReader::VisitDeducedTemplateSpecializationTypeLoc( |
| 6555 | DeducedTemplateSpecializationTypeLoc TL) { |
| 6556 | TL.setTemplateNameLoc(ReadSourceLocation()); |
| 6557 | } |
| 6558 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6559 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6560 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6561 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6562 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6563 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6564 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6565 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6566 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6567 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6568 | TL.setAttrNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6569 | if (TL.hasAttrOperand()) { |
| 6570 | SourceRange range; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6571 | range.setBegin(ReadSourceLocation()); |
| 6572 | range.setEnd(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6573 | TL.setAttrOperandParensRange(range); |
| 6574 | } |
| 6575 | if (TL.hasAttrExprOperand()) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6576 | if (Record[Idx++]) |
| 6577 | TL.setAttrExprOperand(Reader->ReadExpr(*F)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6578 | else |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6579 | TL.setAttrExprOperand(nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6580 | } else if (TL.hasAttrEnumOperand()) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6581 | TL.setAttrEnumOperandLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6582 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6583 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6584 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6585 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6586 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6587 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6588 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 6589 | SubstTemplateTypeParmTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6590 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6591 | } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6592 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6593 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 6594 | SubstTemplateTypeParmPackTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6595 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6596 | } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6597 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6598 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 6599 | TemplateSpecializationTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6600 | TL.setTemplateKeywordLoc(ReadSourceLocation()); |
| 6601 | TL.setTemplateNameLoc(ReadSourceLocation()); |
| 6602 | TL.setLAngleLoc(ReadSourceLocation()); |
| 6603 | TL.setRAngleLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6604 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6605 | TL.setArgLocInfo( |
| 6606 | i, |
| 6607 | Reader->GetTemplateArgumentLocInfo( |
| 6608 | *F, TL.getTypePtr()->getArg(i).getKind(), Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6609 | } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6610 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6611 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6612 | TL.setLParenLoc(ReadSourceLocation()); |
| 6613 | TL.setRParenLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6614 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6615 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6616 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6617 | TL.setElaboratedKeywordLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6618 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6619 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6620 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6621 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6622 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6623 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6624 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6625 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6626 | TL.setElaboratedKeywordLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6627 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6628 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6629 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6630 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6631 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 6632 | DependentTemplateSpecializationTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6633 | TL.setElaboratedKeywordLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6634 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6635 | TL.setTemplateKeywordLoc(ReadSourceLocation()); |
| 6636 | TL.setTemplateNameLoc(ReadSourceLocation()); |
| 6637 | TL.setLAngleLoc(ReadSourceLocation()); |
| 6638 | TL.setRAngleLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6639 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6640 | TL.setArgLocInfo( |
| 6641 | I, |
| 6642 | Reader->GetTemplateArgumentLocInfo( |
| 6643 | *F, TL.getTypePtr()->getArg(I).getKind(), Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6644 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6645 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6646 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6647 | TL.setEllipsisLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6648 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6649 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6650 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6651 | TL.setNameLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6652 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6653 | |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6654 | void TypeLocReader::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { |
| 6655 | if (TL.getNumProtocols()) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6656 | TL.setProtocolLAngleLoc(ReadSourceLocation()); |
| 6657 | TL.setProtocolRAngleLoc(ReadSourceLocation()); |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6658 | } |
| 6659 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6660 | TL.setProtocolLoc(i, ReadSourceLocation()); |
Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6661 | } |
| 6662 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6663 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6664 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6665 | TL.setTypeArgsLAngleLoc(ReadSourceLocation()); |
| 6666 | TL.setTypeArgsRAngleLoc(ReadSourceLocation()); |
Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6667 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6668 | TL.setTypeArgTInfo(i, GetTypeSourceInfo()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6669 | TL.setProtocolLAngleLoc(ReadSourceLocation()); |
| 6670 | TL.setProtocolRAngleLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6671 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6672 | TL.setProtocolLoc(i, ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6673 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6674 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6675 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6676 | TL.setStarLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6677 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6678 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6679 | void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6680 | TL.setKWLoc(ReadSourceLocation()); |
| 6681 | TL.setLParenLoc(ReadSourceLocation()); |
| 6682 | TL.setRParenLoc(ReadSourceLocation()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6683 | } |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6684 | |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6685 | void TypeLocReader::VisitPipeTypeLoc(PipeTypeLoc TL) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6686 | TL.setKWLoc(ReadSourceLocation()); |
Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6687 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6688 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6689 | TypeSourceInfo * |
| 6690 | ASTReader::GetTypeSourceInfo(ModuleFile &F, const ASTReader::RecordData &Record, |
| 6691 | unsigned &Idx) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6692 | QualType InfoTy = readType(F, Record, Idx); |
| 6693 | if (InfoTy.isNull()) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6694 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6695 | |
| 6696 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6697 | TypeLocReader TLR(F, *this, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6698 | for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc()) |
| 6699 | TLR.Visit(TL); |
| 6700 | return TInfo; |
| 6701 | } |
| 6702 | |
| 6703 | QualType ASTReader::GetType(TypeID ID) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 6704 | assert(ContextObj && "reading type with no AST context"); |
| 6705 | ASTContext &Context = *ContextObj; |
| 6706 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6707 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 6708 | unsigned Index = ID >> Qualifiers::FastWidth; |
| 6709 | |
| 6710 | if (Index < NUM_PREDEF_TYPE_IDS) { |
| 6711 | QualType T; |
| 6712 | switch ((PredefinedTypeIDs)Index) { |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6713 | case PREDEF_TYPE_NULL_ID: |
| 6714 | return QualType(); |
| 6715 | case PREDEF_TYPE_VOID_ID: |
| 6716 | T = Context.VoidTy; |
| 6717 | break; |
| 6718 | case PREDEF_TYPE_BOOL_ID: |
| 6719 | T = Context.BoolTy; |
| 6720 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6721 | case PREDEF_TYPE_CHAR_U_ID: |
| 6722 | case PREDEF_TYPE_CHAR_S_ID: |
| 6723 | // FIXME: Check that the signedness of CharTy is correct! |
| 6724 | T = Context.CharTy; |
| 6725 | break; |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6726 | case PREDEF_TYPE_UCHAR_ID: |
| 6727 | T = Context.UnsignedCharTy; |
| 6728 | break; |
| 6729 | case PREDEF_TYPE_USHORT_ID: |
| 6730 | T = Context.UnsignedShortTy; |
| 6731 | break; |
| 6732 | case PREDEF_TYPE_UINT_ID: |
| 6733 | T = Context.UnsignedIntTy; |
| 6734 | break; |
| 6735 | case PREDEF_TYPE_ULONG_ID: |
| 6736 | T = Context.UnsignedLongTy; |
| 6737 | break; |
| 6738 | case PREDEF_TYPE_ULONGLONG_ID: |
| 6739 | T = Context.UnsignedLongLongTy; |
| 6740 | break; |
| 6741 | case PREDEF_TYPE_UINT128_ID: |
| 6742 | T = Context.UnsignedInt128Ty; |
| 6743 | break; |
| 6744 | case PREDEF_TYPE_SCHAR_ID: |
| 6745 | T = Context.SignedCharTy; |
| 6746 | break; |
| 6747 | case PREDEF_TYPE_WCHAR_ID: |
| 6748 | T = Context.WCharTy; |
| 6749 | break; |
| 6750 | case PREDEF_TYPE_SHORT_ID: |
| 6751 | T = Context.ShortTy; |
| 6752 | break; |
| 6753 | case PREDEF_TYPE_INT_ID: |
| 6754 | T = Context.IntTy; |
| 6755 | break; |
| 6756 | case PREDEF_TYPE_LONG_ID: |
| 6757 | T = Context.LongTy; |
| 6758 | break; |
| 6759 | case PREDEF_TYPE_LONGLONG_ID: |
| 6760 | T = Context.LongLongTy; |
| 6761 | break; |
| 6762 | case PREDEF_TYPE_INT128_ID: |
| 6763 | T = Context.Int128Ty; |
| 6764 | break; |
| 6765 | case PREDEF_TYPE_HALF_ID: |
| 6766 | T = Context.HalfTy; |
| 6767 | break; |
| 6768 | case PREDEF_TYPE_FLOAT_ID: |
| 6769 | T = Context.FloatTy; |
| 6770 | break; |
| 6771 | case PREDEF_TYPE_DOUBLE_ID: |
| 6772 | T = Context.DoubleTy; |
| 6773 | break; |
| 6774 | case PREDEF_TYPE_LONGDOUBLE_ID: |
| 6775 | T = Context.LongDoubleTy; |
| 6776 | break; |
Sjoerd Meijer | cc623ad | 2017-09-08 15:15:00 +0000 | [diff] [blame] | 6777 | case PREDEF_TYPE_FLOAT16_ID: |
| 6778 | T = Context.Float16Ty; |
| 6779 | break; |
Nemanja Ivanovic | bb1ea2d | 2016-05-09 08:52:33 +0000 | [diff] [blame] | 6780 | case PREDEF_TYPE_FLOAT128_ID: |
| 6781 | T = Context.Float128Ty; |
| 6782 | break; |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6783 | case PREDEF_TYPE_OVERLOAD_ID: |
| 6784 | T = Context.OverloadTy; |
| 6785 | break; |
| 6786 | case PREDEF_TYPE_BOUND_MEMBER: |
| 6787 | T = Context.BoundMemberTy; |
| 6788 | break; |
| 6789 | case PREDEF_TYPE_PSEUDO_OBJECT: |
| 6790 | T = Context.PseudoObjectTy; |
| 6791 | break; |
| 6792 | case PREDEF_TYPE_DEPENDENT_ID: |
| 6793 | T = Context.DependentTy; |
| 6794 | break; |
| 6795 | case PREDEF_TYPE_UNKNOWN_ANY: |
| 6796 | T = Context.UnknownAnyTy; |
| 6797 | break; |
| 6798 | case PREDEF_TYPE_NULLPTR_ID: |
| 6799 | T = Context.NullPtrTy; |
| 6800 | break; |
| 6801 | case PREDEF_TYPE_CHAR16_ID: |
| 6802 | T = Context.Char16Ty; |
| 6803 | break; |
| 6804 | case PREDEF_TYPE_CHAR32_ID: |
| 6805 | T = Context.Char32Ty; |
| 6806 | break; |
| 6807 | case PREDEF_TYPE_OBJC_ID: |
| 6808 | T = Context.ObjCBuiltinIdTy; |
| 6809 | break; |
| 6810 | case PREDEF_TYPE_OBJC_CLASS: |
| 6811 | T = Context.ObjCBuiltinClassTy; |
| 6812 | break; |
| 6813 | case PREDEF_TYPE_OBJC_SEL: |
| 6814 | T = Context.ObjCBuiltinSelTy; |
| 6815 | break; |
Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 6816 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 6817 | case PREDEF_TYPE_##Id##_ID: \ |
| 6818 | T = Context.SingletonId; \ |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6819 | break; |
Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 6820 | #include "clang/Basic/OpenCLImageTypes.def" |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6821 | case PREDEF_TYPE_SAMPLER_ID: |
| 6822 | T = Context.OCLSamplerTy; |
| 6823 | break; |
| 6824 | case PREDEF_TYPE_EVENT_ID: |
| 6825 | T = Context.OCLEventTy; |
| 6826 | break; |
Alexey Bader | 9c8453f | 2015-09-15 11:18:52 +0000 | [diff] [blame] | 6827 | case PREDEF_TYPE_CLK_EVENT_ID: |
| 6828 | T = Context.OCLClkEventTy; |
| 6829 | break; |
| 6830 | case PREDEF_TYPE_QUEUE_ID: |
| 6831 | T = Context.OCLQueueTy; |
| 6832 | break; |
Alexey Bader | 9c8453f | 2015-09-15 11:18:52 +0000 | [diff] [blame] | 6833 | case PREDEF_TYPE_RESERVE_ID_ID: |
| 6834 | T = Context.OCLReserveIDTy; |
| 6835 | break; |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6836 | case PREDEF_TYPE_AUTO_DEDUCT: |
| 6837 | T = Context.getAutoDeductType(); |
| 6838 | break; |
Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6839 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
| 6840 | T = Context.getAutoRRefDeductType(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6841 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6842 | case PREDEF_TYPE_ARC_UNBRIDGED_CAST: |
| 6843 | T = Context.ARCUnbridgedCastTy; |
| 6844 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6845 | case PREDEF_TYPE_BUILTIN_FN: |
| 6846 | T = Context.BuiltinFnTy; |
| 6847 | break; |
Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 6848 | case PREDEF_TYPE_OMP_ARRAY_SECTION: |
| 6849 | T = Context.OMPArraySectionTy; |
| 6850 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6851 | } |
| 6852 | |
| 6853 | assert(!T.isNull() && "Unknown predefined type"); |
| 6854 | return T.withFastQualifiers(FastQuals); |
| 6855 | } |
| 6856 | |
| 6857 | Index -= NUM_PREDEF_TYPE_IDS; |
| 6858 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
| 6859 | if (TypesLoaded[Index].isNull()) { |
| 6860 | TypesLoaded[Index] = readTypeRecord(Index); |
| 6861 | if (TypesLoaded[Index].isNull()) |
| 6862 | return QualType(); |
| 6863 | |
| 6864 | TypesLoaded[Index]->setFromAST(); |
| 6865 | if (DeserializationListener) |
| 6866 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
| 6867 | TypesLoaded[Index]); |
| 6868 | } |
| 6869 | |
| 6870 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
| 6871 | } |
| 6872 | |
| 6873 | QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) { |
| 6874 | return GetType(getGlobalTypeID(F, LocalID)); |
| 6875 | } |
| 6876 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6877 | serialization::TypeID |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6878 | ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const { |
| 6879 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 6880 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6881 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6882 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 6883 | return LocalID; |
| 6884 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 6885 | if (!F.ModuleOffsetMap.empty()) |
| 6886 | ReadModuleOffsetMap(F); |
| 6887 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6888 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 6889 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 6890 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6891 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6892 | unsigned GlobalIndex = LocalIndex + I->second; |
| 6893 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 6894 | } |
| 6895 | |
| 6896 | TemplateArgumentLocInfo |
| 6897 | ASTReader::GetTemplateArgumentLocInfo(ModuleFile &F, |
| 6898 | TemplateArgument::ArgKind Kind, |
| 6899 | const RecordData &Record, |
| 6900 | unsigned &Index) { |
| 6901 | switch (Kind) { |
| 6902 | case TemplateArgument::Expression: |
| 6903 | return ReadExpr(F); |
| 6904 | case TemplateArgument::Type: |
| 6905 | return GetTypeSourceInfo(F, Record, Index); |
| 6906 | case TemplateArgument::Template: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6907 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6908 | Index); |
| 6909 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
| 6910 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
| 6911 | SourceLocation()); |
| 6912 | } |
| 6913 | case TemplateArgument::TemplateExpansion: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6914 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6915 | Index); |
| 6916 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
| 6917 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6918 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6919 | EllipsisLoc); |
| 6920 | } |
| 6921 | case TemplateArgument::Null: |
| 6922 | case TemplateArgument::Integral: |
| 6923 | case TemplateArgument::Declaration: |
| 6924 | case TemplateArgument::NullPtr: |
| 6925 | case TemplateArgument::Pack: |
| 6926 | // FIXME: Is this right? |
| 6927 | return TemplateArgumentLocInfo(); |
| 6928 | } |
| 6929 | llvm_unreachable("unexpected template argument loc"); |
| 6930 | } |
| 6931 | |
| 6932 | TemplateArgumentLoc |
| 6933 | ASTReader::ReadTemplateArgumentLoc(ModuleFile &F, |
| 6934 | const RecordData &Record, unsigned &Index) { |
| 6935 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
| 6936 | |
| 6937 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 6938 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 6939 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 6940 | } |
| 6941 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
| 6942 | Record, Index)); |
| 6943 | } |
| 6944 | |
Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 6945 | const ASTTemplateArgumentListInfo* |
| 6946 | ASTReader::ReadASTTemplateArgumentListInfo(ModuleFile &F, |
| 6947 | const RecordData &Record, |
| 6948 | unsigned &Index) { |
| 6949 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Index); |
| 6950 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Index); |
| 6951 | unsigned NumArgsAsWritten = Record[Index++]; |
| 6952 | TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); |
| 6953 | for (unsigned i = 0; i != NumArgsAsWritten; ++i) |
| 6954 | TemplArgsInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Index)); |
| 6955 | return ASTTemplateArgumentListInfo::Create(getContext(), TemplArgsInfo); |
| 6956 | } |
| 6957 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6958 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
| 6959 | return GetDecl(ID); |
| 6960 | } |
| 6961 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6962 | void ASTReader::CompleteRedeclChain(const Decl *D) { |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 6963 | if (NumCurrentElementsDeserializing) { |
| 6964 | // We arrange to not care about the complete redeclaration chain while we're |
| 6965 | // deserializing. Just remember that the AST has marked this one as complete |
| 6966 | // but that it's not actually complete yet, so we know we still need to |
| 6967 | // complete it later. |
| 6968 | PendingIncompleteDeclChains.push_back(const_cast<Decl*>(D)); |
| 6969 | return; |
| 6970 | } |
| 6971 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6972 | const DeclContext *DC = D->getDeclContext()->getRedeclContext(); |
| 6973 | |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6974 | // If this is a named declaration, complete it by looking it up |
| 6975 | // within its context. |
| 6976 | // |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 6977 | // FIXME: Merging a function definition should merge |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6978 | // all mergeable entities within it. |
| 6979 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC) || |
| 6980 | isa<CXXRecordDecl>(DC) || isa<EnumDecl>(DC)) { |
| 6981 | if (DeclarationName Name = cast<NamedDecl>(D)->getDeclName()) { |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 6982 | if (!getContext().getLangOpts().CPlusPlus && |
| 6983 | isa<TranslationUnitDecl>(DC)) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6984 | // 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] | 6985 | // the identifier instead. (For C++ modules, we don't store decls |
| 6986 | // in the serialized identifier table, so we do the lookup in the TU.) |
| 6987 | auto *II = Name.getAsIdentifierInfo(); |
| 6988 | assert(II && "non-identifier name in C?"); |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 6989 | if (II->isOutOfDate()) |
| 6990 | updateOutOfDateIdentifier(*II); |
| 6991 | } else |
| 6992 | DC->lookup(Name); |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 6993 | } else if (needsAnonymousDeclarationNumber(cast<NamedDecl>(D))) { |
Richard Smith | 3cb1572 | 2015-08-05 22:41:45 +0000 | [diff] [blame] | 6994 | // Find all declarations of this kind from the relevant context. |
| 6995 | for (auto *DCDecl : cast<Decl>(D->getLexicalDeclContext())->redecls()) { |
| 6996 | auto *DC = cast<DeclContext>(DCDecl); |
| 6997 | SmallVector<Decl*, 8> Decls; |
| 6998 | FindExternalLexicalDecls( |
| 6999 | DC, [&](Decl::Kind K) { return K == D->getKind(); }, Decls); |
| 7000 | } |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 7001 | } |
| 7002 | } |
Richard Smith | 5089542 | 2015-01-31 03:04:55 +0000 | [diff] [blame] | 7003 | |
| 7004 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D)) |
| 7005 | CTSD->getSpecializedTemplate()->LoadLazySpecializations(); |
| 7006 | if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) |
| 7007 | VTSD->getSpecializedTemplate()->LoadLazySpecializations(); |
| 7008 | if (auto *FD = dyn_cast<FunctionDecl>(D)) { |
| 7009 | if (auto *Template = FD->getPrimaryTemplate()) |
| 7010 | Template->LoadLazySpecializations(); |
| 7011 | } |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 7012 | } |
| 7013 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 7014 | CXXCtorInitializer ** |
| 7015 | ASTReader::GetExternalCXXCtorInitializers(uint64_t Offset) { |
| 7016 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 7017 | BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
| 7018 | SavedStreamPosition SavedPosition(Cursor); |
| 7019 | Cursor.JumpToBit(Loc.Offset); |
| 7020 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 7021 | |
| 7022 | RecordData Record; |
| 7023 | unsigned Code = Cursor.ReadCode(); |
| 7024 | unsigned RecCode = Cursor.readRecord(Code, Record); |
| 7025 | if (RecCode != DECL_CXX_CTOR_INITIALIZERS) { |
| 7026 | Error("malformed AST file: missing C++ ctor initializers"); |
| 7027 | return nullptr; |
| 7028 | } |
| 7029 | |
| 7030 | unsigned Idx = 0; |
| 7031 | return ReadCXXCtorInitializers(*Loc.F, Record, Idx); |
| 7032 | } |
| 7033 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7034 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 7035 | assert(ContextObj && "reading base specifiers with no AST context"); |
| 7036 | ASTContext &Context = *ContextObj; |
| 7037 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7038 | RecordLocation Loc = getLocalBitOffset(Offset); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 7039 | BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7040 | SavedStreamPosition SavedPosition(Cursor); |
| 7041 | Cursor.JumpToBit(Loc.Offset); |
| 7042 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 7043 | RecordData Record; |
| 7044 | unsigned Code = Cursor.ReadCode(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 7045 | unsigned RecCode = Cursor.readRecord(Code, Record); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7046 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7047 | Error("malformed AST file: missing C++ base specifiers"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7048 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7049 | } |
| 7050 | |
| 7051 | unsigned Idx = 0; |
| 7052 | unsigned NumBases = Record[Idx++]; |
| 7053 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 7054 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 7055 | for (unsigned I = 0; I != NumBases; ++I) |
| 7056 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
| 7057 | return Bases; |
| 7058 | } |
| 7059 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7060 | serialization::DeclID |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7061 | ASTReader::getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const { |
| 7062 | if (LocalID < NUM_PREDEF_DECL_IDS) |
| 7063 | return LocalID; |
| 7064 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 7065 | if (!F.ModuleOffsetMap.empty()) |
| 7066 | ReadModuleOffsetMap(F); |
| 7067 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7068 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 7069 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
| 7070 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7071 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7072 | return LocalID + I->second; |
| 7073 | } |
| 7074 | |
| 7075 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
| 7076 | ModuleFile &M) const { |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7077 | // Predefined decls aren't from any module. |
| 7078 | if (ID < NUM_PREDEF_DECL_IDS) |
| 7079 | return false; |
| 7080 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7081 | return ID - NUM_PREDEF_DECL_IDS >= M.BaseDeclID && |
Richard Smith | bcda1a9 | 2015-07-12 23:51:20 +0000 | [diff] [blame] | 7082 | ID - NUM_PREDEF_DECL_IDS < M.BaseDeclID + M.LocalNumDecls; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7083 | } |
| 7084 | |
Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 7085 | ModuleFile *ASTReader::getOwningModuleFile(const Decl *D) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7086 | if (!D->isFromASTFile()) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7087 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7088 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID()); |
| 7089 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 7090 | return I->second; |
| 7091 | } |
| 7092 | |
| 7093 | SourceLocation ASTReader::getSourceLocationForDeclID(GlobalDeclID ID) { |
| 7094 | if (ID < NUM_PREDEF_DECL_IDS) |
| 7095 | return SourceLocation(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7096 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7097 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 7098 | |
| 7099 | if (Index > DeclsLoaded.size()) { |
| 7100 | Error("declaration ID out-of-range for AST file"); |
| 7101 | return SourceLocation(); |
| 7102 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7103 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7104 | if (Decl *D = DeclsLoaded[Index]) |
| 7105 | return D->getLocation(); |
| 7106 | |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 7107 | SourceLocation Loc; |
| 7108 | DeclCursorForID(ID, Loc); |
| 7109 | return Loc; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7110 | } |
| 7111 | |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7112 | static Decl *getPredefinedDecl(ASTContext &Context, PredefinedDeclIDs ID) { |
| 7113 | switch (ID) { |
| 7114 | case PREDEF_DECL_NULL_ID: |
| 7115 | return nullptr; |
| 7116 | |
| 7117 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
| 7118 | return Context.getTranslationUnitDecl(); |
| 7119 | |
| 7120 | case PREDEF_DECL_OBJC_ID_ID: |
| 7121 | return Context.getObjCIdDecl(); |
| 7122 | |
| 7123 | case PREDEF_DECL_OBJC_SEL_ID: |
| 7124 | return Context.getObjCSelDecl(); |
| 7125 | |
| 7126 | case PREDEF_DECL_OBJC_CLASS_ID: |
| 7127 | return Context.getObjCClassDecl(); |
| 7128 | |
| 7129 | case PREDEF_DECL_OBJC_PROTOCOL_ID: |
| 7130 | return Context.getObjCProtocolDecl(); |
| 7131 | |
| 7132 | case PREDEF_DECL_INT_128_ID: |
| 7133 | return Context.getInt128Decl(); |
| 7134 | |
| 7135 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
| 7136 | return Context.getUInt128Decl(); |
| 7137 | |
| 7138 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
| 7139 | return Context.getObjCInstanceTypeDecl(); |
| 7140 | |
| 7141 | case PREDEF_DECL_BUILTIN_VA_LIST_ID: |
| 7142 | return Context.getBuiltinVaListDecl(); |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 7143 | |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 7144 | case PREDEF_DECL_VA_LIST_TAG: |
| 7145 | return Context.getVaListTagDecl(); |
| 7146 | |
Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 7147 | case PREDEF_DECL_BUILTIN_MS_VA_LIST_ID: |
| 7148 | return Context.getBuiltinMSVaListDecl(); |
| 7149 | |
Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 7150 | case PREDEF_DECL_EXTERN_C_CONTEXT_ID: |
| 7151 | return Context.getExternCContextDecl(); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 7152 | |
| 7153 | case PREDEF_DECL_MAKE_INTEGER_SEQ_ID: |
| 7154 | return Context.getMakeIntegerSeqDecl(); |
Quentin Colombet | 043406b | 2016-02-03 22:41:00 +0000 | [diff] [blame] | 7155 | |
| 7156 | case PREDEF_DECL_CF_CONSTANT_STRING_ID: |
| 7157 | return Context.getCFConstantStringDecl(); |
Ben Langmuir | f541674 | 2016-02-04 00:55:24 +0000 | [diff] [blame] | 7158 | |
| 7159 | case PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID: |
| 7160 | return Context.getCFConstantStringTagDecl(); |
Eric Fiselier | 6ad6855 | 2016-07-01 01:24:09 +0000 | [diff] [blame] | 7161 | |
| 7162 | case PREDEF_DECL_TYPE_PACK_ELEMENT_ID: |
| 7163 | return Context.getTypePackElementDecl(); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7164 | } |
Yaron Keren | 322bdad | 2015-03-06 07:49:14 +0000 | [diff] [blame] | 7165 | llvm_unreachable("PredefinedDeclIDs unknown enum value"); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7166 | } |
| 7167 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7168 | Decl *ASTReader::GetExistingDecl(DeclID ID) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 7169 | assert(ContextObj && "reading decl with no AST context"); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7170 | if (ID < NUM_PREDEF_DECL_IDS) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 7171 | Decl *D = getPredefinedDecl(*ContextObj, (PredefinedDeclIDs)ID); |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7172 | if (D) { |
| 7173 | // Track that we have merged the declaration with ID \p ID into the |
| 7174 | // pre-existing predefined declaration \p D. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 7175 | auto &Merged = KeyDecls[D->getCanonicalDecl()]; |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7176 | if (Merged.empty()) |
| 7177 | Merged.push_back(ID); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7178 | } |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7179 | return D; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7180 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7181 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7182 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 7183 | |
| 7184 | if (Index >= DeclsLoaded.size()) { |
| 7185 | assert(0 && "declaration ID out-of-range for AST file"); |
| 7186 | Error("declaration ID out-of-range for AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7187 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7188 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7189 | |
| 7190 | return DeclsLoaded[Index]; |
| 7191 | } |
| 7192 | |
| 7193 | Decl *ASTReader::GetDecl(DeclID ID) { |
| 7194 | if (ID < NUM_PREDEF_DECL_IDS) |
| 7195 | return GetExistingDecl(ID); |
| 7196 | |
| 7197 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 7198 | |
| 7199 | if (Index >= DeclsLoaded.size()) { |
| 7200 | assert(0 && "declaration ID out-of-range for AST file"); |
| 7201 | Error("declaration ID out-of-range for AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7202 | return nullptr; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7203 | } |
| 7204 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7205 | if (!DeclsLoaded[Index]) { |
| 7206 | ReadDeclRecord(ID); |
| 7207 | if (DeserializationListener) |
| 7208 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 7209 | } |
| 7210 | |
| 7211 | return DeclsLoaded[Index]; |
| 7212 | } |
| 7213 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7214 | DeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile &M, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7215 | DeclID GlobalID) { |
| 7216 | if (GlobalID < NUM_PREDEF_DECL_IDS) |
| 7217 | return GlobalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7218 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7219 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID); |
| 7220 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 7221 | ModuleFile *Owner = I->second; |
| 7222 | |
| 7223 | llvm::DenseMap<ModuleFile *, serialization::DeclID>::iterator Pos |
| 7224 | = M.GlobalToLocalDeclIDs.find(Owner); |
| 7225 | if (Pos == M.GlobalToLocalDeclIDs.end()) |
| 7226 | return 0; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7227 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7228 | return GlobalID - Owner->BaseDeclID + Pos->second; |
| 7229 | } |
| 7230 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7231 | serialization::DeclID ASTReader::ReadDeclID(ModuleFile &F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7232 | const RecordData &Record, |
| 7233 | unsigned &Idx) { |
| 7234 | if (Idx >= Record.size()) { |
| 7235 | Error("Corrupted AST file"); |
| 7236 | return 0; |
| 7237 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7238 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7239 | return getGlobalDeclID(F, Record[Idx++]); |
| 7240 | } |
| 7241 | |
| 7242 | /// \brief Resolve the offset of a statement into a statement. |
| 7243 | /// |
| 7244 | /// This operation will read a new statement from the external |
| 7245 | /// source each time it is called, and is meant to be used via a |
| 7246 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
| 7247 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
| 7248 | // Switch case IDs are per Decl. |
| 7249 | ClearSwitchCaseIDs(); |
| 7250 | |
| 7251 | // Offset here is a global offset across the entire chain. |
| 7252 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 7253 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
David Blaikie | 9fd16f8 | 2017-03-08 23:57:08 +0000 | [diff] [blame] | 7254 | assert(NumCurrentElementsDeserializing == 0 && |
| 7255 | "should not be called while already deserializing"); |
| 7256 | Deserializing D(this); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7257 | return ReadStmtFromStream(*Loc.F); |
| 7258 | } |
| 7259 | |
Richard Smith | 3cb1572 | 2015-08-05 22:41:45 +0000 | [diff] [blame] | 7260 | void ASTReader::FindExternalLexicalDecls( |
| 7261 | const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, |
| 7262 | SmallVectorImpl<Decl *> &Decls) { |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7263 | bool PredefsVisited[NUM_PREDEF_DECL_IDS] = {}; |
| 7264 | |
Richard Smith | 9ccdd93 | 2015-08-06 22:14:12 +0000 | [diff] [blame] | 7265 | auto Visit = [&] (ModuleFile *M, LexicalContents LexicalDecls) { |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7266 | assert(LexicalDecls.size() % 2 == 0 && "expected an even number of entries"); |
| 7267 | for (int I = 0, N = LexicalDecls.size(); I != N; I += 2) { |
| 7268 | auto K = (Decl::Kind)+LexicalDecls[I]; |
| 7269 | if (!IsKindWeWant(K)) |
| 7270 | continue; |
| 7271 | |
| 7272 | auto ID = (serialization::DeclID)+LexicalDecls[I + 1]; |
| 7273 | |
| 7274 | // Don't add predefined declarations to the lexical context more |
| 7275 | // than once. |
| 7276 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 7277 | if (PredefsVisited[ID]) |
| 7278 | continue; |
| 7279 | |
| 7280 | PredefsVisited[ID] = true; |
| 7281 | } |
| 7282 | |
| 7283 | if (Decl *D = GetLocalDecl(*M, ID)) { |
Richard Smith | 2317a3e | 2015-08-11 21:21:20 +0000 | [diff] [blame] | 7284 | assert(D->getKind() == K && "wrong kind for lexical decl"); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7285 | if (!DC->isDeclInLexicalTraversal(D)) |
| 7286 | Decls.push_back(D); |
| 7287 | } |
| 7288 | } |
| 7289 | }; |
| 7290 | |
| 7291 | if (isa<TranslationUnitDecl>(DC)) { |
| 7292 | for (auto Lexical : TULexicalDecls) |
| 7293 | Visit(Lexical.first, Lexical.second); |
| 7294 | } else { |
| 7295 | auto I = LexicalDecls.find(DC); |
| 7296 | if (I != LexicalDecls.end()) |
Richard Smith | 9c9173d | 2015-08-11 22:00:24 +0000 | [diff] [blame] | 7297 | Visit(I->second.first, I->second.second); |
Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7298 | } |
| 7299 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7300 | ++NumLexicalDeclContextsRead; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7301 | } |
| 7302 | |
| 7303 | namespace { |
| 7304 | |
| 7305 | class DeclIDComp { |
| 7306 | ASTReader &Reader; |
| 7307 | ModuleFile &Mod; |
| 7308 | |
| 7309 | public: |
| 7310 | DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {} |
| 7311 | |
| 7312 | bool operator()(LocalDeclID L, LocalDeclID R) const { |
| 7313 | SourceLocation LHS = getLocation(L); |
| 7314 | SourceLocation RHS = getLocation(R); |
| 7315 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7316 | } |
| 7317 | |
| 7318 | bool operator()(SourceLocation LHS, LocalDeclID R) const { |
| 7319 | SourceLocation RHS = getLocation(R); |
| 7320 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7321 | } |
| 7322 | |
| 7323 | bool operator()(LocalDeclID L, SourceLocation RHS) const { |
| 7324 | SourceLocation LHS = getLocation(L); |
| 7325 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7326 | } |
| 7327 | |
| 7328 | SourceLocation getLocation(LocalDeclID ID) const { |
| 7329 | return Reader.getSourceManager().getFileLoc( |
| 7330 | Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID))); |
| 7331 | } |
| 7332 | }; |
| 7333 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7334 | } // namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7335 | |
| 7336 | void ASTReader::FindFileRegionDecls(FileID File, |
| 7337 | unsigned Offset, unsigned Length, |
| 7338 | SmallVectorImpl<Decl *> &Decls) { |
| 7339 | SourceManager &SM = getSourceManager(); |
| 7340 | |
| 7341 | llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File); |
| 7342 | if (I == FileDeclIDs.end()) |
| 7343 | return; |
| 7344 | |
| 7345 | FileDeclsInfo &DInfo = I->second; |
| 7346 | if (DInfo.Decls.empty()) |
| 7347 | return; |
| 7348 | |
| 7349 | SourceLocation |
| 7350 | BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset); |
| 7351 | SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length); |
| 7352 | |
| 7353 | DeclIDComp DIDComp(*this, *DInfo.Mod); |
| 7354 | ArrayRef<serialization::LocalDeclID>::iterator |
| 7355 | BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 7356 | BeginLoc, DIDComp); |
| 7357 | if (BeginIt != DInfo.Decls.begin()) |
| 7358 | --BeginIt; |
| 7359 | |
| 7360 | // If we are pointing at a top-level decl inside an objc container, we need |
| 7361 | // to backtrack until we find it otherwise we will fail to report that the |
| 7362 | // region overlaps with an objc container. |
| 7363 | while (BeginIt != DInfo.Decls.begin() && |
| 7364 | GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt)) |
| 7365 | ->isTopLevelDeclInObjCContainer()) |
| 7366 | --BeginIt; |
| 7367 | |
| 7368 | ArrayRef<serialization::LocalDeclID>::iterator |
| 7369 | EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 7370 | EndLoc, DIDComp); |
| 7371 | if (EndIt != DInfo.Decls.end()) |
| 7372 | ++EndIt; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7373 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7374 | for (ArrayRef<serialization::LocalDeclID>::iterator |
| 7375 | DIt = BeginIt; DIt != EndIt; ++DIt) |
| 7376 | Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt))); |
| 7377 | } |
| 7378 | |
Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 7379 | bool |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7380 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
| 7381 | DeclarationName Name) { |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7382 | assert(DC->hasExternalVisibleStorage() && DC == DC->getPrimaryContext() && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7383 | "DeclContext has no visible decls in storage"); |
| 7384 | if (!Name) |
Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 7385 | return false; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7386 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7387 | auto It = Lookups.find(DC); |
| 7388 | if (It == Lookups.end()) |
| 7389 | return false; |
| 7390 | |
Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 7391 | Deserializing LookupResults(this); |
| 7392 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7393 | // Load the list of declarations. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7394 | SmallVector<NamedDecl *, 64> Decls; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7395 | for (DeclID ID : It->second.Table.find(Name)) { |
| 7396 | NamedDecl *ND = cast<NamedDecl>(GetDecl(ID)); |
| 7397 | if (ND->getDeclName() == Name) |
| 7398 | Decls.push_back(ND); |
| 7399 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7400 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7401 | ++NumVisibleDeclContextsRead; |
| 7402 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 7403 | return !Decls.empty(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7404 | } |
| 7405 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7406 | void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) { |
| 7407 | if (!DC->hasExternalVisibleStorage()) |
| 7408 | return; |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7409 | |
| 7410 | auto It = Lookups.find(DC); |
| 7411 | assert(It != Lookups.end() && |
| 7412 | "have external visible storage but no lookup tables"); |
| 7413 | |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 7414 | DeclsMap Decls; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7415 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7416 | for (DeclID ID : It->second.Table.findAll()) { |
| 7417 | NamedDecl *ND = cast<NamedDecl>(GetDecl(ID)); |
| 7418 | Decls[ND->getDeclName()].push_back(ND); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7419 | } |
| 7420 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7421 | ++NumVisibleDeclContextsRead; |
| 7422 | |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 7423 | for (DeclsMap::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7424 | SetExternalVisibleDeclsForName(DC, I->first, I->second); |
| 7425 | } |
| 7426 | const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false); |
| 7427 | } |
| 7428 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7429 | const serialization::reader::DeclContextLookupTable * |
| 7430 | ASTReader::getLoadedLookupTables(DeclContext *Primary) const { |
| 7431 | auto I = Lookups.find(Primary); |
| 7432 | return I == Lookups.end() ? nullptr : &I->second; |
| 7433 | } |
| 7434 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7435 | /// \brief Under non-PCH compilation the consumer receives the objc methods |
| 7436 | /// before receiving the implementation, and codegen depends on this. |
| 7437 | /// We simulate this by deserializing and passing to consumer the methods of the |
| 7438 | /// implementation before passing the deserialized implementation decl. |
| 7439 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 7440 | ASTConsumer *Consumer) { |
| 7441 | assert(ImplD && Consumer); |
| 7442 | |
Aaron Ballman | aff18c0 | 2014-03-13 19:03:34 +0000 | [diff] [blame] | 7443 | for (auto *I : ImplD->methods()) |
| 7444 | Consumer->HandleInterestingDecl(DeclGroupRef(I)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7445 | |
| 7446 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 7447 | } |
| 7448 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7449 | void ASTReader::PassInterestingDeclToConsumer(Decl *D) { |
| 7450 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 7451 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 7452 | else |
| 7453 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
| 7454 | } |
| 7455 | |
| 7456 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
| 7457 | this->Consumer = Consumer; |
| 7458 | |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 7459 | if (Consumer) |
| 7460 | PassInterestingDeclsToConsumer(); |
Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 7461 | |
| 7462 | if (DeserializationListener) |
| 7463 | DeserializationListener->ReaderInitialized(this); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7464 | } |
| 7465 | |
| 7466 | void ASTReader::PrintStats() { |
| 7467 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
| 7468 | |
| 7469 | unsigned NumTypesLoaded |
| 7470 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
| 7471 | QualType()); |
| 7472 | unsigned NumDeclsLoaded |
| 7473 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7474 | (Decl *)nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7475 | unsigned NumIdentifiersLoaded |
| 7476 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 7477 | IdentifiersLoaded.end(), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7478 | (IdentifierInfo *)nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7479 | unsigned NumMacrosLoaded |
| 7480 | = MacrosLoaded.size() - std::count(MacrosLoaded.begin(), |
| 7481 | MacrosLoaded.end(), |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7482 | (MacroInfo *)nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7483 | unsigned NumSelectorsLoaded |
| 7484 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 7485 | SelectorsLoaded.end(), |
| 7486 | Selector()); |
| 7487 | |
| 7488 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
| 7489 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 7490 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 7491 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
| 7492 | if (!TypesLoaded.empty()) |
| 7493 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
| 7494 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 7495 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 7496 | if (!DeclsLoaded.empty()) |
| 7497 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
| 7498 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 7499 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
| 7500 | if (!IdentifiersLoaded.empty()) |
| 7501 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
| 7502 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 7503 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
| 7504 | if (!MacrosLoaded.empty()) |
| 7505 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 7506 | NumMacrosLoaded, (unsigned)MacrosLoaded.size(), |
| 7507 | ((float)NumMacrosLoaded/MacrosLoaded.size() * 100)); |
| 7508 | if (!SelectorsLoaded.empty()) |
| 7509 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
| 7510 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 7511 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
| 7512 | if (TotalNumStatements) |
| 7513 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 7514 | NumStatementsRead, TotalNumStatements, |
| 7515 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 7516 | if (TotalNumMacros) |
| 7517 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 7518 | NumMacrosRead, TotalNumMacros, |
| 7519 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 7520 | if (TotalLexicalDeclContexts) |
| 7521 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 7522 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 7523 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 7524 | * 100)); |
| 7525 | if (TotalVisibleDeclContexts) |
| 7526 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 7527 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 7528 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 7529 | * 100)); |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7530 | if (TotalNumMethodPoolEntries) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7531 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
| 7532 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 7533 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
| 7534 | * 100)); |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7535 | if (NumMethodPoolLookups) |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7536 | std::fprintf(stderr, " %u/%u method pool lookups succeeded (%f%%)\n", |
| 7537 | NumMethodPoolHits, NumMethodPoolLookups, |
| 7538 | ((float)NumMethodPoolHits/NumMethodPoolLookups * 100.0)); |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7539 | if (NumMethodPoolTableLookups) |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7540 | std::fprintf(stderr, " %u/%u method pool table lookups succeeded (%f%%)\n", |
| 7541 | NumMethodPoolTableHits, NumMethodPoolTableLookups, |
| 7542 | ((float)NumMethodPoolTableHits/NumMethodPoolTableLookups |
| 7543 | * 100.0)); |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7544 | if (NumIdentifierLookupHits) |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 7545 | std::fprintf(stderr, |
| 7546 | " %u / %u identifier table lookups succeeded (%f%%)\n", |
| 7547 | NumIdentifierLookupHits, NumIdentifierLookups, |
| 7548 | (double)NumIdentifierLookupHits*100.0/NumIdentifierLookups); |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 7549 | |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 7550 | if (GlobalIndex) { |
| 7551 | std::fprintf(stderr, "\n"); |
| 7552 | GlobalIndex->printStats(); |
| 7553 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7554 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7555 | std::fprintf(stderr, "\n"); |
| 7556 | dump(); |
| 7557 | std::fprintf(stderr, "\n"); |
| 7558 | } |
| 7559 | |
| 7560 | template<typename Key, typename ModuleFile, unsigned InitialCapacity> |
Vassil Vassilev | b271068 | 2017-03-02 18:13:19 +0000 | [diff] [blame] | 7561 | LLVM_DUMP_METHOD static void |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7562 | dumpModuleIDMap(StringRef Name, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7563 | const ContinuousRangeMap<Key, ModuleFile *, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7564 | InitialCapacity> &Map) { |
| 7565 | if (Map.begin() == Map.end()) |
| 7566 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7567 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7568 | using MapType = ContinuousRangeMap<Key, ModuleFile *, InitialCapacity>; |
| 7569 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7570 | llvm::errs() << Name << ":\n"; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7571 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7572 | I != IEnd; ++I) { |
| 7573 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 7574 | << "\n"; |
| 7575 | } |
| 7576 | } |
| 7577 | |
Yaron Keren | cdae941 | 2016-01-29 19:38:18 +0000 | [diff] [blame] | 7578 | LLVM_DUMP_METHOD void ASTReader::dump() { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7579 | llvm::errs() << "*** PCH/ModuleFile Remappings:\n"; |
| 7580 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
| 7581 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
| 7582 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
| 7583 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
| 7584 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
| 7585 | dumpModuleIDMap("Global macro map", GlobalMacroMap); |
| 7586 | dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap); |
| 7587 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7588 | dumpModuleIDMap("Global preprocessed entity map", |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7589 | GlobalPreprocessedEntityMap); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7590 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7591 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 7592 | for (ModuleFile &M : ModuleMgr) |
| 7593 | M.dump(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7594 | } |
| 7595 | |
| 7596 | /// Return the amount of memory used by memory buffers, breaking down |
| 7597 | /// by heap-backed versus mmap'ed memory. |
| 7598 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 7599 | for (ModuleFile &I : ModuleMgr) { |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 7600 | if (llvm::MemoryBuffer *buf = I.Buffer) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7601 | size_t bytes = buf->getBufferSize(); |
| 7602 | switch (buf->getBufferKind()) { |
| 7603 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 7604 | sizes.malloc_bytes += bytes; |
| 7605 | break; |
| 7606 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 7607 | sizes.mmap_bytes += bytes; |
| 7608 | break; |
| 7609 | } |
| 7610 | } |
| 7611 | } |
| 7612 | } |
| 7613 | |
| 7614 | void ASTReader::InitializeSema(Sema &S) { |
| 7615 | SemaObj = &S; |
| 7616 | S.addExternalSource(this); |
| 7617 | |
| 7618 | // Makes sure any declarations that were deserialized "too early" |
| 7619 | // still get added to the identifier's declaration chains. |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7620 | for (uint64_t ID : PreloadedDeclIDs) { |
| 7621 | NamedDecl *D = cast<NamedDecl>(GetDecl(ID)); |
| 7622 | pushExternalDeclIntoScope(D, D->getDeclName()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7623 | } |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7624 | PreloadedDeclIDs.clear(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7625 | |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7626 | // FIXME: What happens if these are changed by a module import? |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7627 | if (!FPPragmaOptions.empty()) { |
| 7628 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 7629 | SemaObj->FPFeatures = FPOptions(FPPragmaOptions[0]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7630 | } |
| 7631 | |
Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 7632 | SemaObj->OpenCLFeatures.copy(OpenCLExtensions); |
| 7633 | SemaObj->OpenCLTypeExtMap = OpenCLTypeExtMap; |
| 7634 | SemaObj->OpenCLDeclExtMap = OpenCLDeclExtMap; |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7635 | |
| 7636 | UpdateSema(); |
| 7637 | } |
| 7638 | |
| 7639 | void ASTReader::UpdateSema() { |
| 7640 | assert(SemaObj && "no Sema to update"); |
| 7641 | |
| 7642 | // Load the offsets of the declarations that Sema references. |
| 7643 | // They will be lazily deserialized when needed. |
| 7644 | if (!SemaDeclRefs.empty()) { |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 7645 | assert(SemaDeclRefs.size() % 3 == 0); |
| 7646 | for (unsigned I = 0; I != SemaDeclRefs.size(); I += 3) { |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7647 | if (!SemaObj->StdNamespace) |
| 7648 | SemaObj->StdNamespace = SemaDeclRefs[I]; |
| 7649 | if (!SemaObj->StdBadAlloc) |
| 7650 | SemaObj->StdBadAlloc = SemaDeclRefs[I+1]; |
Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 7651 | if (!SemaObj->StdAlignValT) |
| 7652 | SemaObj->StdAlignValT = SemaDeclRefs[I+2]; |
Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7653 | } |
| 7654 | SemaDeclRefs.clear(); |
| 7655 | } |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 7656 | |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 7657 | // Update the state of pragmas. Use the same API as if we had encountered the |
| 7658 | // pragma in the source. |
Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 7659 | if(OptimizeOffPragmaLocation.isValid()) |
| 7660 | SemaObj->ActOnPragmaOptimize(/* IsOn = */ false, OptimizeOffPragmaLocation); |
Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 7661 | if (PragmaMSStructState != -1) |
| 7662 | SemaObj->ActOnPragmaMSStruct((PragmaMSStructKind)PragmaMSStructState); |
Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 7663 | if (PointersToMembersPragmaLocation.isValid()) { |
| 7664 | SemaObj->ActOnPragmaMSPointersToMembers( |
| 7665 | (LangOptions::PragmaMSPointersToMembersKind) |
| 7666 | PragmaMSPointersToMembersState, |
| 7667 | PointersToMembersPragmaLocation); |
| 7668 | } |
Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 7669 | SemaObj->ForceCUDAHostDeviceDepth = ForceCUDAHostDeviceDepth; |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 7670 | |
| 7671 | if (PragmaPackCurrentValue) { |
| 7672 | // The bottom of the stack might have a default value. It must be adjusted |
| 7673 | // to the current value to ensure that the packing state is preserved after |
| 7674 | // popping entries that were included/imported from a PCH/module. |
| 7675 | bool DropFirst = false; |
| 7676 | if (!PragmaPackStack.empty() && |
| 7677 | PragmaPackStack.front().Location.isInvalid()) { |
| 7678 | assert(PragmaPackStack.front().Value == SemaObj->PackStack.DefaultValue && |
| 7679 | "Expected a default alignment value"); |
| 7680 | SemaObj->PackStack.Stack.emplace_back( |
| 7681 | PragmaPackStack.front().SlotLabel, SemaObj->PackStack.CurrentValue, |
Alex Lorenz | 45b4014 | 2017-07-28 14:41:21 +0000 | [diff] [blame] | 7682 | SemaObj->PackStack.CurrentPragmaLocation, |
| 7683 | PragmaPackStack.front().PushLocation); |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 7684 | DropFirst = true; |
| 7685 | } |
| 7686 | for (const auto &Entry : |
| 7687 | llvm::makeArrayRef(PragmaPackStack).drop_front(DropFirst ? 1 : 0)) |
| 7688 | SemaObj->PackStack.Stack.emplace_back(Entry.SlotLabel, Entry.Value, |
Alex Lorenz | 45b4014 | 2017-07-28 14:41:21 +0000 | [diff] [blame] | 7689 | Entry.Location, Entry.PushLocation); |
Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 7690 | if (PragmaPackCurrentLocation.isInvalid()) { |
| 7691 | assert(*PragmaPackCurrentValue == SemaObj->PackStack.DefaultValue && |
| 7692 | "Expected a default alignment value"); |
| 7693 | // Keep the current values. |
| 7694 | } else { |
| 7695 | SemaObj->PackStack.CurrentValue = *PragmaPackCurrentValue; |
| 7696 | SemaObj->PackStack.CurrentPragmaLocation = PragmaPackCurrentLocation; |
| 7697 | } |
| 7698 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7699 | } |
| 7700 | |
Richard Smith | a8d5b6a | 2015-07-17 19:51:03 +0000 | [diff] [blame] | 7701 | IdentifierInfo *ASTReader::get(StringRef Name) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7702 | // Note that we are loading an identifier. |
| 7703 | Deserializing AnIdentifier(this); |
Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 7704 | |
Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 7705 | IdentifierLookupVisitor Visitor(Name, /*PriorGeneration=*/0, |
Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 7706 | NumIdentifierLookups, |
| 7707 | NumIdentifierLookupHits); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7708 | |
| 7709 | // We don't need to do identifier table lookups in C++ modules (we preload |
| 7710 | // all interesting declarations, and don't need to use the scope for name |
| 7711 | // lookups). Perform the lookup in PCH files, though, since we don't build |
| 7712 | // 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] | 7713 | if (PP.getLangOpts().CPlusPlus) { |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7714 | for (auto F : ModuleMgr.pch_modules()) |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7715 | if (Visitor(*F)) |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7716 | break; |
| 7717 | } else { |
| 7718 | // If there is a global index, look there first to determine which modules |
| 7719 | // provably do not have any results for this identifier. |
| 7720 | GlobalModuleIndex::HitSet Hits; |
| 7721 | GlobalModuleIndex::HitSet *HitsPtr = nullptr; |
| 7722 | if (!loadGlobalIndex()) { |
| 7723 | if (GlobalIndex->lookupIdentifier(Name, Hits)) { |
| 7724 | HitsPtr = &Hits; |
| 7725 | } |
| 7726 | } |
| 7727 | |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7728 | ModuleMgr.visit(Visitor, HitsPtr); |
Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7729 | } |
| 7730 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7731 | IdentifierInfo *II = Visitor.getIdentifierInfo(); |
| 7732 | markIdentifierUpToDate(II); |
| 7733 | return II; |
| 7734 | } |
| 7735 | |
| 7736 | namespace clang { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7737 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7738 | /// \brief An identifier-lookup iterator that enumerates all of the |
| 7739 | /// identifiers stored within a set of AST files. |
| 7740 | class ASTIdentifierIterator : public IdentifierIterator { |
| 7741 | /// \brief The AST reader whose identifiers are being enumerated. |
| 7742 | const ASTReader &Reader; |
| 7743 | |
| 7744 | /// \brief The current index into the chain of AST files stored in |
| 7745 | /// the AST reader. |
| 7746 | unsigned Index; |
| 7747 | |
| 7748 | /// \brief The current position within the identifier lookup table |
| 7749 | /// of the current AST file. |
| 7750 | ASTIdentifierLookupTable::key_iterator Current; |
| 7751 | |
| 7752 | /// \brief The end position within the identifier lookup table of |
| 7753 | /// the current AST file. |
| 7754 | ASTIdentifierLookupTable::key_iterator End; |
| 7755 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7756 | /// \brief Whether to skip any modules in the ASTReader. |
| 7757 | bool SkipModules; |
| 7758 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7759 | public: |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7760 | explicit ASTIdentifierIterator(const ASTReader &Reader, |
| 7761 | bool SkipModules = false); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7762 | |
Craig Topper | 3e89dfe | 2014-03-13 02:13:41 +0000 | [diff] [blame] | 7763 | StringRef Next() override; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7764 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7765 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7766 | } // namespace clang |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7767 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7768 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader, |
| 7769 | bool SkipModules) |
| 7770 | : Reader(Reader), Index(Reader.ModuleMgr.size()), SkipModules(SkipModules) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7771 | } |
| 7772 | |
| 7773 | StringRef ASTIdentifierIterator::Next() { |
| 7774 | while (Current == End) { |
| 7775 | // If we have exhausted all of our AST files, we're done. |
| 7776 | if (Index == 0) |
| 7777 | return StringRef(); |
| 7778 | |
| 7779 | --Index; |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7780 | ModuleFile &F = Reader.ModuleMgr[Index]; |
| 7781 | if (SkipModules && F.isModule()) |
| 7782 | continue; |
| 7783 | |
| 7784 | ASTIdentifierLookupTable *IdTable = |
| 7785 | (ASTIdentifierLookupTable *)F.IdentifierLookupTable; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7786 | Current = IdTable->key_begin(); |
| 7787 | End = IdTable->key_end(); |
| 7788 | } |
| 7789 | |
| 7790 | // We have any identifiers remaining in the current AST file; return |
| 7791 | // the next one. |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 7792 | StringRef Result = *Current; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7793 | ++Current; |
Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 7794 | return Result; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7795 | } |
| 7796 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7797 | namespace { |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7798 | |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7799 | /// A utility for appending two IdentifierIterators. |
| 7800 | class ChainedIdentifierIterator : public IdentifierIterator { |
| 7801 | std::unique_ptr<IdentifierIterator> Current; |
| 7802 | std::unique_ptr<IdentifierIterator> Queued; |
| 7803 | |
| 7804 | public: |
| 7805 | ChainedIdentifierIterator(std::unique_ptr<IdentifierIterator> First, |
| 7806 | std::unique_ptr<IdentifierIterator> Second) |
| 7807 | : Current(std::move(First)), Queued(std::move(Second)) {} |
| 7808 | |
| 7809 | StringRef Next() override { |
| 7810 | if (!Current) |
| 7811 | return StringRef(); |
| 7812 | |
| 7813 | StringRef result = Current->Next(); |
| 7814 | if (!result.empty()) |
| 7815 | return result; |
| 7816 | |
| 7817 | // Try the queued iterator, which may itself be empty. |
| 7818 | Current.reset(); |
| 7819 | std::swap(Current, Queued); |
| 7820 | return Next(); |
| 7821 | } |
| 7822 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7823 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7824 | } // namespace |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7825 | |
Argyrios Kyrtzidis | 9aca3c6 | 2013-04-17 22:10:55 +0000 | [diff] [blame] | 7826 | IdentifierIterator *ASTReader::getIdentifiers() { |
Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7827 | if (!loadGlobalIndex()) { |
| 7828 | std::unique_ptr<IdentifierIterator> ReaderIter( |
| 7829 | new ASTIdentifierIterator(*this, /*SkipModules=*/true)); |
| 7830 | std::unique_ptr<IdentifierIterator> ModulesIter( |
| 7831 | GlobalIndex->createIdentifierIterator()); |
| 7832 | return new ChainedIdentifierIterator(std::move(ReaderIter), |
| 7833 | std::move(ModulesIter)); |
| 7834 | } |
Argyrios Kyrtzidis | 9aca3c6 | 2013-04-17 22:10:55 +0000 | [diff] [blame] | 7835 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7836 | return new ASTIdentifierIterator(*this); |
| 7837 | } |
| 7838 | |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7839 | namespace clang { |
| 7840 | namespace serialization { |
| 7841 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7842 | class ReadMethodPoolVisitor { |
| 7843 | ASTReader &Reader; |
| 7844 | Selector Sel; |
| 7845 | unsigned PriorGeneration; |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7846 | unsigned InstanceBits = 0; |
| 7847 | unsigned FactoryBits = 0; |
| 7848 | bool InstanceHasMoreThanOneDecl = false; |
| 7849 | bool FactoryHasMoreThanOneDecl = false; |
Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 7850 | SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 7851 | SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7852 | |
| 7853 | public: |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 7854 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7855 | unsigned PriorGeneration) |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7856 | : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration) {} |
Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 7857 | |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7858 | bool operator()(ModuleFile &M) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7859 | if (!M.SelectorLookupTable) |
| 7860 | return false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7861 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7862 | // If we've already searched this module file, skip it now. |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7863 | if (M.Generation <= PriorGeneration) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7864 | return true; |
| 7865 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7866 | ++Reader.NumMethodPoolTableLookups; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7867 | ASTSelectorLookupTable *PoolTable |
| 7868 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7869 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7870 | if (Pos == PoolTable->end()) |
| 7871 | return false; |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7872 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7873 | ++Reader.NumMethodPoolTableHits; |
| 7874 | ++Reader.NumSelectorsRead; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7875 | // FIXME: Not quite happy with the statistics here. We probably should |
| 7876 | // disable this tracking when called via LoadSelector. |
| 7877 | // Also, should entries without methods count as misses? |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7878 | ++Reader.NumMethodPoolEntriesRead; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7879 | ASTSelectorLookupTrait::data_type Data = *Pos; |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7880 | if (Reader.DeserializationListener) |
| 7881 | Reader.DeserializationListener->SelectorRead(Data.ID, Sel); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7882 | |
Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 7883 | InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 7884 | FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 7885 | InstanceBits = Data.InstanceBits; |
| 7886 | FactoryBits = Data.FactoryBits; |
| 7887 | InstanceHasMoreThanOneDecl = Data.InstanceHasMoreThanOneDecl; |
| 7888 | FactoryHasMoreThanOneDecl = Data.FactoryHasMoreThanOneDecl; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7889 | return true; |
| 7890 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7891 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7892 | /// \brief Retrieve the instance methods found by this visitor. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7893 | ArrayRef<ObjCMethodDecl *> getInstanceMethods() const { |
| 7894 | return InstanceMethods; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7895 | } |
| 7896 | |
| 7897 | /// \brief Retrieve the instance methods found by this visitor. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7898 | ArrayRef<ObjCMethodDecl *> getFactoryMethods() const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7899 | return FactoryMethods; |
| 7900 | } |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7901 | |
| 7902 | unsigned getInstanceBits() const { return InstanceBits; } |
| 7903 | unsigned getFactoryBits() const { return FactoryBits; } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7904 | |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7905 | bool instanceHasMoreThanOneDecl() const { |
| 7906 | return InstanceHasMoreThanOneDecl; |
| 7907 | } |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7908 | |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7909 | bool factoryHasMoreThanOneDecl() const { return FactoryHasMoreThanOneDecl; } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7910 | }; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7911 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7912 | } // namespace serialization |
| 7913 | } // namespace clang |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7914 | |
| 7915 | /// \brief Add the given set of methods to the method list. |
| 7916 | static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods, |
| 7917 | ObjCMethodList &List) { |
| 7918 | for (unsigned I = 0, N = Methods.size(); I != N; ++I) { |
| 7919 | S.addMethodToGlobalList(&List, Methods[I]); |
| 7920 | } |
| 7921 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7922 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7923 | void ASTReader::ReadMethodPool(Selector Sel) { |
| 7924 | // Get the selector generation and update it to the current generation. |
| 7925 | unsigned &Generation = SelectorGeneration[Sel]; |
| 7926 | unsigned PriorGeneration = Generation; |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 7927 | Generation = getGeneration(); |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 7928 | SelectorOutOfDate[Sel] = false; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7929 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7930 | // Search for methods defined with this selector. |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7931 | ++NumMethodPoolLookups; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7932 | ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7933 | ModuleMgr.visit(Visitor); |
| 7934 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7935 | if (Visitor.getInstanceMethods().empty() && |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7936 | Visitor.getFactoryMethods().empty()) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7937 | return; |
Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7938 | |
| 7939 | ++NumMethodPoolHits; |
| 7940 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7941 | if (!getSema()) |
| 7942 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7943 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7944 | Sema &S = *getSema(); |
| 7945 | Sema::GlobalMethodPool::iterator Pos |
| 7946 | = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first; |
Ben Langmuir | a0c32e9 | 2015-01-12 19:27:00 +0000 | [diff] [blame] | 7947 | |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7948 | Pos->second.first.setBits(Visitor.getInstanceBits()); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7949 | Pos->second.first.setHasMoreThanOneDecl(Visitor.instanceHasMoreThanOneDecl()); |
Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 7950 | Pos->second.second.setBits(Visitor.getFactoryBits()); |
Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 7951 | Pos->second.second.setHasMoreThanOneDecl(Visitor.factoryHasMoreThanOneDecl()); |
Ben Langmuir | a0c32e9 | 2015-01-12 19:27:00 +0000 | [diff] [blame] | 7952 | |
| 7953 | // Add methods to the global pool *after* setting hasMoreThanOneDecl, since |
| 7954 | // when building a module we keep every method individually and may need to |
| 7955 | // update hasMoreThanOneDecl as we add the methods. |
| 7956 | addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first); |
| 7957 | addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7958 | } |
| 7959 | |
Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 7960 | void ASTReader::updateOutOfDateSelector(Selector Sel) { |
| 7961 | if (SelectorOutOfDate[Sel]) |
| 7962 | ReadMethodPool(Sel); |
| 7963 | } |
| 7964 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7965 | void ASTReader::ReadKnownNamespaces( |
| 7966 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
| 7967 | Namespaces.clear(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7968 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7969 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7970 | if (NamespaceDecl *Namespace |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7971 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 7972 | Namespaces.push_back(Namespace); |
| 7973 | } |
| 7974 | } |
| 7975 | |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 7976 | void ASTReader::ReadUndefinedButUsed( |
Richard Smith | d6a04d7 | 2016-03-25 21:49:43 +0000 | [diff] [blame] | 7977 | llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) { |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 7978 | for (unsigned Idx = 0, N = UndefinedButUsed.size(); Idx != N;) { |
| 7979 | NamedDecl *D = cast<NamedDecl>(GetDecl(UndefinedButUsed[Idx++])); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 7980 | SourceLocation Loc = |
Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 7981 | SourceLocation::getFromRawEncoding(UndefinedButUsed[Idx++]); |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 7982 | Undefined.insert(std::make_pair(D, Loc)); |
| 7983 | } |
| 7984 | } |
Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 7985 | |
Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 7986 | void ASTReader::ReadMismatchingDeleteExpressions(llvm::MapVector< |
| 7987 | FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> & |
| 7988 | Exprs) { |
| 7989 | for (unsigned Idx = 0, N = DelayedDeleteExprs.size(); Idx != N;) { |
| 7990 | FieldDecl *FD = cast<FieldDecl>(GetDecl(DelayedDeleteExprs[Idx++])); |
| 7991 | uint64_t Count = DelayedDeleteExprs[Idx++]; |
| 7992 | for (uint64_t C = 0; C < Count; ++C) { |
| 7993 | SourceLocation DeleteLoc = |
| 7994 | SourceLocation::getFromRawEncoding(DelayedDeleteExprs[Idx++]); |
| 7995 | const bool IsArrayForm = DelayedDeleteExprs[Idx++]; |
| 7996 | Exprs[FD].push_back(std::make_pair(DeleteLoc, IsArrayForm)); |
| 7997 | } |
| 7998 | } |
| 7999 | } |
| 8000 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8001 | void ASTReader::ReadTentativeDefinitions( |
| 8002 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 8003 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 8004 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 8005 | if (Var) |
| 8006 | TentativeDefs.push_back(Var); |
| 8007 | } |
| 8008 | TentativeDefinitions.clear(); |
| 8009 | } |
| 8010 | |
| 8011 | void ASTReader::ReadUnusedFileScopedDecls( |
| 8012 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 8013 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 8014 | DeclaratorDecl *D |
| 8015 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 8016 | if (D) |
| 8017 | Decls.push_back(D); |
| 8018 | } |
| 8019 | UnusedFileScopedDecls.clear(); |
| 8020 | } |
| 8021 | |
| 8022 | void ASTReader::ReadDelegatingConstructors( |
| 8023 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 8024 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 8025 | CXXConstructorDecl *D |
| 8026 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 8027 | if (D) |
| 8028 | Decls.push_back(D); |
| 8029 | } |
| 8030 | DelegatingCtorDecls.clear(); |
| 8031 | } |
| 8032 | |
| 8033 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 8034 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 8035 | TypedefNameDecl *D |
| 8036 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 8037 | if (D) |
| 8038 | Decls.push_back(D); |
| 8039 | } |
| 8040 | ExtVectorDecls.clear(); |
| 8041 | } |
| 8042 | |
Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 8043 | void ASTReader::ReadUnusedLocalTypedefNameCandidates( |
| 8044 | llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) { |
| 8045 | for (unsigned I = 0, N = UnusedLocalTypedefNameCandidates.size(); I != N; |
| 8046 | ++I) { |
| 8047 | TypedefNameDecl *D = dyn_cast_or_null<TypedefNameDecl>( |
| 8048 | GetDecl(UnusedLocalTypedefNameCandidates[I])); |
| 8049 | if (D) |
| 8050 | Decls.insert(D); |
| 8051 | } |
| 8052 | UnusedLocalTypedefNameCandidates.clear(); |
| 8053 | } |
| 8054 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8055 | void ASTReader::ReadReferencedSelectors( |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 8056 | SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8057 | if (ReferencedSelectorsData.empty()) |
| 8058 | return; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8059 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8060 | // If there are @selector references added them to its pool. This is for |
| 8061 | // implementation of -Wselector. |
| 8062 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 8063 | unsigned I = 0; |
| 8064 | while (I < DataSize) { |
| 8065 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 8066 | SourceLocation SelLoc |
| 8067 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 8068 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 8069 | } |
| 8070 | ReferencedSelectorsData.clear(); |
| 8071 | } |
| 8072 | |
| 8073 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 8074 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WeakIDs) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8075 | if (WeakUndeclaredIdentifiers.empty()) |
| 8076 | return; |
| 8077 | |
| 8078 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8079 | IdentifierInfo *WeakId |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8080 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8081 | IdentifierInfo *AliasId |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8082 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 8083 | SourceLocation Loc |
| 8084 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 8085 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 8086 | WeakInfo WI(AliasId, Loc); |
| 8087 | WI.setUsed(Used); |
| 8088 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 8089 | } |
| 8090 | WeakUndeclaredIdentifiers.clear(); |
| 8091 | } |
| 8092 | |
| 8093 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 8094 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 8095 | ExternalVTableUse VT; |
| 8096 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 8097 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 8098 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 8099 | VTables.push_back(VT); |
| 8100 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8101 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8102 | VTableUses.clear(); |
| 8103 | } |
| 8104 | |
| 8105 | void ASTReader::ReadPendingInstantiations( |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 8106 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation>> &Pending) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8107 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 8108 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 8109 | SourceLocation Loc |
| 8110 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 8111 | |
| 8112 | Pending.push_back(std::make_pair(D, Loc)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8113 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8114 | PendingInstantiations.clear(); |
| 8115 | } |
| 8116 | |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8117 | void ASTReader::ReadLateParsedTemplates( |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 8118 | llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> |
| 8119 | &LPTMap) { |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8120 | for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N; |
| 8121 | /* In loop */) { |
| 8122 | FunctionDecl *FD = cast<FunctionDecl>(GetDecl(LateParsedTemplates[Idx++])); |
| 8123 | |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 8124 | auto LT = llvm::make_unique<LateParsedTemplate>(); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8125 | LT->D = GetDecl(LateParsedTemplates[Idx++]); |
| 8126 | |
| 8127 | ModuleFile *F = getOwningModuleFile(LT->D); |
| 8128 | assert(F && "No module"); |
| 8129 | |
| 8130 | unsigned TokN = LateParsedTemplates[Idx++]; |
| 8131 | LT->Toks.reserve(TokN); |
| 8132 | for (unsigned T = 0; T < TokN; ++T) |
| 8133 | LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx)); |
| 8134 | |
Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 8135 | LPTMap.insert(std::make_pair(FD, std::move(LT))); |
Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8136 | } |
| 8137 | |
| 8138 | LateParsedTemplates.clear(); |
| 8139 | } |
| 8140 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8141 | void ASTReader::LoadSelector(Selector Sel) { |
| 8142 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 8143 | ReadMethodPool(Sel); |
| 8144 | } |
| 8145 | |
| 8146 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
| 8147 | assert(ID && "Non-zero identifier ID required"); |
| 8148 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
| 8149 | IdentifiersLoaded[ID - 1] = II; |
| 8150 | if (DeserializationListener) |
| 8151 | DeserializationListener->IdentifierRead(ID, II); |
| 8152 | } |
| 8153 | |
| 8154 | /// \brief Set the globally-visible declarations associated with the given |
| 8155 | /// identifier. |
| 8156 | /// |
| 8157 | /// If the AST reader is currently in a state where the given declaration IDs |
| 8158 | /// cannot safely be resolved, they are queued until it is safe to resolve |
| 8159 | /// them. |
| 8160 | /// |
| 8161 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 8162 | /// declarations. |
| 8163 | /// |
| 8164 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 8165 | /// visible at global scope. |
| 8166 | /// |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8167 | /// \param Decls if non-null, this vector will be populated with the set of |
| 8168 | /// deserialized declarations. These declarations will not be pushed into |
| 8169 | /// scope. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8170 | void |
| 8171 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
| 8172 | const SmallVectorImpl<uint32_t> &DeclIDs, |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8173 | SmallVectorImpl<Decl *> *Decls) { |
| 8174 | if (NumCurrentElementsDeserializing && !Decls) { |
| 8175 | PendingIdentifierInfos[II].append(DeclIDs.begin(), DeclIDs.end()); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8176 | return; |
| 8177 | } |
| 8178 | |
| 8179 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 8180 | if (!SemaObj) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8181 | // Queue this declaration so that it will be added to the |
| 8182 | // translation unit scope and identifier's declaration chain |
| 8183 | // once a Sema object is known. |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 8184 | PreloadedDeclIDs.push_back(DeclIDs[I]); |
| 8185 | continue; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8186 | } |
Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 8187 | |
| 8188 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 8189 | |
| 8190 | // If we're simply supposed to record the declarations, do so now. |
| 8191 | if (Decls) { |
| 8192 | Decls->push_back(D); |
| 8193 | continue; |
| 8194 | } |
| 8195 | |
| 8196 | // Introduce this declaration into the translation-unit scope |
| 8197 | // and add it to the declaration chain for this identifier, so |
| 8198 | // that (unqualified) name lookup will find it. |
| 8199 | pushExternalDeclIntoScope(D, II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8200 | } |
| 8201 | } |
| 8202 | |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 8203 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8204 | if (ID == 0) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8205 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8206 | |
| 8207 | if (IdentifiersLoaded.empty()) { |
| 8208 | Error("no identifier table in AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8209 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8210 | } |
| 8211 | |
| 8212 | ID -= 1; |
| 8213 | if (!IdentifiersLoaded[ID]) { |
| 8214 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 8215 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
| 8216 | ModuleFile *M = I->second; |
| 8217 | unsigned Index = ID - M->BaseIdentifierID; |
| 8218 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
| 8219 | |
| 8220 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 8221 | // Extract that 16-bit length to avoid having to execute strlen(). |
| 8222 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 8223 | // unsigned integers. This is important to avoid integer overflow when |
| 8224 | // we cast them to 'unsigned'. |
| 8225 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
| 8226 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 8227 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 8228 | auto &II = PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
| 8229 | IdentifiersLoaded[ID] = &II; |
| 8230 | markIdentifierFromAST(*this, II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8231 | if (DeserializationListener) |
Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 8232 | DeserializationListener->IdentifierRead(ID + 1, &II); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8233 | } |
| 8234 | |
| 8235 | return IdentifiersLoaded[ID]; |
| 8236 | } |
| 8237 | |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 8238 | IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) { |
| 8239 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8240 | } |
| 8241 | |
| 8242 | IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) { |
| 8243 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 8244 | return LocalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8245 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8246 | if (!M.ModuleOffsetMap.empty()) |
| 8247 | ReadModuleOffsetMap(M); |
| 8248 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8249 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8250 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8251 | assert(I != M.IdentifierRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8252 | && "Invalid index into identifier index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8253 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8254 | return LocalID + I->second; |
| 8255 | } |
| 8256 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8257 | MacroInfo *ASTReader::getMacro(MacroID ID) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8258 | if (ID == 0) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8259 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8260 | |
| 8261 | if (MacrosLoaded.empty()) { |
| 8262 | Error("no macro table in AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8263 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8264 | } |
| 8265 | |
| 8266 | ID -= NUM_PREDEF_MACRO_IDS; |
| 8267 | if (!MacrosLoaded[ID]) { |
| 8268 | GlobalMacroMapType::iterator I |
| 8269 | = GlobalMacroMap.find(ID + NUM_PREDEF_MACRO_IDS); |
| 8270 | assert(I != GlobalMacroMap.end() && "Corrupted global macro map"); |
| 8271 | ModuleFile *M = I->second; |
| 8272 | unsigned Index = ID - M->BaseMacroID; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8273 | MacrosLoaded[ID] = ReadMacroRecord(*M, M->MacroOffsets[Index]); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8274 | |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8275 | if (DeserializationListener) |
| 8276 | DeserializationListener->MacroRead(ID + NUM_PREDEF_MACRO_IDS, |
| 8277 | MacrosLoaded[ID]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8278 | } |
| 8279 | |
| 8280 | return MacrosLoaded[ID]; |
| 8281 | } |
| 8282 | |
| 8283 | MacroID ASTReader::getGlobalMacroID(ModuleFile &M, unsigned LocalID) { |
| 8284 | if (LocalID < NUM_PREDEF_MACRO_IDS) |
| 8285 | return LocalID; |
| 8286 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8287 | if (!M.ModuleOffsetMap.empty()) |
| 8288 | ReadModuleOffsetMap(M); |
| 8289 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8290 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8291 | = M.MacroRemap.find(LocalID - NUM_PREDEF_MACRO_IDS); |
| 8292 | assert(I != M.MacroRemap.end() && "Invalid index into macro index remap"); |
| 8293 | |
| 8294 | return LocalID + I->second; |
| 8295 | } |
| 8296 | |
| 8297 | serialization::SubmoduleID |
| 8298 | ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) { |
| 8299 | if (LocalID < NUM_PREDEF_SUBMODULE_IDS) |
| 8300 | return LocalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8301 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8302 | if (!M.ModuleOffsetMap.empty()) |
| 8303 | ReadModuleOffsetMap(M); |
| 8304 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8305 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8306 | = M.SubmoduleRemap.find(LocalID - NUM_PREDEF_SUBMODULE_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8307 | assert(I != M.SubmoduleRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8308 | && "Invalid index into submodule index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8309 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8310 | return LocalID + I->second; |
| 8311 | } |
| 8312 | |
| 8313 | Module *ASTReader::getSubmodule(SubmoduleID GlobalID) { |
| 8314 | if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) { |
| 8315 | assert(GlobalID == 0 && "Unhandled global submodule ID"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8316 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8317 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8318 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8319 | if (GlobalID > SubmodulesLoaded.size()) { |
| 8320 | Error("submodule ID out of range in AST file"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8321 | return nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8322 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8323 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8324 | return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS]; |
| 8325 | } |
Douglas Gregor | c147b0b | 2013-01-12 01:29:50 +0000 | [diff] [blame] | 8326 | |
| 8327 | Module *ASTReader::getModule(unsigned ID) { |
| 8328 | return getSubmodule(ID); |
| 8329 | } |
| 8330 | |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 8331 | ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &F, unsigned ID) { |
| 8332 | if (ID & 1) { |
| 8333 | // It's a module, look it up by submodule ID. |
| 8334 | auto I = GlobalSubmoduleMap.find(getGlobalSubmoduleID(F, ID >> 1)); |
| 8335 | return I == GlobalSubmoduleMap.end() ? nullptr : I->second; |
| 8336 | } else { |
| 8337 | // It's a prefix (preamble, PCH, ...). Look it up by index. |
| 8338 | unsigned IndexFromEnd = ID >> 1; |
| 8339 | assert(IndexFromEnd && "got reference to unknown module file"); |
| 8340 | return getModuleManager().pch_modules().end()[-IndexFromEnd]; |
| 8341 | } |
| 8342 | } |
| 8343 | |
| 8344 | unsigned ASTReader::getModuleFileID(ModuleFile *F) { |
| 8345 | if (!F) |
| 8346 | return 1; |
| 8347 | |
| 8348 | // For a file representing a module, use the submodule ID of the top-level |
| 8349 | // module as the file ID. For any other kind of file, the number of such |
| 8350 | // files loaded beforehand will be the same on reload. |
| 8351 | // FIXME: Is this true even if we have an explicit module file and a PCH? |
| 8352 | if (F->isModule()) |
| 8353 | return ((F->BaseSubmoduleID + NUM_PREDEF_SUBMODULE_IDS) << 1) | 1; |
| 8354 | |
| 8355 | auto PCHModules = getModuleManager().pch_modules(); |
| 8356 | auto I = std::find(PCHModules.begin(), PCHModules.end(), F); |
| 8357 | assert(I != PCHModules.end() && "emitting reference to unknown file"); |
| 8358 | return (I - PCHModules.end()) << 1; |
| 8359 | } |
| 8360 | |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8361 | llvm::Optional<ExternalASTSource::ASTSourceDescriptor> |
| 8362 | ASTReader::getSourceDescriptor(unsigned ID) { |
| 8363 | if (const Module *M = getSubmodule(ID)) |
Adrian Prantl | c6458d6 | 2015-09-19 00:10:32 +0000 | [diff] [blame] | 8364 | return ExternalASTSource::ASTSourceDescriptor(*M); |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8365 | |
| 8366 | // If there is only a single PCH, return it instead. |
Hiroshi Inoue | 3170de0 | 2017-07-01 08:46:43 +0000 | [diff] [blame] | 8367 | // Chained PCH are not supported. |
Saleem Abdulrasool | 97d2555 | 2017-03-02 17:37:11 +0000 | [diff] [blame] | 8368 | const auto &PCHChain = ModuleMgr.pch_modules(); |
| 8369 | if (std::distance(std::begin(PCHChain), std::end(PCHChain))) { |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8370 | ModuleFile &MF = ModuleMgr.getPrimaryModule(); |
Adrian Prantl | 3a2d494 | 2016-01-22 23:30:56 +0000 | [diff] [blame] | 8371 | StringRef ModuleName = llvm::sys::path::filename(MF.OriginalSourceFileName); |
Adrian Prantl | 9bc3c4f | 2016-04-27 17:06:22 +0000 | [diff] [blame] | 8372 | StringRef FileName = llvm::sys::path::filename(MF.FileName); |
| 8373 | return ASTReader::ASTSourceDescriptor(ModuleName, MF.OriginalDir, FileName, |
| 8374 | MF.Signature); |
Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8375 | } |
| 8376 | return None; |
| 8377 | } |
| 8378 | |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 8379 | ExternalASTSource::ExtKind ASTReader::hasExternalDefinitions(const Decl *FD) { |
Richard Smith | a465362 | 2017-09-06 20:01:14 +0000 | [diff] [blame] | 8380 | auto I = DefinitionSource.find(FD); |
| 8381 | if (I == DefinitionSource.end()) |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 8382 | return EK_ReplyHazy; |
David Blaikie | e6b7c28 | 2017-04-11 20:46:34 +0000 | [diff] [blame] | 8383 | return I->second ? EK_Never : EK_Always; |
David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 8384 | } |
| 8385 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8386 | Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) { |
| 8387 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 8388 | } |
| 8389 | |
| 8390 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
| 8391 | if (ID == 0) |
| 8392 | return Selector(); |
| 8393 | |
| 8394 | if (ID > SelectorsLoaded.size()) { |
| 8395 | Error("selector ID out of range in AST file"); |
| 8396 | return Selector(); |
| 8397 | } |
| 8398 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8399 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == nullptr) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8400 | // Load this selector from the selector table. |
| 8401 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 8402 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
| 8403 | ModuleFile &M = *I->second; |
| 8404 | ASTSelectorLookupTrait Trait(*this, M); |
| 8405 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
| 8406 | SelectorsLoaded[ID - 1] = |
| 8407 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
| 8408 | if (DeserializationListener) |
| 8409 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 8410 | } |
| 8411 | |
| 8412 | return SelectorsLoaded[ID - 1]; |
| 8413 | } |
| 8414 | |
| 8415 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
| 8416 | return DecodeSelector(ID); |
| 8417 | } |
| 8418 | |
| 8419 | uint32_t ASTReader::GetNumExternalSelectors() { |
| 8420 | // ID 0 (the null selector) is considered an external selector. |
| 8421 | return getTotalNumSelectors() + 1; |
| 8422 | } |
| 8423 | |
| 8424 | serialization::SelectorID |
| 8425 | ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const { |
| 8426 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 8427 | return LocalID; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8428 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8429 | if (!M.ModuleOffsetMap.empty()) |
| 8430 | ReadModuleOffsetMap(M); |
| 8431 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8432 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8433 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8434 | assert(I != M.SelectorRemap.end() |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8435 | && "Invalid index into selector index remap"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8436 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8437 | return LocalID + I->second; |
| 8438 | } |
| 8439 | |
| 8440 | DeclarationName |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8441 | ASTReader::ReadDeclarationName(ModuleFile &F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8442 | const RecordData &Record, 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 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| 8445 | switch (Kind) { |
| 8446 | case DeclarationName::Identifier: |
Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 8447 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8448 | |
| 8449 | case DeclarationName::ObjCZeroArgSelector: |
| 8450 | case DeclarationName::ObjCOneArgSelector: |
| 8451 | case DeclarationName::ObjCMultiArgSelector: |
| 8452 | return DeclarationName(ReadSelector(F, Record, Idx)); |
| 8453 | |
| 8454 | case DeclarationName::CXXConstructorName: |
| 8455 | return Context.DeclarationNames.getCXXConstructorName( |
| 8456 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 8457 | |
| 8458 | case DeclarationName::CXXDestructorName: |
| 8459 | return Context.DeclarationNames.getCXXDestructorName( |
| 8460 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 8461 | |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8462 | case DeclarationName::CXXDeductionGuideName: |
| 8463 | return Context.DeclarationNames.getCXXDeductionGuideName( |
| 8464 | ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
| 8465 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8466 | case DeclarationName::CXXConversionFunctionName: |
| 8467 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 8468 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 8469 | |
| 8470 | case DeclarationName::CXXOperatorName: |
| 8471 | return Context.DeclarationNames.getCXXOperatorName( |
| 8472 | (OverloadedOperatorKind)Record[Idx++]); |
| 8473 | |
| 8474 | case DeclarationName::CXXLiteralOperatorName: |
| 8475 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
| 8476 | GetIdentifierInfo(F, Record, Idx)); |
| 8477 | |
| 8478 | case DeclarationName::CXXUsingDirective: |
| 8479 | return DeclarationName::getUsingDirectiveName(); |
| 8480 | } |
| 8481 | |
| 8482 | llvm_unreachable("Invalid NameKind!"); |
| 8483 | } |
| 8484 | |
| 8485 | void ASTReader::ReadDeclarationNameLoc(ModuleFile &F, |
| 8486 | DeclarationNameLoc &DNLoc, |
| 8487 | DeclarationName Name, |
| 8488 | const RecordData &Record, unsigned &Idx) { |
| 8489 | switch (Name.getNameKind()) { |
| 8490 | case DeclarationName::CXXConstructorName: |
| 8491 | case DeclarationName::CXXDestructorName: |
| 8492 | case DeclarationName::CXXConversionFunctionName: |
| 8493 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8494 | break; |
| 8495 | |
| 8496 | case DeclarationName::CXXOperatorName: |
| 8497 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 8498 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 8499 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 8500 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 8501 | break; |
| 8502 | |
| 8503 | case DeclarationName::CXXLiteralOperatorName: |
| 8504 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 8505 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 8506 | break; |
| 8507 | |
| 8508 | case DeclarationName::Identifier: |
| 8509 | case DeclarationName::ObjCZeroArgSelector: |
| 8510 | case DeclarationName::ObjCOneArgSelector: |
| 8511 | case DeclarationName::ObjCMultiArgSelector: |
| 8512 | case DeclarationName::CXXUsingDirective: |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8513 | case DeclarationName::CXXDeductionGuideName: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8514 | break; |
| 8515 | } |
| 8516 | } |
| 8517 | |
| 8518 | void ASTReader::ReadDeclarationNameInfo(ModuleFile &F, |
| 8519 | DeclarationNameInfo &NameInfo, |
| 8520 | const RecordData &Record, unsigned &Idx) { |
| 8521 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
| 8522 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 8523 | DeclarationNameLoc DNLoc; |
| 8524 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 8525 | NameInfo.setInfo(DNLoc); |
| 8526 | } |
| 8527 | |
| 8528 | void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, |
| 8529 | const RecordData &Record, unsigned &Idx) { |
| 8530 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
| 8531 | unsigned NumTPLists = Record[Idx++]; |
| 8532 | Info.NumTemplParamLists = NumTPLists; |
| 8533 | if (NumTPLists) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8534 | Info.TemplParamLists = |
| 8535 | new (getContext()) TemplateParameterList *[NumTPLists]; |
Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 8536 | for (unsigned i = 0; i != NumTPLists; ++i) |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8537 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 8538 | } |
| 8539 | } |
| 8540 | |
| 8541 | TemplateName |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8542 | ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8543 | unsigned &Idx) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8544 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8545 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
| 8546 | switch (Kind) { |
| 8547 | case TemplateName::Template: |
| 8548 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
| 8549 | |
| 8550 | case TemplateName::OverloadedTemplate: { |
| 8551 | unsigned size = Record[Idx++]; |
| 8552 | UnresolvedSet<8> Decls; |
| 8553 | while (size--) |
| 8554 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
| 8555 | |
| 8556 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 8557 | } |
| 8558 | |
| 8559 | case TemplateName::QualifiedTemplate: { |
| 8560 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
| 8561 | bool hasTemplKeyword = Record[Idx++]; |
| 8562 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
| 8563 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 8564 | } |
| 8565 | |
| 8566 | case TemplateName::DependentTemplate: { |
| 8567 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
| 8568 | if (Record[Idx++]) // isIdentifier |
| 8569 | return Context.getDependentTemplateName(NNS, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8570 | GetIdentifierInfo(F, Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8571 | Idx)); |
| 8572 | return Context.getDependentTemplateName(NNS, |
| 8573 | (OverloadedOperatorKind)Record[Idx++]); |
| 8574 | } |
| 8575 | |
| 8576 | case TemplateName::SubstTemplateTemplateParm: { |
| 8577 | TemplateTemplateParmDecl *param |
| 8578 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
| 8579 | if (!param) return TemplateName(); |
| 8580 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
| 8581 | return Context.getSubstTemplateTemplateParm(param, replacement); |
| 8582 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8583 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8584 | case TemplateName::SubstTemplateTemplateParmPack: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8585 | TemplateTemplateParmDecl *Param |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8586 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
| 8587 | if (!Param) |
| 8588 | return TemplateName(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8589 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8590 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 8591 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| 8592 | return TemplateName(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8593 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8594 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 8595 | } |
| 8596 | } |
| 8597 | |
| 8598 | llvm_unreachable("Unhandled template name kind!"); |
| 8599 | } |
| 8600 | |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8601 | TemplateArgument ASTReader::ReadTemplateArgument(ModuleFile &F, |
| 8602 | const RecordData &Record, |
| 8603 | unsigned &Idx, |
| 8604 | bool Canonicalize) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8605 | ASTContext &Context = getContext(); |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8606 | if (Canonicalize) { |
| 8607 | // The caller wants a canonical template argument. Sometimes the AST only |
| 8608 | // wants template arguments in canonical form (particularly as the template |
| 8609 | // argument lists of template specializations) so ensure we preserve that |
| 8610 | // canonical form across serialization. |
| 8611 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Idx, false); |
| 8612 | return Context.getCanonicalTemplateArgument(Arg); |
| 8613 | } |
| 8614 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8615 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| 8616 | switch (Kind) { |
| 8617 | case TemplateArgument::Null: |
| 8618 | return TemplateArgument(); |
| 8619 | case TemplateArgument::Type: |
| 8620 | return TemplateArgument(readType(F, Record, Idx)); |
| 8621 | case TemplateArgument::Declaration: { |
| 8622 | ValueDecl *D = ReadDeclAs<ValueDecl>(F, Record, Idx); |
David Blaikie | 0f62c8d | 2014-10-16 04:21:25 +0000 | [diff] [blame] | 8623 | return TemplateArgument(D, readType(F, Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8624 | } |
| 8625 | case TemplateArgument::NullPtr: |
| 8626 | return TemplateArgument(readType(F, Record, Idx), /*isNullPtr*/true); |
| 8627 | case TemplateArgument::Integral: { |
| 8628 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 8629 | QualType T = readType(F, Record, Idx); |
| 8630 | return TemplateArgument(Context, Value, T); |
| 8631 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8632 | case TemplateArgument::Template: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8633 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
| 8634 | case TemplateArgument::TemplateExpansion: { |
| 8635 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8636 | Optional<unsigned> NumTemplateExpansions; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8637 | if (unsigned NumExpansions = Record[Idx++]) |
| 8638 | NumTemplateExpansions = NumExpansions - 1; |
| 8639 | return TemplateArgument(Name, NumTemplateExpansions); |
| 8640 | } |
| 8641 | case TemplateArgument::Expression: |
| 8642 | return TemplateArgument(ReadExpr(F)); |
| 8643 | case TemplateArgument::Pack: { |
| 8644 | unsigned NumArgs = Record[Idx++]; |
| 8645 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
| 8646 | for (unsigned I = 0; I != NumArgs; ++I) |
| 8647 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 8648 | return TemplateArgument(llvm::makeArrayRef(Args, NumArgs)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8649 | } |
| 8650 | } |
| 8651 | |
| 8652 | llvm_unreachable("Unhandled template argument kind!"); |
| 8653 | } |
| 8654 | |
| 8655 | TemplateParameterList * |
| 8656 | ASTReader::ReadTemplateParameterList(ModuleFile &F, |
| 8657 | const RecordData &Record, unsigned &Idx) { |
| 8658 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 8659 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 8660 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 8661 | |
| 8662 | unsigned NumParams = Record[Idx++]; |
| 8663 | SmallVector<NamedDecl *, 16> Params; |
| 8664 | Params.reserve(NumParams); |
| 8665 | while (NumParams--) |
| 8666 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
| 8667 | |
Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 8668 | // TODO: Concepts |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8669 | TemplateParameterList *TemplateParams = TemplateParameterList::Create( |
| 8670 | getContext(), TemplateLoc, LAngleLoc, Params, RAngleLoc, nullptr); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8671 | return TemplateParams; |
| 8672 | } |
| 8673 | |
| 8674 | void |
| 8675 | ASTReader:: |
Craig Topper | 5603df4 | 2013-07-05 19:34:19 +0000 | [diff] [blame] | 8676 | ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8677 | ModuleFile &F, const RecordData &Record, |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8678 | unsigned &Idx, bool Canonicalize) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8679 | unsigned NumTemplateArgs = Record[Idx++]; |
| 8680 | TemplArgs.reserve(NumTemplateArgs); |
| 8681 | while (NumTemplateArgs--) |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8682 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx, Canonicalize)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8683 | } |
| 8684 | |
| 8685 | /// \brief Read a UnresolvedSet structure. |
Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 8686 | void ASTReader::ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8687 | const RecordData &Record, unsigned &Idx) { |
| 8688 | unsigned NumDecls = Record[Idx++]; |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8689 | Set.reserve(getContext(), NumDecls); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8690 | while (NumDecls--) { |
Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 8691 | DeclID ID = ReadDeclID(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8692 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8693 | Set.addLazyDecl(getContext(), ID, AS); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8694 | } |
| 8695 | } |
| 8696 | |
| 8697 | CXXBaseSpecifier |
| 8698 | ASTReader::ReadCXXBaseSpecifier(ModuleFile &F, |
| 8699 | const RecordData &Record, unsigned &Idx) { |
| 8700 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 8701 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 8702 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
| 8703 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
| 8704 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8705 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8706 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8707 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8708 | EllipsisLoc); |
| 8709 | Result.setInheritConstructors(inheritConstructors); |
| 8710 | return Result; |
| 8711 | } |
| 8712 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8713 | CXXCtorInitializer ** |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8714 | ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, |
| 8715 | unsigned &Idx) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8716 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8717 | unsigned NumInitializers = Record[Idx++]; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8718 | assert(NumInitializers && "wrote ctor initializers but have no inits"); |
| 8719 | auto **CtorInitializers = new (Context) CXXCtorInitializer*[NumInitializers]; |
| 8720 | for (unsigned i = 0; i != NumInitializers; ++i) { |
| 8721 | TypeSourceInfo *TInfo = nullptr; |
| 8722 | bool IsBaseVirtual = false; |
| 8723 | FieldDecl *Member = nullptr; |
| 8724 | IndirectFieldDecl *IndirectMember = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8725 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8726 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| 8727 | switch (Type) { |
| 8728 | case CTOR_INITIALIZER_BASE: |
| 8729 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8730 | IsBaseVirtual = Record[Idx++]; |
| 8731 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8732 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8733 | case CTOR_INITIALIZER_DELEGATING: |
| 8734 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8735 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8736 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8737 | case CTOR_INITIALIZER_MEMBER: |
| 8738 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
| 8739 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8740 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8741 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
| 8742 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
| 8743 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8744 | } |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8745 | |
| 8746 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
| 8747 | Expr *Init = ReadExpr(F); |
| 8748 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 8749 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8750 | |
| 8751 | CXXCtorInitializer *BOMInit; |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8752 | if (Type == CTOR_INITIALIZER_BASE) |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8753 | BOMInit = new (Context) |
| 8754 | CXXCtorInitializer(Context, TInfo, IsBaseVirtual, LParenLoc, Init, |
| 8755 | RParenLoc, MemberOrEllipsisLoc); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8756 | else if (Type == CTOR_INITIALIZER_DELEGATING) |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8757 | BOMInit = new (Context) |
| 8758 | CXXCtorInitializer(Context, TInfo, LParenLoc, Init, RParenLoc); |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8759 | else if (Member) |
| 8760 | BOMInit = new (Context) |
| 8761 | CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, LParenLoc, |
| 8762 | Init, RParenLoc); |
| 8763 | else |
| 8764 | BOMInit = new (Context) |
| 8765 | CXXCtorInitializer(Context, IndirectMember, MemberOrEllipsisLoc, |
| 8766 | LParenLoc, Init, RParenLoc); |
| 8767 | |
Richard Smith | 418ed82 | 2016-12-14 19:45:03 +0000 | [diff] [blame] | 8768 | if (/*IsWritten*/Record[Idx++]) { |
Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8769 | unsigned SourceOrder = Record[Idx++]; |
| 8770 | BOMInit->setSourceOrder(SourceOrder); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8771 | } |
| 8772 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8773 | CtorInitializers[i] = BOMInit; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8774 | } |
| 8775 | |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8776 | return CtorInitializers; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8777 | } |
| 8778 | |
| 8779 | NestedNameSpecifier * |
| 8780 | ASTReader::ReadNestedNameSpecifier(ModuleFile &F, |
| 8781 | const RecordData &Record, unsigned &Idx) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8782 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8783 | unsigned N = Record[Idx++]; |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8784 | NestedNameSpecifier *NNS = nullptr, *Prev = nullptr; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8785 | for (unsigned I = 0; I != N; ++I) { |
| 8786 | NestedNameSpecifier::SpecifierKind Kind |
| 8787 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 8788 | switch (Kind) { |
| 8789 | case NestedNameSpecifier::Identifier: { |
| 8790 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
| 8791 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
| 8792 | break; |
| 8793 | } |
| 8794 | |
| 8795 | case NestedNameSpecifier::Namespace: { |
| 8796 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
| 8797 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
| 8798 | break; |
| 8799 | } |
| 8800 | |
| 8801 | case NestedNameSpecifier::NamespaceAlias: { |
| 8802 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
| 8803 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
| 8804 | break; |
| 8805 | } |
| 8806 | |
| 8807 | case NestedNameSpecifier::TypeSpec: |
| 8808 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 8809 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
| 8810 | if (!T) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8811 | return nullptr; |
| 8812 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8813 | bool Template = Record[Idx++]; |
| 8814 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
| 8815 | break; |
| 8816 | } |
| 8817 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 8818 | case NestedNameSpecifier::Global: |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8819 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
| 8820 | // No associated value, and there can't be a prefix. |
| 8821 | break; |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8822 | |
| 8823 | case NestedNameSpecifier::Super: { |
| 8824 | CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx); |
| 8825 | NNS = NestedNameSpecifier::SuperSpecifier(Context, RD); |
| 8826 | break; |
| 8827 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8828 | } |
| 8829 | Prev = NNS; |
| 8830 | } |
| 8831 | return NNS; |
| 8832 | } |
| 8833 | |
| 8834 | NestedNameSpecifierLoc |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8835 | ASTReader::ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8836 | unsigned &Idx) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8837 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8838 | unsigned N = Record[Idx++]; |
| 8839 | NestedNameSpecifierLocBuilder Builder; |
| 8840 | for (unsigned I = 0; I != N; ++I) { |
| 8841 | NestedNameSpecifier::SpecifierKind Kind |
| 8842 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| 8843 | switch (Kind) { |
| 8844 | case NestedNameSpecifier::Identifier: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8845 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8846 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8847 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
| 8848 | break; |
| 8849 | } |
| 8850 | |
| 8851 | case NestedNameSpecifier::Namespace: { |
| 8852 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
| 8853 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8854 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
| 8855 | break; |
| 8856 | } |
| 8857 | |
| 8858 | case NestedNameSpecifier::NamespaceAlias: { |
| 8859 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
| 8860 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8861 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
| 8862 | break; |
| 8863 | } |
| 8864 | |
| 8865 | case NestedNameSpecifier::TypeSpec: |
| 8866 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 8867 | bool Template = Record[Idx++]; |
| 8868 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 8869 | if (!T) |
| 8870 | return NestedNameSpecifierLoc(); |
| 8871 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
| 8872 | |
| 8873 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8874 | Builder.Extend(Context, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8875 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 8876 | T->getTypeLoc(), ColonColonLoc); |
| 8877 | break; |
| 8878 | } |
| 8879 | |
| 8880 | case NestedNameSpecifier::Global: { |
| 8881 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
| 8882 | Builder.MakeGlobal(Context, ColonColonLoc); |
| 8883 | break; |
| 8884 | } |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8885 | |
| 8886 | case NestedNameSpecifier::Super: { |
| 8887 | CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx); |
| 8888 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8889 | Builder.MakeSuper(Context, RD, Range.getBegin(), Range.getEnd()); |
| 8890 | break; |
| 8891 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8892 | } |
| 8893 | } |
Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8894 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8895 | return Builder.getWithLocInContext(Context); |
| 8896 | } |
| 8897 | |
| 8898 | SourceRange |
| 8899 | ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record, |
| 8900 | unsigned &Idx) { |
| 8901 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 8902 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
| 8903 | return SourceRange(beg, end); |
| 8904 | } |
| 8905 | |
| 8906 | /// \brief Read an integral value |
| 8907 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
| 8908 | unsigned BitWidth = Record[Idx++]; |
| 8909 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 8910 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 8911 | Idx += NumWords; |
| 8912 | return Result; |
| 8913 | } |
| 8914 | |
| 8915 | /// \brief Read a signed integral value |
| 8916 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
| 8917 | bool isUnsigned = Record[Idx++]; |
| 8918 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 8919 | } |
| 8920 | |
| 8921 | /// \brief Read a floating-point value |
Tim Northover | 178723a | 2013-01-22 09:46:51 +0000 | [diff] [blame] | 8922 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, |
| 8923 | const llvm::fltSemantics &Sem, |
| 8924 | unsigned &Idx) { |
| 8925 | return llvm::APFloat(Sem, ReadAPInt(Record, Idx)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8926 | } |
| 8927 | |
| 8928 | // \brief Read a string |
| 8929 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
| 8930 | unsigned Len = Record[Idx++]; |
| 8931 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
| 8932 | Idx += Len; |
| 8933 | return Result; |
| 8934 | } |
| 8935 | |
Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 8936 | std::string ASTReader::ReadPath(ModuleFile &F, const RecordData &Record, |
| 8937 | unsigned &Idx) { |
| 8938 | std::string Filename = ReadString(Record, Idx); |
| 8939 | ResolveImportedPath(F, Filename); |
| 8940 | return Filename; |
| 8941 | } |
| 8942 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8943 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8944 | unsigned &Idx) { |
| 8945 | unsigned Major = Record[Idx++]; |
| 8946 | unsigned Minor = Record[Idx++]; |
| 8947 | unsigned Subminor = Record[Idx++]; |
| 8948 | if (Minor == 0) |
| 8949 | return VersionTuple(Major); |
| 8950 | if (Subminor == 0) |
| 8951 | return VersionTuple(Major, Minor - 1); |
| 8952 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 8953 | } |
| 8954 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8955 | CXXTemporary *ASTReader::ReadCXXTemporary(ModuleFile &F, |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8956 | const RecordData &Record, |
| 8957 | unsigned &Idx) { |
| 8958 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8959 | return CXXTemporary::Create(getContext(), Decl); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8960 | } |
| 8961 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8962 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) const { |
Argyrios Kyrtzidis | dc9fdaf | 2013-05-24 05:44:08 +0000 | [diff] [blame] | 8963 | return Diag(CurrentImportLoc, DiagID); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8964 | } |
| 8965 | |
Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8966 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) const { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8967 | return Diags.Report(Loc, DiagID); |
| 8968 | } |
| 8969 | |
| 8970 | /// \brief Retrieve the identifier table associated with the |
| 8971 | /// preprocessor. |
| 8972 | IdentifierTable &ASTReader::getIdentifierTable() { |
| 8973 | return PP.getIdentifierTable(); |
| 8974 | } |
| 8975 | |
| 8976 | /// \brief Record that the given ID maps to the given switch-case |
| 8977 | /// statement. |
| 8978 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8979 | assert((*CurrSwitchCaseStmts)[ID] == nullptr && |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8980 | "Already have a SwitchCase with this ID"); |
| 8981 | (*CurrSwitchCaseStmts)[ID] = SC; |
| 8982 | } |
| 8983 | |
| 8984 | /// \brief Retrieve the switch-case statement with the given ID. |
| 8985 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8986 | assert((*CurrSwitchCaseStmts)[ID] != nullptr && "No SwitchCase with this ID"); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8987 | return (*CurrSwitchCaseStmts)[ID]; |
| 8988 | } |
| 8989 | |
| 8990 | void ASTReader::ClearSwitchCaseIDs() { |
| 8991 | CurrSwitchCaseStmts->clear(); |
| 8992 | } |
| 8993 | |
| 8994 | void ASTReader::ReadComments() { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8995 | ASTContext &Context = getContext(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8996 | std::vector<RawComment *> Comments; |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 8997 | for (SmallVectorImpl<std::pair<BitstreamCursor, |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 8998 | serialization::ModuleFile *>>::iterator |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8999 | I = CommentsCursors.begin(), |
| 9000 | E = CommentsCursors.end(); |
| 9001 | I != E; ++I) { |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 9002 | Comments.clear(); |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 9003 | BitstreamCursor &Cursor = I->first; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9004 | serialization::ModuleFile &F = *I->second; |
| 9005 | SavedStreamPosition SavedPosition(Cursor); |
| 9006 | |
| 9007 | RecordData Record; |
| 9008 | while (true) { |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 9009 | llvm::BitstreamEntry Entry = |
| 9010 | Cursor.advanceSkippingSubblocks(BitstreamCursor::AF_DontPopBlockAtEnd); |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 9011 | |
Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 9012 | switch (Entry.Kind) { |
| 9013 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 9014 | case llvm::BitstreamEntry::Error: |
| 9015 | Error("malformed block record in AST file"); |
| 9016 | return; |
| 9017 | case llvm::BitstreamEntry::EndBlock: |
| 9018 | goto NextCursor; |
| 9019 | case llvm::BitstreamEntry::Record: |
| 9020 | // The interesting case. |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9021 | break; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9022 | } |
| 9023 | |
| 9024 | // Read a record. |
| 9025 | Record.clear(); |
Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 9026 | switch ((CommentRecordTypes)Cursor.readRecord(Entry.ID, Record)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9027 | case COMMENTS_RAW_COMMENT: { |
| 9028 | unsigned Idx = 0; |
| 9029 | SourceRange SR = ReadSourceRange(F, Record, Idx); |
| 9030 | RawComment::CommentKind Kind = |
| 9031 | (RawComment::CommentKind) Record[Idx++]; |
| 9032 | bool IsTrailingComment = Record[Idx++]; |
| 9033 | bool IsAlmostTrailingComment = Record[Idx++]; |
Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 9034 | Comments.push_back(new (Context) RawComment( |
| 9035 | SR, Kind, IsTrailingComment, IsAlmostTrailingComment, |
| 9036 | Context.getLangOpts().CommentOpts.ParseAllComments)); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9037 | break; |
| 9038 | } |
| 9039 | } |
| 9040 | } |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 9041 | NextCursor: |
Bruno Cardoso Lopes | c23af57 | 2016-12-19 21:06:06 +0000 | [diff] [blame] | 9042 | // De-serialized SourceLocations get negative FileIDs for other modules, |
| 9043 | // potentially invalidating the original order. Sort it again. |
| 9044 | std::sort(Comments.begin(), Comments.end(), |
| 9045 | BeforeThanCompare<RawComment>(SourceMgr)); |
Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 9046 | Context.Comments.addDeserializedComments(Comments); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9047 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9048 | } |
| 9049 | |
Argyrios Kyrtzidis | a38cb20 | 2017-01-30 06:05:58 +0000 | [diff] [blame] | 9050 | void ASTReader::visitInputFiles(serialization::ModuleFile &MF, |
| 9051 | bool IncludeSystem, bool Complain, |
| 9052 | llvm::function_ref<void(const serialization::InputFile &IF, |
| 9053 | bool isSystem)> Visitor) { |
| 9054 | unsigned NumUserInputs = MF.NumUserInputFiles; |
| 9055 | unsigned NumInputs = MF.InputFilesLoaded.size(); |
| 9056 | assert(NumUserInputs <= NumInputs); |
| 9057 | unsigned N = IncludeSystem ? NumInputs : NumUserInputs; |
| 9058 | for (unsigned I = 0; I < N; ++I) { |
| 9059 | bool IsSystem = I >= NumUserInputs; |
| 9060 | InputFile IF = getInputFile(MF, I+1, Complain); |
| 9061 | Visitor(IF, IsSystem); |
| 9062 | } |
| 9063 | } |
| 9064 | |
Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 9065 | void ASTReader::visitTopLevelModuleMaps( |
| 9066 | serialization::ModuleFile &MF, |
| 9067 | llvm::function_ref<void(const FileEntry *FE)> Visitor) { |
| 9068 | unsigned NumInputs = MF.InputFilesLoaded.size(); |
| 9069 | for (unsigned I = 0; I < NumInputs; ++I) { |
| 9070 | InputFileInfo IFI = readInputFileInfo(MF, I + 1); |
| 9071 | if (IFI.TopLevelModuleMap) |
| 9072 | // FIXME: This unnecessarily re-reads the InputFileInfo. |
| 9073 | if (auto *FE = getInputFile(MF, I + 1).getFile()) |
| 9074 | Visitor(FE); |
| 9075 | } |
| 9076 | } |
| 9077 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9078 | std::string ASTReader::getOwningModuleNameForDiagnostic(const Decl *D) { |
| 9079 | // If we know the owning module, use it. |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 9080 | if (Module *M = D->getImportedOwningModule()) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9081 | return M->getFullModuleName(); |
| 9082 | |
| 9083 | // Otherwise, use the name of the top-level module the decl is within. |
| 9084 | if (ModuleFile *M = getOwningModuleFile(D)) |
| 9085 | return M->ModuleName; |
| 9086 | |
| 9087 | // Not from a module. |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 9088 | return {}; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9089 | } |
| 9090 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9091 | void ASTReader::finishPendingActions() { |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 9092 | while (!PendingIdentifierInfos.empty() || |
| 9093 | !PendingIncompleteDeclChains.empty() || !PendingDeclChains.empty() || |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 9094 | !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() || |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9095 | !PendingUpdateRecords.empty()) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9096 | // If any identifiers with corresponding top-level declarations have |
| 9097 | // been loaded, load those declarations now. |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 9098 | using TopLevelDeclsMap = |
| 9099 | llvm::DenseMap<IdentifierInfo *, SmallVector<Decl *, 2>>; |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 9100 | TopLevelDeclsMap TopLevelDecls; |
| 9101 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9102 | while (!PendingIdentifierInfos.empty()) { |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9103 | IdentifierInfo *II = PendingIdentifierInfos.back().first; |
Richard Smith | f0ae3c2d | 2014-03-28 17:31:23 +0000 | [diff] [blame] | 9104 | SmallVector<uint32_t, 4> DeclIDs = |
| 9105 | std::move(PendingIdentifierInfos.back().second); |
Douglas Gregor | cb15f08 | 2013-02-19 18:26:28 +0000 | [diff] [blame] | 9106 | PendingIdentifierInfos.pop_back(); |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9107 | |
| 9108 | SetGloballyVisibleDecls(II, DeclIDs, &TopLevelDecls[II]); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9109 | } |
Richard Smith | f0ae3c2d | 2014-03-28 17:31:23 +0000 | [diff] [blame] | 9110 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 9111 | // For each decl chain that we wanted to complete while deserializing, mark |
| 9112 | // it as "still needs to be completed". |
| 9113 | for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) { |
| 9114 | markIncompleteDeclChain(PendingIncompleteDeclChains[I]); |
| 9115 | } |
| 9116 | PendingIncompleteDeclChains.clear(); |
| 9117 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9118 | // Load pending declaration chains. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 9119 | for (unsigned I = 0; I != PendingDeclChains.size(); ++I) |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 9120 | loadPendingDeclChain(PendingDeclChains[I].first, PendingDeclChains[I].second); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9121 | PendingDeclChains.clear(); |
| 9122 | |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9123 | // Make the most recent of the top-level declarations visible. |
Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 9124 | for (TopLevelDeclsMap::iterator TLD = TopLevelDecls.begin(), |
| 9125 | TLDEnd = TopLevelDecls.end(); TLD != TLDEnd; ++TLD) { |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9126 | IdentifierInfo *II = TLD->first; |
| 9127 | for (unsigned I = 0, N = TLD->second.size(); I != N; ++I) { |
Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 9128 | pushExternalDeclIntoScope(cast<NamedDecl>(TLD->second[I]), II); |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9129 | } |
| 9130 | } |
| 9131 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9132 | // Load any pending macro definitions. |
| 9133 | for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) { |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9134 | IdentifierInfo *II = PendingMacroIDs.begin()[I].first; |
| 9135 | SmallVector<PendingMacroInfo, 2> GlobalIDs; |
| 9136 | GlobalIDs.swap(PendingMacroIDs.begin()[I].second); |
| 9137 | // Initialize the macro history from chained-PCHs ahead of module imports. |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 9138 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
Argyrios Kyrtzidis | 719736c | 2013-01-19 03:14:56 +0000 | [diff] [blame] | 9139 | ++IDIdx) { |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9140 | const PendingMacroInfo &Info = GlobalIDs[IDIdx]; |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 9141 | if (!Info.M->isModule()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9142 | resolvePendingMacro(II, Info); |
| 9143 | } |
| 9144 | // Handle module imports. |
Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 9145 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9146 | ++IDIdx) { |
| 9147 | const PendingMacroInfo &Info = GlobalIDs[IDIdx]; |
Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 9148 | if (Info.M->isModule()) |
Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9149 | resolvePendingMacro(II, Info); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9150 | } |
| 9151 | } |
| 9152 | PendingMacroIDs.clear(); |
Argyrios Kyrtzidis | 83a6e3b | 2013-02-16 00:48:59 +0000 | [diff] [blame] | 9153 | |
| 9154 | // Wire up the DeclContexts for Decls that we delayed setting until |
| 9155 | // recursive loading is completed. |
| 9156 | while (!PendingDeclContextInfos.empty()) { |
| 9157 | PendingDeclContextInfo Info = PendingDeclContextInfos.front(); |
| 9158 | PendingDeclContextInfos.pop_front(); |
| 9159 | DeclContext *SemaDC = cast<DeclContext>(GetDecl(Info.SemaDC)); |
| 9160 | DeclContext *LexicalDC = cast<DeclContext>(GetDecl(Info.LexicalDC)); |
| 9161 | Info.D->setDeclContextsImpl(SemaDC, LexicalDC, getContext()); |
| 9162 | } |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 9163 | |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 9164 | // Perform any pending declaration updates. |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 9165 | while (!PendingUpdateRecords.empty()) { |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 9166 | auto Update = PendingUpdateRecords.pop_back_val(); |
| 9167 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 9168 | loadDeclUpdateRecords(Update); |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 9169 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9170 | } |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 9171 | |
| 9172 | // At this point, all update records for loaded decls are in place, so any |
| 9173 | // fake class definitions should have become real. |
| 9174 | assert(PendingFakeDefinitionData.empty() && |
| 9175 | "faked up a class definition but never saw the real one"); |
| 9176 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9177 | // If we deserialized any C++ or Objective-C class definitions, any |
| 9178 | // Objective-C protocol definitions, or any redeclarable templates, make sure |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 9179 | // that all redeclarations point to the definitions. Note that this can only |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9180 | // happen now, after the redeclaration chains have been fully wired. |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9181 | for (Decl *D : PendingDefinitions) { |
| 9182 | if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
Richard Smith | 5b21db8 | 2014-04-23 18:20:42 +0000 | [diff] [blame] | 9183 | if (const TagType *TagT = dyn_cast<TagType>(TD->getTypeForDecl())) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9184 | // Make sure that the TagType points at the definition. |
| 9185 | const_cast<TagType*>(TagT)->decl = TD; |
| 9186 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9187 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9188 | if (auto RD = dyn_cast<CXXRecordDecl>(D)) { |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9189 | for (auto *R = getMostRecentExistingDecl(RD); R; |
| 9190 | R = R->getPreviousDecl()) { |
| 9191 | assert((R == D) == |
| 9192 | cast<CXXRecordDecl>(R)->isThisDeclarationADefinition() && |
Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 9193 | "declaration thinks it's the definition but it isn't"); |
Aaron Ballman | 86c9390 | 2014-03-06 23:45:36 +0000 | [diff] [blame] | 9194 | cast<CXXRecordDecl>(R)->DefinitionData = RD->DefinitionData; |
Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 9195 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9196 | } |
| 9197 | |
| 9198 | continue; |
| 9199 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9200 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9201 | if (auto ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9202 | // Make sure that the ObjCInterfaceType points at the definition. |
| 9203 | const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl)) |
| 9204 | ->Decl = ID; |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9205 | |
| 9206 | for (auto *R = getMostRecentExistingDecl(ID); R; R = R->getPreviousDecl()) |
| 9207 | cast<ObjCInterfaceDecl>(R)->Data = ID->Data; |
| 9208 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9209 | continue; |
| 9210 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9211 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9212 | if (auto PD = dyn_cast<ObjCProtocolDecl>(D)) { |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9213 | for (auto *R = getMostRecentExistingDecl(PD); R; R = R->getPreviousDecl()) |
| 9214 | cast<ObjCProtocolDecl>(R)->Data = PD->Data; |
| 9215 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9216 | continue; |
| 9217 | } |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9218 | |
Craig Topper | c6914d0 | 2014-08-25 04:15:02 +0000 | [diff] [blame] | 9219 | auto RTD = cast<RedeclarableTemplateDecl>(D)->getCanonicalDecl(); |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9220 | for (auto *R = getMostRecentExistingDecl(RTD); R; R = R->getPreviousDecl()) |
| 9221 | cast<RedeclarableTemplateDecl>(R)->Common = RTD->Common; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9222 | } |
| 9223 | PendingDefinitions.clear(); |
| 9224 | |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 9225 | // Load the bodies of any functions or methods we've encountered. We do |
| 9226 | // this now (delayed) so that we can be sure that the declaration chains |
| 9227 | // have been fully wired up (hasBody relies on this). |
| 9228 | // FIXME: We shouldn't require complete redeclaration chains here. |
| 9229 | for (PendingBodiesMap::iterator PB = PendingBodies.begin(), |
| 9230 | PBEnd = PendingBodies.end(); |
| 9231 | PB != PBEnd; ++PB) { |
| 9232 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(PB->first)) { |
| 9233 | // FIXME: Check for =delete/=default? |
| 9234 | // FIXME: Complain about ODR violations here? |
| 9235 | const FunctionDecl *Defn = nullptr; |
| 9236 | if (!getContext().getLangOpts().Modules || !FD->hasBody(Defn)) { |
| 9237 | FD->setLazyBody(PB->second); |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9238 | } else { |
| 9239 | auto *NonConstDefn = const_cast<FunctionDecl*>(Defn); |
| 9240 | mergeDefinitionVisibility(NonConstDefn, FD); |
| 9241 | |
| 9242 | if (!FD->isLateTemplateParsed() && |
| 9243 | !NonConstDefn->isLateTemplateParsed() && |
| 9244 | FD->getODRHash() != NonConstDefn->getODRHash()) { |
| 9245 | PendingFunctionOdrMergeFailures[FD].push_back(NonConstDefn); |
| 9246 | } |
| 9247 | } |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 9248 | continue; |
| 9249 | } |
| 9250 | |
| 9251 | ObjCMethodDecl *MD = cast<ObjCMethodDecl>(PB->first); |
| 9252 | if (!getContext().getLangOpts().Modules || !MD->hasBody()) |
| 9253 | MD->setLazyBody(PB->second); |
| 9254 | } |
| 9255 | PendingBodies.clear(); |
| 9256 | |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 9257 | // Do some cleanup. |
| 9258 | for (auto *ND : PendingMergedDefinitionsToDeduplicate) |
| 9259 | getContext().deduplicateMergedDefinitonsFor(ND); |
| 9260 | PendingMergedDefinitionsToDeduplicate.clear(); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9261 | } |
| 9262 | |
| 9263 | void ASTReader::diagnoseOdrViolations() { |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9264 | if (PendingOdrMergeFailures.empty() && PendingOdrMergeChecks.empty() && |
| 9265 | PendingFunctionOdrMergeFailures.empty()) |
Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 9266 | return; |
| 9267 | |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9268 | // Trigger the import of the full definition of each class that had any |
| 9269 | // odr-merging problems, so we can produce better diagnostics for them. |
Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 9270 | // These updates may in turn find and diagnose some ODR failures, so take |
| 9271 | // ownership of the set first. |
| 9272 | auto OdrMergeFailures = std::move(PendingOdrMergeFailures); |
| 9273 | PendingOdrMergeFailures.clear(); |
| 9274 | for (auto &Merge : OdrMergeFailures) { |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9275 | Merge.first->buildLookup(); |
| 9276 | Merge.first->decls_begin(); |
| 9277 | Merge.first->bases_begin(); |
| 9278 | Merge.first->vbases_begin(); |
Richard Trieu | e13eabe | 2017-09-30 02:19:17 +0000 | [diff] [blame] | 9279 | for (auto &RecordPair : Merge.second) { |
| 9280 | auto *RD = RecordPair.first; |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9281 | RD->decls_begin(); |
| 9282 | RD->bases_begin(); |
| 9283 | RD->vbases_begin(); |
| 9284 | } |
| 9285 | } |
| 9286 | |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9287 | // Trigger the import of functions. |
| 9288 | auto FunctionOdrMergeFailures = std::move(PendingFunctionOdrMergeFailures); |
| 9289 | PendingFunctionOdrMergeFailures.clear(); |
| 9290 | for (auto &Merge : FunctionOdrMergeFailures) { |
| 9291 | Merge.first->buildLookup(); |
| 9292 | Merge.first->decls_begin(); |
| 9293 | Merge.first->getBody(); |
| 9294 | for (auto &FD : Merge.second) { |
| 9295 | FD->buildLookup(); |
| 9296 | FD->decls_begin(); |
| 9297 | FD->getBody(); |
| 9298 | } |
| 9299 | } |
| 9300 | |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9301 | // For each declaration from a merged context, check that the canonical |
| 9302 | // definition of that context also contains a declaration of the same |
| 9303 | // entity. |
| 9304 | // |
| 9305 | // Caution: this loop does things that might invalidate iterators into |
| 9306 | // PendingOdrMergeChecks. Don't turn this into a range-based for loop! |
| 9307 | while (!PendingOdrMergeChecks.empty()) { |
| 9308 | NamedDecl *D = PendingOdrMergeChecks.pop_back_val(); |
| 9309 | |
| 9310 | // FIXME: Skip over implicit declarations for now. This matters for things |
| 9311 | // like implicitly-declared special member functions. This isn't entirely |
| 9312 | // correct; we can end up with multiple unmerged declarations of the same |
| 9313 | // implicit entity. |
| 9314 | if (D->isImplicit()) |
| 9315 | continue; |
| 9316 | |
| 9317 | DeclContext *CanonDef = D->getDeclContext(); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9318 | |
| 9319 | bool Found = false; |
| 9320 | const Decl *DCanon = D->getCanonicalDecl(); |
| 9321 | |
Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 9322 | for (auto RI : D->redecls()) { |
| 9323 | if (RI->getLexicalDeclContext() == CanonDef) { |
| 9324 | Found = true; |
| 9325 | break; |
| 9326 | } |
| 9327 | } |
| 9328 | if (Found) |
| 9329 | continue; |
| 9330 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9331 | // Quick check failed, time to do the slow thing. Note, we can't just |
| 9332 | // look up the name of D in CanonDef here, because the member that is |
| 9333 | // in CanonDef might not be found by name lookup (it might have been |
| 9334 | // replaced by a more recent declaration in the lookup table), and we |
| 9335 | // can't necessarily find it in the redeclaration chain because it might |
| 9336 | // be merely mergeable, not redeclarable. |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9337 | llvm::SmallVector<const NamedDecl*, 4> Candidates; |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9338 | for (auto *CanonMember : CanonDef->decls()) { |
| 9339 | if (CanonMember->getCanonicalDecl() == DCanon) { |
| 9340 | // This can happen if the declaration is merely mergeable and not |
| 9341 | // actually redeclarable (we looked for redeclarations earlier). |
| 9342 | // |
| 9343 | // FIXME: We should be able to detect this more efficiently, without |
| 9344 | // pulling in all of the members of CanonDef. |
| 9345 | Found = true; |
| 9346 | break; |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9347 | } |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9348 | if (auto *ND = dyn_cast<NamedDecl>(CanonMember)) |
| 9349 | if (ND->getDeclName() == D->getDeclName()) |
| 9350 | Candidates.push_back(ND); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9351 | } |
| 9352 | |
| 9353 | if (!Found) { |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 9354 | // The AST doesn't like TagDecls becoming invalid after they've been |
| 9355 | // completed. We only really need to mark FieldDecls as invalid here. |
| 9356 | if (!isa<TagDecl>(D)) |
| 9357 | D->setInvalidDecl(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 9358 | |
Richard Smith | 4ab3dbd | 2015-02-13 22:43:51 +0000 | [diff] [blame] | 9359 | // Ensure we don't accidentally recursively enter deserialization while |
| 9360 | // we're producing our diagnostic. |
| 9361 | Deserializing RecursionGuard(this); |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9362 | |
| 9363 | std::string CanonDefModule = |
| 9364 | getOwningModuleNameForDiagnostic(cast<Decl>(CanonDef)); |
| 9365 | Diag(D->getLocation(), diag::err_module_odr_violation_missing_decl) |
| 9366 | << D << getOwningModuleNameForDiagnostic(D) |
| 9367 | << CanonDef << CanonDefModule.empty() << CanonDefModule; |
| 9368 | |
| 9369 | if (Candidates.empty()) |
| 9370 | Diag(cast<Decl>(CanonDef)->getLocation(), |
| 9371 | diag::note_module_odr_violation_no_possible_decls) << D; |
| 9372 | else { |
| 9373 | for (unsigned I = 0, N = Candidates.size(); I != N; ++I) |
| 9374 | Diag(Candidates[I]->getLocation(), |
| 9375 | diag::note_module_odr_violation_possible_decl) |
| 9376 | << Candidates[I]; |
| 9377 | } |
| 9378 | |
| 9379 | DiagnosedOdrMergeFailures.insert(CanonDef); |
| 9380 | } |
| 9381 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9382 | |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9383 | if (OdrMergeFailures.empty() && FunctionOdrMergeFailures.empty()) |
Richard Smith | 4ab3dbd | 2015-02-13 22:43:51 +0000 | [diff] [blame] | 9384 | return; |
| 9385 | |
| 9386 | // Ensure we don't accidentally recursively enter deserialization while |
| 9387 | // we're producing our diagnostics. |
| 9388 | Deserializing RecursionGuard(this); |
| 9389 | |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9390 | // Common code for hashing helpers. |
| 9391 | ODRHash Hash; |
| 9392 | auto ComputeQualTypeODRHash = [&Hash](QualType Ty) { |
| 9393 | Hash.clear(); |
| 9394 | Hash.AddQualType(Ty); |
| 9395 | return Hash.CalculateHash(); |
| 9396 | }; |
| 9397 | |
| 9398 | auto ComputeODRHash = [&Hash](const Stmt *S) { |
| 9399 | assert(S); |
| 9400 | Hash.clear(); |
| 9401 | Hash.AddStmt(S); |
| 9402 | return Hash.CalculateHash(); |
| 9403 | }; |
| 9404 | |
| 9405 | auto ComputeSubDeclODRHash = [&Hash](const Decl *D) { |
| 9406 | assert(D); |
| 9407 | Hash.clear(); |
| 9408 | Hash.AddSubDecl(D); |
| 9409 | return Hash.CalculateHash(); |
| 9410 | }; |
| 9411 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9412 | // Issue any pending ODR-failure diagnostics. |
Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 9413 | for (auto &Merge : OdrMergeFailures) { |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9414 | // If we've already pointed out a specific problem with this class, don't |
| 9415 | // bother issuing a general "something's different" diagnostic. |
David Blaikie | 82e95a3 | 2014-11-19 07:49:47 +0000 | [diff] [blame] | 9416 | if (!DiagnosedOdrMergeFailures.insert(Merge.first).second) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9417 | continue; |
| 9418 | |
| 9419 | bool Diagnosed = false; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9420 | CXXRecordDecl *FirstRecord = Merge.first; |
| 9421 | std::string FirstModule = getOwningModuleNameForDiagnostic(FirstRecord); |
Richard Trieu | e13eabe | 2017-09-30 02:19:17 +0000 | [diff] [blame] | 9422 | for (auto &RecordPair : Merge.second) { |
| 9423 | CXXRecordDecl *SecondRecord = RecordPair.first; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9424 | // Multiple different declarations got merged together; tell the user |
| 9425 | // where they came from. |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9426 | if (FirstRecord == SecondRecord) |
| 9427 | continue; |
| 9428 | |
| 9429 | std::string SecondModule = getOwningModuleNameForDiagnostic(SecondRecord); |
Richard Trieu | e13eabe | 2017-09-30 02:19:17 +0000 | [diff] [blame] | 9430 | |
| 9431 | auto *FirstDD = FirstRecord->DefinitionData; |
| 9432 | auto *SecondDD = RecordPair.second; |
| 9433 | |
| 9434 | assert(FirstDD && SecondDD && "Definitions without DefinitionData"); |
| 9435 | |
| 9436 | // Diagnostics from DefinitionData are emitted here. |
| 9437 | if (FirstDD != SecondDD) { |
| 9438 | enum ODRDefinitionDataDifference { |
| 9439 | NumBases, |
| 9440 | NumVBases, |
| 9441 | BaseType, |
| 9442 | BaseVirtual, |
| 9443 | BaseAccess, |
| 9444 | }; |
| 9445 | auto ODRDiagError = [FirstRecord, &FirstModule, |
| 9446 | this](SourceLocation Loc, SourceRange Range, |
| 9447 | ODRDefinitionDataDifference DiffType) { |
| 9448 | return Diag(Loc, diag::err_module_odr_violation_definition_data) |
| 9449 | << FirstRecord << FirstModule.empty() << FirstModule << Range |
| 9450 | << DiffType; |
| 9451 | }; |
| 9452 | auto ODRDiagNote = [&SecondModule, |
| 9453 | this](SourceLocation Loc, SourceRange Range, |
| 9454 | ODRDefinitionDataDifference DiffType) { |
| 9455 | return Diag(Loc, diag::note_module_odr_violation_definition_data) |
| 9456 | << SecondModule << Range << DiffType; |
| 9457 | }; |
| 9458 | |
Richard Trieu | e13eabe | 2017-09-30 02:19:17 +0000 | [diff] [blame] | 9459 | unsigned FirstNumBases = FirstDD->NumBases; |
| 9460 | unsigned FirstNumVBases = FirstDD->NumVBases; |
| 9461 | unsigned SecondNumBases = SecondDD->NumBases; |
| 9462 | unsigned SecondNumVBases = SecondDD->NumVBases; |
| 9463 | |
| 9464 | auto GetSourceRange = [](struct CXXRecordDecl::DefinitionData *DD) { |
| 9465 | unsigned NumBases = DD->NumBases; |
| 9466 | if (NumBases == 0) return SourceRange(); |
| 9467 | auto bases = DD->bases(); |
| 9468 | return SourceRange(bases[0].getLocStart(), |
| 9469 | bases[NumBases - 1].getLocEnd()); |
| 9470 | }; |
| 9471 | |
| 9472 | if (FirstNumBases != SecondNumBases) { |
| 9473 | ODRDiagError(FirstRecord->getLocation(), GetSourceRange(FirstDD), |
| 9474 | NumBases) |
| 9475 | << FirstNumBases; |
| 9476 | ODRDiagNote(SecondRecord->getLocation(), GetSourceRange(SecondDD), |
| 9477 | NumBases) |
| 9478 | << SecondNumBases; |
| 9479 | Diagnosed = true; |
| 9480 | break; |
| 9481 | } |
| 9482 | |
| 9483 | if (FirstNumVBases != SecondNumVBases) { |
| 9484 | ODRDiagError(FirstRecord->getLocation(), GetSourceRange(FirstDD), |
| 9485 | NumVBases) |
| 9486 | << FirstNumVBases; |
| 9487 | ODRDiagNote(SecondRecord->getLocation(), GetSourceRange(SecondDD), |
| 9488 | NumVBases) |
| 9489 | << SecondNumVBases; |
| 9490 | Diagnosed = true; |
| 9491 | break; |
| 9492 | } |
| 9493 | |
| 9494 | auto FirstBases = FirstDD->bases(); |
| 9495 | auto SecondBases = SecondDD->bases(); |
| 9496 | unsigned i = 0; |
| 9497 | for (i = 0; i < FirstNumBases; ++i) { |
| 9498 | auto FirstBase = FirstBases[i]; |
| 9499 | auto SecondBase = SecondBases[i]; |
| 9500 | if (ComputeQualTypeODRHash(FirstBase.getType()) != |
| 9501 | ComputeQualTypeODRHash(SecondBase.getType())) { |
| 9502 | ODRDiagError(FirstRecord->getLocation(), FirstBase.getSourceRange(), |
| 9503 | BaseType) |
| 9504 | << (i + 1) << FirstBase.getType(); |
| 9505 | ODRDiagNote(SecondRecord->getLocation(), |
| 9506 | SecondBase.getSourceRange(), BaseType) |
| 9507 | << (i + 1) << SecondBase.getType(); |
| 9508 | break; |
| 9509 | } |
| 9510 | |
| 9511 | if (FirstBase.isVirtual() != SecondBase.isVirtual()) { |
| 9512 | ODRDiagError(FirstRecord->getLocation(), FirstBase.getSourceRange(), |
| 9513 | BaseVirtual) |
| 9514 | << (i + 1) << FirstBase.isVirtual() << FirstBase.getType(); |
| 9515 | ODRDiagNote(SecondRecord->getLocation(), |
| 9516 | SecondBase.getSourceRange(), BaseVirtual) |
| 9517 | << (i + 1) << SecondBase.isVirtual() << SecondBase.getType(); |
| 9518 | break; |
| 9519 | } |
| 9520 | |
| 9521 | if (FirstBase.getAccessSpecifierAsWritten() != |
| 9522 | SecondBase.getAccessSpecifierAsWritten()) { |
| 9523 | ODRDiagError(FirstRecord->getLocation(), FirstBase.getSourceRange(), |
| 9524 | BaseAccess) |
| 9525 | << (i + 1) << FirstBase.getType() |
| 9526 | << (int)FirstBase.getAccessSpecifierAsWritten(); |
| 9527 | ODRDiagNote(SecondRecord->getLocation(), |
| 9528 | SecondBase.getSourceRange(), BaseAccess) |
| 9529 | << (i + 1) << SecondBase.getType() |
| 9530 | << (int)SecondBase.getAccessSpecifierAsWritten(); |
| 9531 | break; |
| 9532 | } |
| 9533 | } |
| 9534 | |
| 9535 | if (i != FirstNumBases) { |
| 9536 | Diagnosed = true; |
| 9537 | break; |
| 9538 | } |
| 9539 | } |
| 9540 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9541 | using DeclHashes = llvm::SmallVector<std::pair<Decl *, unsigned>, 4>; |
Richard Trieu | 498117b | 2017-08-23 02:43:59 +0000 | [diff] [blame] | 9542 | |
| 9543 | const ClassTemplateDecl *FirstTemplate = |
| 9544 | FirstRecord->getDescribedClassTemplate(); |
| 9545 | const ClassTemplateDecl *SecondTemplate = |
| 9546 | SecondRecord->getDescribedClassTemplate(); |
| 9547 | |
| 9548 | assert(!FirstTemplate == !SecondTemplate && |
| 9549 | "Both pointers should be null or non-null"); |
| 9550 | |
| 9551 | enum ODRTemplateDifference { |
| 9552 | ParamEmptyName, |
| 9553 | ParamName, |
| 9554 | ParamSingleDefaultArgument, |
| 9555 | ParamDifferentDefaultArgument, |
| 9556 | }; |
| 9557 | |
| 9558 | if (FirstTemplate && SecondTemplate) { |
| 9559 | DeclHashes FirstTemplateHashes; |
| 9560 | DeclHashes SecondTemplateHashes; |
Richard Trieu | 498117b | 2017-08-23 02:43:59 +0000 | [diff] [blame] | 9561 | |
| 9562 | auto PopulateTemplateParameterHashs = |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9563 | [&ComputeSubDeclODRHash](DeclHashes &Hashes, |
| 9564 | const ClassTemplateDecl *TD) { |
Richard Trieu | 498117b | 2017-08-23 02:43:59 +0000 | [diff] [blame] | 9565 | for (auto *D : TD->getTemplateParameters()->asArray()) { |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9566 | Hashes.emplace_back(D, ComputeSubDeclODRHash(D)); |
Richard Trieu | 498117b | 2017-08-23 02:43:59 +0000 | [diff] [blame] | 9567 | } |
| 9568 | }; |
| 9569 | |
| 9570 | PopulateTemplateParameterHashs(FirstTemplateHashes, FirstTemplate); |
| 9571 | PopulateTemplateParameterHashs(SecondTemplateHashes, SecondTemplate); |
| 9572 | |
| 9573 | assert(FirstTemplateHashes.size() == SecondTemplateHashes.size() && |
| 9574 | "Number of template parameters should be equal."); |
| 9575 | |
| 9576 | auto FirstIt = FirstTemplateHashes.begin(); |
| 9577 | auto FirstEnd = FirstTemplateHashes.end(); |
| 9578 | auto SecondIt = SecondTemplateHashes.begin(); |
| 9579 | for (; FirstIt != FirstEnd; ++FirstIt, ++SecondIt) { |
| 9580 | if (FirstIt->second == SecondIt->second) |
| 9581 | continue; |
| 9582 | |
| 9583 | auto ODRDiagError = [FirstRecord, &FirstModule, |
| 9584 | this](SourceLocation Loc, SourceRange Range, |
| 9585 | ODRTemplateDifference DiffType) { |
| 9586 | return Diag(Loc, diag::err_module_odr_violation_template_parameter) |
| 9587 | << FirstRecord << FirstModule.empty() << FirstModule << Range |
| 9588 | << DiffType; |
| 9589 | }; |
| 9590 | auto ODRDiagNote = [&SecondModule, |
| 9591 | this](SourceLocation Loc, SourceRange Range, |
| 9592 | ODRTemplateDifference DiffType) { |
| 9593 | return Diag(Loc, diag::note_module_odr_violation_template_parameter) |
| 9594 | << SecondModule << Range << DiffType; |
| 9595 | }; |
| 9596 | |
| 9597 | const NamedDecl* FirstDecl = cast<NamedDecl>(FirstIt->first); |
| 9598 | const NamedDecl* SecondDecl = cast<NamedDecl>(SecondIt->first); |
| 9599 | |
| 9600 | assert(FirstDecl->getKind() == SecondDecl->getKind() && |
| 9601 | "Parameter Decl's should be the same kind."); |
| 9602 | |
| 9603 | DeclarationName FirstName = FirstDecl->getDeclName(); |
| 9604 | DeclarationName SecondName = SecondDecl->getDeclName(); |
| 9605 | |
| 9606 | if (FirstName != SecondName) { |
| 9607 | const bool FirstNameEmpty = |
| 9608 | FirstName.isIdentifier() && !FirstName.getAsIdentifierInfo(); |
| 9609 | const bool SecondNameEmpty = |
| 9610 | SecondName.isIdentifier() && !SecondName.getAsIdentifierInfo(); |
| 9611 | assert((!FirstNameEmpty || !SecondNameEmpty) && |
| 9612 | "Both template parameters cannot be unnamed."); |
| 9613 | ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(), |
| 9614 | FirstNameEmpty ? ParamEmptyName : ParamName) |
| 9615 | << FirstName; |
| 9616 | ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(), |
| 9617 | SecondNameEmpty ? ParamEmptyName : ParamName) |
| 9618 | << SecondName; |
| 9619 | break; |
| 9620 | } |
| 9621 | |
| 9622 | switch (FirstDecl->getKind()) { |
| 9623 | default: |
| 9624 | llvm_unreachable("Invalid template parameter type."); |
| 9625 | case Decl::TemplateTypeParm: { |
| 9626 | const auto *FirstParam = cast<TemplateTypeParmDecl>(FirstDecl); |
| 9627 | const auto *SecondParam = cast<TemplateTypeParmDecl>(SecondDecl); |
| 9628 | const bool HasFirstDefaultArgument = |
| 9629 | FirstParam->hasDefaultArgument() && |
| 9630 | !FirstParam->defaultArgumentWasInherited(); |
| 9631 | const bool HasSecondDefaultArgument = |
| 9632 | SecondParam->hasDefaultArgument() && |
| 9633 | !SecondParam->defaultArgumentWasInherited(); |
| 9634 | |
| 9635 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 9636 | ODRDiagError(FirstDecl->getLocation(), |
| 9637 | FirstDecl->getSourceRange(), |
| 9638 | ParamSingleDefaultArgument) |
| 9639 | << HasFirstDefaultArgument; |
| 9640 | ODRDiagNote(SecondDecl->getLocation(), |
| 9641 | SecondDecl->getSourceRange(), |
| 9642 | ParamSingleDefaultArgument) |
| 9643 | << HasSecondDefaultArgument; |
| 9644 | break; |
| 9645 | } |
| 9646 | |
| 9647 | assert(HasFirstDefaultArgument && HasSecondDefaultArgument && |
| 9648 | "Expecting default arguments."); |
| 9649 | |
| 9650 | ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(), |
| 9651 | ParamDifferentDefaultArgument); |
| 9652 | ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(), |
| 9653 | ParamDifferentDefaultArgument); |
| 9654 | |
| 9655 | break; |
| 9656 | } |
| 9657 | case Decl::NonTypeTemplateParm: { |
| 9658 | const auto *FirstParam = cast<NonTypeTemplateParmDecl>(FirstDecl); |
| 9659 | const auto *SecondParam = cast<NonTypeTemplateParmDecl>(SecondDecl); |
| 9660 | const bool HasFirstDefaultArgument = |
| 9661 | FirstParam->hasDefaultArgument() && |
| 9662 | !FirstParam->defaultArgumentWasInherited(); |
| 9663 | const bool HasSecondDefaultArgument = |
| 9664 | SecondParam->hasDefaultArgument() && |
| 9665 | !SecondParam->defaultArgumentWasInherited(); |
| 9666 | |
| 9667 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 9668 | ODRDiagError(FirstDecl->getLocation(), |
| 9669 | FirstDecl->getSourceRange(), |
| 9670 | ParamSingleDefaultArgument) |
| 9671 | << HasFirstDefaultArgument; |
| 9672 | ODRDiagNote(SecondDecl->getLocation(), |
| 9673 | SecondDecl->getSourceRange(), |
| 9674 | ParamSingleDefaultArgument) |
| 9675 | << HasSecondDefaultArgument; |
| 9676 | break; |
| 9677 | } |
| 9678 | |
| 9679 | assert(HasFirstDefaultArgument && HasSecondDefaultArgument && |
| 9680 | "Expecting default arguments."); |
| 9681 | |
| 9682 | ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(), |
| 9683 | ParamDifferentDefaultArgument); |
| 9684 | ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(), |
| 9685 | ParamDifferentDefaultArgument); |
| 9686 | |
| 9687 | break; |
| 9688 | } |
| 9689 | case Decl::TemplateTemplateParm: { |
| 9690 | const auto *FirstParam = cast<TemplateTemplateParmDecl>(FirstDecl); |
| 9691 | const auto *SecondParam = |
| 9692 | cast<TemplateTemplateParmDecl>(SecondDecl); |
| 9693 | const bool HasFirstDefaultArgument = |
| 9694 | FirstParam->hasDefaultArgument() && |
| 9695 | !FirstParam->defaultArgumentWasInherited(); |
| 9696 | const bool HasSecondDefaultArgument = |
| 9697 | SecondParam->hasDefaultArgument() && |
| 9698 | !SecondParam->defaultArgumentWasInherited(); |
| 9699 | |
| 9700 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 9701 | ODRDiagError(FirstDecl->getLocation(), |
| 9702 | FirstDecl->getSourceRange(), |
| 9703 | ParamSingleDefaultArgument) |
| 9704 | << HasFirstDefaultArgument; |
| 9705 | ODRDiagNote(SecondDecl->getLocation(), |
| 9706 | SecondDecl->getSourceRange(), |
| 9707 | ParamSingleDefaultArgument) |
| 9708 | << HasSecondDefaultArgument; |
| 9709 | break; |
| 9710 | } |
| 9711 | |
| 9712 | assert(HasFirstDefaultArgument && HasSecondDefaultArgument && |
| 9713 | "Expecting default arguments."); |
| 9714 | |
| 9715 | ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(), |
| 9716 | ParamDifferentDefaultArgument); |
| 9717 | ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(), |
| 9718 | ParamDifferentDefaultArgument); |
| 9719 | |
| 9720 | break; |
| 9721 | } |
| 9722 | } |
| 9723 | |
| 9724 | break; |
| 9725 | } |
| 9726 | |
| 9727 | if (FirstIt != FirstEnd) { |
| 9728 | Diagnosed = true; |
| 9729 | break; |
| 9730 | } |
| 9731 | } |
| 9732 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9733 | DeclHashes FirstHashes; |
| 9734 | DeclHashes SecondHashes; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9735 | |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9736 | auto PopulateHashes = [&ComputeSubDeclODRHash, FirstRecord]( |
| 9737 | DeclHashes &Hashes, CXXRecordDecl *Record) { |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9738 | for (auto *D : Record->decls()) { |
| 9739 | // Due to decl merging, the first CXXRecordDecl is the parent of |
| 9740 | // Decls in both records. |
| 9741 | if (!ODRHash::isWhitelistedDecl(D, FirstRecord)) |
| 9742 | continue; |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9743 | Hashes.emplace_back(D, ComputeSubDeclODRHash(D)); |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9744 | } |
| 9745 | }; |
| 9746 | PopulateHashes(FirstHashes, FirstRecord); |
| 9747 | PopulateHashes(SecondHashes, SecondRecord); |
| 9748 | |
| 9749 | // Used with err_module_odr_violation_mismatch_decl and |
| 9750 | // note_module_odr_violation_mismatch_decl |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 9751 | // This list should be the same Decl's as in ODRHash::isWhiteListedDecl |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9752 | enum { |
| 9753 | EndOfClass, |
| 9754 | PublicSpecifer, |
| 9755 | PrivateSpecifer, |
| 9756 | ProtectedSpecifer, |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9757 | StaticAssert, |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9758 | Field, |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9759 | CXXMethod, |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 9760 | TypeAlias, |
| 9761 | TypeDef, |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9762 | Var, |
Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 9763 | Friend, |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9764 | Other |
| 9765 | } FirstDiffType = Other, |
| 9766 | SecondDiffType = Other; |
| 9767 | |
| 9768 | auto DifferenceSelector = [](Decl *D) { |
| 9769 | assert(D && "valid Decl required"); |
| 9770 | switch (D->getKind()) { |
| 9771 | default: |
| 9772 | return Other; |
| 9773 | case Decl::AccessSpec: |
| 9774 | switch (D->getAccess()) { |
| 9775 | case AS_public: |
| 9776 | return PublicSpecifer; |
| 9777 | case AS_private: |
| 9778 | return PrivateSpecifer; |
| 9779 | case AS_protected: |
| 9780 | return ProtectedSpecifer; |
| 9781 | case AS_none: |
Simon Pilgrim | eeb1b30 | 2017-02-22 13:21:24 +0000 | [diff] [blame] | 9782 | break; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9783 | } |
Simon Pilgrim | eeb1b30 | 2017-02-22 13:21:24 +0000 | [diff] [blame] | 9784 | llvm_unreachable("Invalid access specifier"); |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9785 | case Decl::StaticAssert: |
| 9786 | return StaticAssert; |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9787 | case Decl::Field: |
| 9788 | return Field; |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9789 | case Decl::CXXMethod: |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 9790 | case Decl::CXXConstructor: |
| 9791 | case Decl::CXXDestructor: |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9792 | return CXXMethod; |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 9793 | case Decl::TypeAlias: |
| 9794 | return TypeAlias; |
| 9795 | case Decl::Typedef: |
| 9796 | return TypeDef; |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9797 | case Decl::Var: |
| 9798 | return Var; |
Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 9799 | case Decl::Friend: |
| 9800 | return Friend; |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9801 | } |
| 9802 | }; |
| 9803 | |
| 9804 | Decl *FirstDecl = nullptr; |
| 9805 | Decl *SecondDecl = nullptr; |
| 9806 | auto FirstIt = FirstHashes.begin(); |
| 9807 | auto SecondIt = SecondHashes.begin(); |
| 9808 | |
| 9809 | // If there is a diagnoseable difference, FirstDiffType and |
| 9810 | // SecondDiffType will not be Other and FirstDecl and SecondDecl will be |
| 9811 | // filled in if not EndOfClass. |
| 9812 | while (FirstIt != FirstHashes.end() || SecondIt != SecondHashes.end()) { |
Benjamin Kramer | 6f224d2 | 2017-02-22 10:19:45 +0000 | [diff] [blame] | 9813 | if (FirstIt != FirstHashes.end() && SecondIt != SecondHashes.end() && |
| 9814 | FirstIt->second == SecondIt->second) { |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9815 | ++FirstIt; |
| 9816 | ++SecondIt; |
| 9817 | continue; |
Richard Trieu | dc4cb02 | 2017-02-17 07:19:24 +0000 | [diff] [blame] | 9818 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9819 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9820 | FirstDecl = FirstIt == FirstHashes.end() ? nullptr : FirstIt->first; |
| 9821 | SecondDecl = SecondIt == SecondHashes.end() ? nullptr : SecondIt->first; |
| 9822 | |
| 9823 | FirstDiffType = FirstDecl ? DifferenceSelector(FirstDecl) : EndOfClass; |
| 9824 | SecondDiffType = |
| 9825 | SecondDecl ? DifferenceSelector(SecondDecl) : EndOfClass; |
| 9826 | |
| 9827 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9828 | } |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9829 | |
| 9830 | if (FirstDiffType == Other || SecondDiffType == Other) { |
| 9831 | // Reaching this point means an unexpected Decl was encountered |
| 9832 | // or no difference was detected. This causes a generic error |
| 9833 | // message to be emitted. |
| 9834 | Diag(FirstRecord->getLocation(), |
| 9835 | diag::err_module_odr_violation_different_definitions) |
| 9836 | << FirstRecord << FirstModule.empty() << FirstModule; |
| 9837 | |
Richard Trieu | ca48d36 | 2017-06-21 01:43:13 +0000 | [diff] [blame] | 9838 | if (FirstDecl) { |
| 9839 | Diag(FirstDecl->getLocation(), diag::note_first_module_difference) |
| 9840 | << FirstRecord << FirstDecl->getSourceRange(); |
| 9841 | } |
| 9842 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9843 | Diag(SecondRecord->getLocation(), |
| 9844 | diag::note_module_odr_violation_different_definitions) |
| 9845 | << SecondModule; |
Richard Trieu | ca48d36 | 2017-06-21 01:43:13 +0000 | [diff] [blame] | 9846 | |
| 9847 | if (SecondDecl) { |
| 9848 | Diag(SecondDecl->getLocation(), diag::note_second_module_difference) |
| 9849 | << SecondDecl->getSourceRange(); |
| 9850 | } |
| 9851 | |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9852 | Diagnosed = true; |
| 9853 | break; |
| 9854 | } |
| 9855 | |
| 9856 | if (FirstDiffType != SecondDiffType) { |
| 9857 | SourceLocation FirstLoc; |
| 9858 | SourceRange FirstRange; |
| 9859 | if (FirstDiffType == EndOfClass) { |
| 9860 | FirstLoc = FirstRecord->getBraceRange().getEnd(); |
| 9861 | } else { |
| 9862 | FirstLoc = FirstIt->first->getLocation(); |
| 9863 | FirstRange = FirstIt->first->getSourceRange(); |
| 9864 | } |
| 9865 | Diag(FirstLoc, diag::err_module_odr_violation_mismatch_decl) |
| 9866 | << FirstRecord << FirstModule.empty() << FirstModule << FirstRange |
| 9867 | << FirstDiffType; |
| 9868 | |
| 9869 | SourceLocation SecondLoc; |
| 9870 | SourceRange SecondRange; |
| 9871 | if (SecondDiffType == EndOfClass) { |
| 9872 | SecondLoc = SecondRecord->getBraceRange().getEnd(); |
| 9873 | } else { |
| 9874 | SecondLoc = SecondDecl->getLocation(); |
| 9875 | SecondRange = SecondDecl->getSourceRange(); |
| 9876 | } |
| 9877 | Diag(SecondLoc, diag::note_module_odr_violation_mismatch_decl) |
| 9878 | << SecondModule << SecondRange << SecondDiffType; |
| 9879 | Diagnosed = true; |
| 9880 | break; |
| 9881 | } |
| 9882 | |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9883 | assert(FirstDiffType == SecondDiffType); |
| 9884 | |
| 9885 | // Used with err_module_odr_violation_mismatch_decl_diff and |
| 9886 | // note_module_odr_violation_mismatch_decl_diff |
| 9887 | enum ODRDeclDifference{ |
| 9888 | StaticAssertCondition, |
| 9889 | StaticAssertMessage, |
| 9890 | StaticAssertOnlyMessage, |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 9891 | FieldName, |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 9892 | FieldTypeName, |
Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 9893 | FieldSingleBitField, |
Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 9894 | FieldDifferentWidthBitField, |
| 9895 | FieldSingleMutable, |
| 9896 | FieldSingleInitializer, |
| 9897 | FieldDifferentInitializers, |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 9898 | MethodName, |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 9899 | MethodDeleted, |
| 9900 | MethodVirtual, |
| 9901 | MethodStatic, |
| 9902 | MethodVolatile, |
| 9903 | MethodConst, |
| 9904 | MethodInline, |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 9905 | MethodNumberParameters, |
| 9906 | MethodParameterType, |
| 9907 | MethodParameterName, |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9908 | MethodParameterSingleDefaultArgument, |
| 9909 | MethodParameterDifferentDefaultArgument, |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 9910 | TypedefName, |
| 9911 | TypedefType, |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 9912 | VarName, |
| 9913 | VarType, |
| 9914 | VarSingleInitializer, |
| 9915 | VarDifferentInitializer, |
| 9916 | VarConstexpr, |
Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 9917 | FriendTypeFunction, |
| 9918 | FriendType, |
| 9919 | FriendFunction, |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9920 | }; |
| 9921 | |
| 9922 | // These lambdas have the common portions of the ODR diagnostics. This |
| 9923 | // has the same return as Diag(), so addition parameters can be passed |
| 9924 | // in with operator<< |
| 9925 | auto ODRDiagError = [FirstRecord, &FirstModule, this]( |
| 9926 | SourceLocation Loc, SourceRange Range, ODRDeclDifference DiffType) { |
| 9927 | return Diag(Loc, diag::err_module_odr_violation_mismatch_decl_diff) |
| 9928 | << FirstRecord << FirstModule.empty() << FirstModule << Range |
| 9929 | << DiffType; |
| 9930 | }; |
| 9931 | auto ODRDiagNote = [&SecondModule, this]( |
| 9932 | SourceLocation Loc, SourceRange Range, ODRDeclDifference DiffType) { |
| 9933 | return Diag(Loc, diag::note_module_odr_violation_mismatch_decl_diff) |
| 9934 | << SecondModule << Range << DiffType; |
| 9935 | }; |
| 9936 | |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 9937 | switch (FirstDiffType) { |
| 9938 | case Other: |
| 9939 | case EndOfClass: |
| 9940 | case PublicSpecifer: |
| 9941 | case PrivateSpecifer: |
| 9942 | case ProtectedSpecifer: |
| 9943 | llvm_unreachable("Invalid diff type"); |
| 9944 | |
| 9945 | case StaticAssert: { |
| 9946 | StaticAssertDecl *FirstSA = cast<StaticAssertDecl>(FirstDecl); |
| 9947 | StaticAssertDecl *SecondSA = cast<StaticAssertDecl>(SecondDecl); |
| 9948 | |
| 9949 | Expr *FirstExpr = FirstSA->getAssertExpr(); |
| 9950 | Expr *SecondExpr = SecondSA->getAssertExpr(); |
| 9951 | unsigned FirstODRHash = ComputeODRHash(FirstExpr); |
| 9952 | unsigned SecondODRHash = ComputeODRHash(SecondExpr); |
| 9953 | if (FirstODRHash != SecondODRHash) { |
| 9954 | ODRDiagError(FirstExpr->getLocStart(), FirstExpr->getSourceRange(), |
| 9955 | StaticAssertCondition); |
| 9956 | ODRDiagNote(SecondExpr->getLocStart(), |
| 9957 | SecondExpr->getSourceRange(), StaticAssertCondition); |
| 9958 | Diagnosed = true; |
| 9959 | break; |
| 9960 | } |
| 9961 | |
| 9962 | StringLiteral *FirstStr = FirstSA->getMessage(); |
| 9963 | StringLiteral *SecondStr = SecondSA->getMessage(); |
| 9964 | assert((FirstStr || SecondStr) && "Both messages cannot be empty"); |
| 9965 | if ((FirstStr && !SecondStr) || (!FirstStr && SecondStr)) { |
| 9966 | SourceLocation FirstLoc, SecondLoc; |
| 9967 | SourceRange FirstRange, SecondRange; |
| 9968 | if (FirstStr) { |
| 9969 | FirstLoc = FirstStr->getLocStart(); |
| 9970 | FirstRange = FirstStr->getSourceRange(); |
| 9971 | } else { |
| 9972 | FirstLoc = FirstSA->getLocStart(); |
| 9973 | FirstRange = FirstSA->getSourceRange(); |
| 9974 | } |
| 9975 | if (SecondStr) { |
| 9976 | SecondLoc = SecondStr->getLocStart(); |
| 9977 | SecondRange = SecondStr->getSourceRange(); |
| 9978 | } else { |
| 9979 | SecondLoc = SecondSA->getLocStart(); |
| 9980 | SecondRange = SecondSA->getSourceRange(); |
| 9981 | } |
| 9982 | ODRDiagError(FirstLoc, FirstRange, StaticAssertOnlyMessage) |
| 9983 | << (FirstStr == nullptr); |
| 9984 | ODRDiagNote(SecondLoc, SecondRange, StaticAssertOnlyMessage) |
| 9985 | << (SecondStr == nullptr); |
| 9986 | Diagnosed = true; |
| 9987 | break; |
| 9988 | } |
| 9989 | |
| 9990 | if (FirstStr && SecondStr && |
| 9991 | FirstStr->getString() != SecondStr->getString()) { |
| 9992 | ODRDiagError(FirstStr->getLocStart(), FirstStr->getSourceRange(), |
| 9993 | StaticAssertMessage); |
| 9994 | ODRDiagNote(SecondStr->getLocStart(), SecondStr->getSourceRange(), |
| 9995 | StaticAssertMessage); |
| 9996 | Diagnosed = true; |
| 9997 | break; |
| 9998 | } |
| 9999 | break; |
| 10000 | } |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 10001 | case Field: { |
| 10002 | FieldDecl *FirstField = cast<FieldDecl>(FirstDecl); |
| 10003 | FieldDecl *SecondField = cast<FieldDecl>(SecondDecl); |
| 10004 | IdentifierInfo *FirstII = FirstField->getIdentifier(); |
| 10005 | IdentifierInfo *SecondII = SecondField->getIdentifier(); |
| 10006 | if (FirstII->getName() != SecondII->getName()) { |
| 10007 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 10008 | FieldName) |
| 10009 | << FirstII; |
| 10010 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 10011 | FieldName) |
| 10012 | << SecondII; |
| 10013 | |
| 10014 | Diagnosed = true; |
| 10015 | break; |
| 10016 | } |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 10017 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 10018 | assert(getContext().hasSameType(FirstField->getType(), |
| 10019 | SecondField->getType())); |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 10020 | |
| 10021 | QualType FirstType = FirstField->getType(); |
| 10022 | QualType SecondType = SecondField->getType(); |
Richard Trieu | ce81b19 | 2017-05-17 03:23:35 +0000 | [diff] [blame] | 10023 | if (ComputeQualTypeODRHash(FirstType) != |
| 10024 | ComputeQualTypeODRHash(SecondType)) { |
Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 10025 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 10026 | FieldTypeName) |
| 10027 | << FirstII << FirstType; |
| 10028 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 10029 | FieldTypeName) |
| 10030 | << SecondII << SecondType; |
| 10031 | |
| 10032 | Diagnosed = true; |
| 10033 | break; |
| 10034 | } |
| 10035 | |
Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 10036 | const bool IsFirstBitField = FirstField->isBitField(); |
| 10037 | const bool IsSecondBitField = SecondField->isBitField(); |
| 10038 | if (IsFirstBitField != IsSecondBitField) { |
| 10039 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 10040 | FieldSingleBitField) |
| 10041 | << FirstII << IsFirstBitField; |
| 10042 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 10043 | FieldSingleBitField) |
| 10044 | << SecondII << IsSecondBitField; |
| 10045 | Diagnosed = true; |
| 10046 | break; |
| 10047 | } |
| 10048 | |
| 10049 | if (IsFirstBitField && IsSecondBitField) { |
| 10050 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 10051 | FieldDifferentWidthBitField) |
| 10052 | << FirstII << FirstField->getBitWidth()->getSourceRange(); |
| 10053 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 10054 | FieldDifferentWidthBitField) |
| 10055 | << SecondII << SecondField->getBitWidth()->getSourceRange(); |
| 10056 | Diagnosed = true; |
| 10057 | break; |
| 10058 | } |
| 10059 | |
Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 10060 | const bool IsFirstMutable = FirstField->isMutable(); |
| 10061 | const bool IsSecondMutable = SecondField->isMutable(); |
| 10062 | if (IsFirstMutable != IsSecondMutable) { |
| 10063 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 10064 | FieldSingleMutable) |
| 10065 | << FirstII << IsFirstMutable; |
| 10066 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 10067 | FieldSingleMutable) |
| 10068 | << SecondII << IsSecondMutable; |
| 10069 | Diagnosed = true; |
| 10070 | break; |
| 10071 | } |
| 10072 | |
| 10073 | const Expr *FirstInitializer = FirstField->getInClassInitializer(); |
| 10074 | const Expr *SecondInitializer = SecondField->getInClassInitializer(); |
| 10075 | if ((!FirstInitializer && SecondInitializer) || |
| 10076 | (FirstInitializer && !SecondInitializer)) { |
| 10077 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 10078 | FieldSingleInitializer) |
| 10079 | << FirstII << (FirstInitializer != nullptr); |
| 10080 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 10081 | FieldSingleInitializer) |
| 10082 | << SecondII << (SecondInitializer != nullptr); |
| 10083 | Diagnosed = true; |
| 10084 | break; |
| 10085 | } |
| 10086 | |
| 10087 | if (FirstInitializer && SecondInitializer) { |
| 10088 | unsigned FirstInitHash = ComputeODRHash(FirstInitializer); |
| 10089 | unsigned SecondInitHash = ComputeODRHash(SecondInitializer); |
| 10090 | if (FirstInitHash != SecondInitHash) { |
| 10091 | ODRDiagError(FirstField->getLocation(), |
| 10092 | FirstField->getSourceRange(), |
| 10093 | FieldDifferentInitializers) |
| 10094 | << FirstII << FirstInitializer->getSourceRange(); |
| 10095 | ODRDiagNote(SecondField->getLocation(), |
| 10096 | SecondField->getSourceRange(), |
| 10097 | FieldDifferentInitializers) |
| 10098 | << SecondII << SecondInitializer->getSourceRange(); |
| 10099 | Diagnosed = true; |
| 10100 | break; |
| 10101 | } |
| 10102 | } |
| 10103 | |
Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 10104 | break; |
| 10105 | } |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10106 | case CXXMethod: { |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10107 | enum { |
| 10108 | DiagMethod, |
| 10109 | DiagConstructor, |
| 10110 | DiagDestructor, |
| 10111 | } FirstMethodType, |
| 10112 | SecondMethodType; |
| 10113 | auto GetMethodTypeForDiagnostics = [](const CXXMethodDecl* D) { |
| 10114 | if (isa<CXXConstructorDecl>(D)) return DiagConstructor; |
| 10115 | if (isa<CXXDestructorDecl>(D)) return DiagDestructor; |
| 10116 | return DiagMethod; |
| 10117 | }; |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10118 | const CXXMethodDecl *FirstMethod = cast<CXXMethodDecl>(FirstDecl); |
| 10119 | const CXXMethodDecl *SecondMethod = cast<CXXMethodDecl>(SecondDecl); |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10120 | FirstMethodType = GetMethodTypeForDiagnostics(FirstMethod); |
| 10121 | SecondMethodType = GetMethodTypeForDiagnostics(SecondMethod); |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10122 | auto FirstName = FirstMethod->getDeclName(); |
| 10123 | auto SecondName = SecondMethod->getDeclName(); |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10124 | if (FirstMethodType != SecondMethodType || FirstName != SecondName) { |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10125 | ODRDiagError(FirstMethod->getLocation(), |
| 10126 | FirstMethod->getSourceRange(), MethodName) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10127 | << FirstMethodType << FirstName; |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10128 | ODRDiagNote(SecondMethod->getLocation(), |
| 10129 | SecondMethod->getSourceRange(), MethodName) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10130 | << SecondMethodType << SecondName; |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10131 | |
| 10132 | Diagnosed = true; |
| 10133 | break; |
| 10134 | } |
| 10135 | |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10136 | const bool FirstDeleted = FirstMethod->isDeleted(); |
| 10137 | const bool SecondDeleted = SecondMethod->isDeleted(); |
| 10138 | if (FirstDeleted != SecondDeleted) { |
| 10139 | ODRDiagError(FirstMethod->getLocation(), |
| 10140 | FirstMethod->getSourceRange(), MethodDeleted) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10141 | << FirstMethodType << FirstName << FirstDeleted; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10142 | |
| 10143 | ODRDiagNote(SecondMethod->getLocation(), |
| 10144 | SecondMethod->getSourceRange(), MethodDeleted) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10145 | << SecondMethodType << SecondName << SecondDeleted; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10146 | Diagnosed = true; |
| 10147 | break; |
| 10148 | } |
| 10149 | |
| 10150 | const bool FirstVirtual = FirstMethod->isVirtualAsWritten(); |
| 10151 | const bool SecondVirtual = SecondMethod->isVirtualAsWritten(); |
| 10152 | const bool FirstPure = FirstMethod->isPure(); |
| 10153 | const bool SecondPure = SecondMethod->isPure(); |
| 10154 | if ((FirstVirtual || SecondVirtual) && |
| 10155 | (FirstVirtual != SecondVirtual || FirstPure != SecondPure)) { |
| 10156 | ODRDiagError(FirstMethod->getLocation(), |
| 10157 | FirstMethod->getSourceRange(), MethodVirtual) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10158 | << FirstMethodType << FirstName << FirstPure << FirstVirtual; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10159 | ODRDiagNote(SecondMethod->getLocation(), |
| 10160 | SecondMethod->getSourceRange(), MethodVirtual) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10161 | << SecondMethodType << SecondName << SecondPure << SecondVirtual; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10162 | Diagnosed = true; |
| 10163 | break; |
| 10164 | } |
| 10165 | |
| 10166 | // CXXMethodDecl::isStatic uses the canonical Decl. With Decl merging, |
| 10167 | // FirstDecl is the canonical Decl of SecondDecl, so the storage |
| 10168 | // class needs to be checked instead. |
| 10169 | const auto FirstStorage = FirstMethod->getStorageClass(); |
| 10170 | const auto SecondStorage = SecondMethod->getStorageClass(); |
| 10171 | const bool FirstStatic = FirstStorage == SC_Static; |
| 10172 | const bool SecondStatic = SecondStorage == SC_Static; |
| 10173 | if (FirstStatic != SecondStatic) { |
| 10174 | ODRDiagError(FirstMethod->getLocation(), |
| 10175 | FirstMethod->getSourceRange(), MethodStatic) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10176 | << FirstMethodType << FirstName << FirstStatic; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10177 | ODRDiagNote(SecondMethod->getLocation(), |
| 10178 | SecondMethod->getSourceRange(), MethodStatic) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10179 | << SecondMethodType << SecondName << SecondStatic; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10180 | Diagnosed = true; |
| 10181 | break; |
| 10182 | } |
| 10183 | |
| 10184 | const bool FirstVolatile = FirstMethod->isVolatile(); |
| 10185 | const bool SecondVolatile = SecondMethod->isVolatile(); |
| 10186 | if (FirstVolatile != SecondVolatile) { |
| 10187 | ODRDiagError(FirstMethod->getLocation(), |
| 10188 | FirstMethod->getSourceRange(), MethodVolatile) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10189 | << FirstMethodType << FirstName << FirstVolatile; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10190 | ODRDiagNote(SecondMethod->getLocation(), |
| 10191 | SecondMethod->getSourceRange(), MethodVolatile) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10192 | << SecondMethodType << SecondName << SecondVolatile; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10193 | Diagnosed = true; |
| 10194 | break; |
| 10195 | } |
| 10196 | |
| 10197 | const bool FirstConst = FirstMethod->isConst(); |
| 10198 | const bool SecondConst = SecondMethod->isConst(); |
| 10199 | if (FirstConst != SecondConst) { |
| 10200 | ODRDiagError(FirstMethod->getLocation(), |
| 10201 | FirstMethod->getSourceRange(), MethodConst) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10202 | << FirstMethodType << FirstName << FirstConst; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10203 | ODRDiagNote(SecondMethod->getLocation(), |
| 10204 | SecondMethod->getSourceRange(), MethodConst) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10205 | << SecondMethodType << SecondName << SecondConst; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10206 | Diagnosed = true; |
| 10207 | break; |
| 10208 | } |
| 10209 | |
| 10210 | const bool FirstInline = FirstMethod->isInlineSpecified(); |
| 10211 | const bool SecondInline = SecondMethod->isInlineSpecified(); |
| 10212 | if (FirstInline != SecondInline) { |
| 10213 | ODRDiagError(FirstMethod->getLocation(), |
| 10214 | FirstMethod->getSourceRange(), MethodInline) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10215 | << FirstMethodType << FirstName << FirstInline; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10216 | ODRDiagNote(SecondMethod->getLocation(), |
| 10217 | SecondMethod->getSourceRange(), MethodInline) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10218 | << SecondMethodType << SecondName << SecondInline; |
Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10219 | Diagnosed = true; |
| 10220 | break; |
| 10221 | } |
| 10222 | |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10223 | const unsigned FirstNumParameters = FirstMethod->param_size(); |
| 10224 | const unsigned SecondNumParameters = SecondMethod->param_size(); |
| 10225 | if (FirstNumParameters != SecondNumParameters) { |
| 10226 | ODRDiagError(FirstMethod->getLocation(), |
| 10227 | FirstMethod->getSourceRange(), MethodNumberParameters) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10228 | << FirstMethodType << FirstName << FirstNumParameters; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10229 | ODRDiagNote(SecondMethod->getLocation(), |
| 10230 | SecondMethod->getSourceRange(), MethodNumberParameters) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10231 | << SecondMethodType << SecondName << SecondNumParameters; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10232 | Diagnosed = true; |
| 10233 | break; |
| 10234 | } |
| 10235 | |
| 10236 | // Need this status boolean to know when break out of the switch. |
| 10237 | bool ParameterMismatch = false; |
| 10238 | for (unsigned I = 0; I < FirstNumParameters; ++I) { |
| 10239 | const ParmVarDecl *FirstParam = FirstMethod->getParamDecl(I); |
| 10240 | const ParmVarDecl *SecondParam = SecondMethod->getParamDecl(I); |
| 10241 | |
| 10242 | QualType FirstParamType = FirstParam->getType(); |
| 10243 | QualType SecondParamType = SecondParam->getType(); |
| 10244 | if (FirstParamType != SecondParamType && |
| 10245 | ComputeQualTypeODRHash(FirstParamType) != |
| 10246 | ComputeQualTypeODRHash(SecondParamType)) { |
| 10247 | if (const DecayedType *ParamDecayedType = |
| 10248 | FirstParamType->getAs<DecayedType>()) { |
| 10249 | ODRDiagError(FirstMethod->getLocation(), |
| 10250 | FirstMethod->getSourceRange(), MethodParameterType) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10251 | << FirstMethodType << FirstName << (I + 1) << FirstParamType |
| 10252 | << true << ParamDecayedType->getOriginalType(); |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10253 | } else { |
| 10254 | ODRDiagError(FirstMethod->getLocation(), |
| 10255 | FirstMethod->getSourceRange(), MethodParameterType) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10256 | << FirstMethodType << FirstName << (I + 1) << FirstParamType |
| 10257 | << false; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10258 | } |
| 10259 | |
| 10260 | if (const DecayedType *ParamDecayedType = |
| 10261 | SecondParamType->getAs<DecayedType>()) { |
| 10262 | ODRDiagNote(SecondMethod->getLocation(), |
| 10263 | SecondMethod->getSourceRange(), MethodParameterType) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10264 | << SecondMethodType << SecondName << (I + 1) |
| 10265 | << SecondParamType << true |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10266 | << ParamDecayedType->getOriginalType(); |
| 10267 | } else { |
| 10268 | ODRDiagNote(SecondMethod->getLocation(), |
| 10269 | SecondMethod->getSourceRange(), MethodParameterType) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10270 | << SecondMethodType << SecondName << (I + 1) |
| 10271 | << SecondParamType << false; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10272 | } |
| 10273 | ParameterMismatch = true; |
| 10274 | break; |
| 10275 | } |
| 10276 | |
| 10277 | DeclarationName FirstParamName = FirstParam->getDeclName(); |
| 10278 | DeclarationName SecondParamName = SecondParam->getDeclName(); |
| 10279 | if (FirstParamName != SecondParamName) { |
| 10280 | ODRDiagError(FirstMethod->getLocation(), |
| 10281 | FirstMethod->getSourceRange(), MethodParameterName) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10282 | << FirstMethodType << FirstName << (I + 1) << FirstParamName; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10283 | ODRDiagNote(SecondMethod->getLocation(), |
| 10284 | SecondMethod->getSourceRange(), MethodParameterName) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10285 | << SecondMethodType << SecondName << (I + 1) << SecondParamName; |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10286 | ParameterMismatch = true; |
| 10287 | break; |
| 10288 | } |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10289 | |
| 10290 | const Expr *FirstInit = FirstParam->getInit(); |
| 10291 | const Expr *SecondInit = SecondParam->getInit(); |
| 10292 | if ((FirstInit == nullptr) != (SecondInit == nullptr)) { |
| 10293 | ODRDiagError(FirstMethod->getLocation(), |
| 10294 | FirstMethod->getSourceRange(), |
| 10295 | MethodParameterSingleDefaultArgument) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10296 | << FirstMethodType << FirstName << (I + 1) |
| 10297 | << (FirstInit == nullptr) |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10298 | << (FirstInit ? FirstInit->getSourceRange() : SourceRange()); |
| 10299 | ODRDiagNote(SecondMethod->getLocation(), |
| 10300 | SecondMethod->getSourceRange(), |
| 10301 | MethodParameterSingleDefaultArgument) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10302 | << SecondMethodType << SecondName << (I + 1) |
| 10303 | << (SecondInit == nullptr) |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10304 | << (SecondInit ? SecondInit->getSourceRange() : SourceRange()); |
| 10305 | ParameterMismatch = true; |
| 10306 | break; |
| 10307 | } |
| 10308 | |
| 10309 | if (FirstInit && SecondInit && |
| 10310 | ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) { |
| 10311 | ODRDiagError(FirstMethod->getLocation(), |
| 10312 | FirstMethod->getSourceRange(), |
| 10313 | MethodParameterDifferentDefaultArgument) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10314 | << FirstMethodType << FirstName << (I + 1) |
| 10315 | << FirstInit->getSourceRange(); |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10316 | ODRDiagNote(SecondMethod->getLocation(), |
| 10317 | SecondMethod->getSourceRange(), |
| 10318 | MethodParameterDifferentDefaultArgument) |
Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10319 | << SecondMethodType << SecondName << (I + 1) |
| 10320 | << SecondInit->getSourceRange(); |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10321 | ParameterMismatch = true; |
| 10322 | break; |
| 10323 | |
| 10324 | } |
Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10325 | } |
| 10326 | |
| 10327 | if (ParameterMismatch) { |
| 10328 | Diagnosed = true; |
| 10329 | break; |
| 10330 | } |
| 10331 | |
Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10332 | break; |
| 10333 | } |
Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 10334 | case TypeAlias: |
| 10335 | case TypeDef: { |
| 10336 | TypedefNameDecl *FirstTD = cast<TypedefNameDecl>(FirstDecl); |
| 10337 | TypedefNameDecl *SecondTD = cast<TypedefNameDecl>(SecondDecl); |
| 10338 | auto FirstName = FirstTD->getDeclName(); |
| 10339 | auto SecondName = SecondTD->getDeclName(); |
| 10340 | if (FirstName != SecondName) { |
| 10341 | ODRDiagError(FirstTD->getLocation(), FirstTD->getSourceRange(), |
| 10342 | TypedefName) |
| 10343 | << (FirstDiffType == TypeAlias) << FirstName; |
| 10344 | ODRDiagNote(SecondTD->getLocation(), SecondTD->getSourceRange(), |
| 10345 | TypedefName) |
| 10346 | << (FirstDiffType == TypeAlias) << SecondName; |
| 10347 | Diagnosed = true; |
| 10348 | break; |
| 10349 | } |
| 10350 | |
| 10351 | QualType FirstType = FirstTD->getUnderlyingType(); |
| 10352 | QualType SecondType = SecondTD->getUnderlyingType(); |
| 10353 | if (ComputeQualTypeODRHash(FirstType) != |
| 10354 | ComputeQualTypeODRHash(SecondType)) { |
| 10355 | ODRDiagError(FirstTD->getLocation(), FirstTD->getSourceRange(), |
| 10356 | TypedefType) |
| 10357 | << (FirstDiffType == TypeAlias) << FirstName << FirstType; |
| 10358 | ODRDiagNote(SecondTD->getLocation(), SecondTD->getSourceRange(), |
| 10359 | TypedefType) |
| 10360 | << (FirstDiffType == TypeAlias) << SecondName << SecondType; |
| 10361 | Diagnosed = true; |
| 10362 | break; |
| 10363 | } |
| 10364 | break; |
| 10365 | } |
Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10366 | case Var: { |
| 10367 | VarDecl *FirstVD = cast<VarDecl>(FirstDecl); |
| 10368 | VarDecl *SecondVD = cast<VarDecl>(SecondDecl); |
| 10369 | auto FirstName = FirstVD->getDeclName(); |
| 10370 | auto SecondName = SecondVD->getDeclName(); |
| 10371 | if (FirstName != SecondName) { |
| 10372 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 10373 | VarName) |
| 10374 | << FirstName; |
| 10375 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 10376 | VarName) |
| 10377 | << SecondName; |
| 10378 | Diagnosed = true; |
| 10379 | break; |
| 10380 | } |
| 10381 | |
| 10382 | QualType FirstType = FirstVD->getType(); |
| 10383 | QualType SecondType = SecondVD->getType(); |
| 10384 | if (ComputeQualTypeODRHash(FirstType) != |
| 10385 | ComputeQualTypeODRHash(SecondType)) { |
| 10386 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 10387 | VarType) |
| 10388 | << FirstName << FirstType; |
| 10389 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 10390 | VarType) |
| 10391 | << SecondName << SecondType; |
| 10392 | Diagnosed = true; |
| 10393 | break; |
| 10394 | } |
| 10395 | |
| 10396 | const Expr *FirstInit = FirstVD->getInit(); |
| 10397 | const Expr *SecondInit = SecondVD->getInit(); |
| 10398 | if ((FirstInit == nullptr) != (SecondInit == nullptr)) { |
| 10399 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 10400 | VarSingleInitializer) |
| 10401 | << FirstName << (FirstInit == nullptr) |
| 10402 | << (FirstInit ? FirstInit->getSourceRange(): SourceRange()); |
| 10403 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 10404 | VarSingleInitializer) |
| 10405 | << SecondName << (SecondInit == nullptr) |
| 10406 | << (SecondInit ? SecondInit->getSourceRange() : SourceRange()); |
| 10407 | Diagnosed = true; |
| 10408 | break; |
| 10409 | } |
| 10410 | |
| 10411 | if (FirstInit && SecondInit && |
| 10412 | ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) { |
| 10413 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 10414 | VarDifferentInitializer) |
| 10415 | << FirstName << FirstInit->getSourceRange(); |
| 10416 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 10417 | VarDifferentInitializer) |
| 10418 | << SecondName << SecondInit->getSourceRange(); |
| 10419 | Diagnosed = true; |
| 10420 | break; |
| 10421 | } |
| 10422 | |
| 10423 | const bool FirstIsConstexpr = FirstVD->isConstexpr(); |
| 10424 | const bool SecondIsConstexpr = SecondVD->isConstexpr(); |
| 10425 | if (FirstIsConstexpr != SecondIsConstexpr) { |
| 10426 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 10427 | VarConstexpr) |
| 10428 | << FirstName << FirstIsConstexpr; |
| 10429 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 10430 | VarConstexpr) |
| 10431 | << SecondName << SecondIsConstexpr; |
| 10432 | Diagnosed = true; |
| 10433 | break; |
| 10434 | } |
| 10435 | break; |
| 10436 | } |
Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 10437 | case Friend: { |
| 10438 | FriendDecl *FirstFriend = cast<FriendDecl>(FirstDecl); |
| 10439 | FriendDecl *SecondFriend = cast<FriendDecl>(SecondDecl); |
| 10440 | |
| 10441 | NamedDecl *FirstND = FirstFriend->getFriendDecl(); |
| 10442 | NamedDecl *SecondND = SecondFriend->getFriendDecl(); |
| 10443 | |
| 10444 | TypeSourceInfo *FirstTSI = FirstFriend->getFriendType(); |
| 10445 | TypeSourceInfo *SecondTSI = SecondFriend->getFriendType(); |
| 10446 | |
| 10447 | if (FirstND && SecondND) { |
| 10448 | ODRDiagError(FirstFriend->getFriendLoc(), |
| 10449 | FirstFriend->getSourceRange(), FriendFunction) |
| 10450 | << FirstND; |
| 10451 | ODRDiagNote(SecondFriend->getFriendLoc(), |
| 10452 | SecondFriend->getSourceRange(), FriendFunction) |
| 10453 | << SecondND; |
| 10454 | |
| 10455 | Diagnosed = true; |
| 10456 | break; |
| 10457 | } |
| 10458 | |
| 10459 | if (FirstTSI && SecondTSI) { |
| 10460 | QualType FirstFriendType = FirstTSI->getType(); |
| 10461 | QualType SecondFriendType = SecondTSI->getType(); |
| 10462 | assert(ComputeQualTypeODRHash(FirstFriendType) != |
| 10463 | ComputeQualTypeODRHash(SecondFriendType)); |
| 10464 | ODRDiagError(FirstFriend->getFriendLoc(), |
| 10465 | FirstFriend->getSourceRange(), FriendType) |
| 10466 | << FirstFriendType; |
| 10467 | ODRDiagNote(SecondFriend->getFriendLoc(), |
| 10468 | SecondFriend->getSourceRange(), FriendType) |
| 10469 | << SecondFriendType; |
| 10470 | Diagnosed = true; |
| 10471 | break; |
| 10472 | } |
| 10473 | |
| 10474 | ODRDiagError(FirstFriend->getFriendLoc(), FirstFriend->getSourceRange(), |
| 10475 | FriendTypeFunction) |
| 10476 | << (FirstTSI == nullptr); |
| 10477 | ODRDiagNote(SecondFriend->getFriendLoc(), |
| 10478 | SecondFriend->getSourceRange(), FriendTypeFunction) |
| 10479 | << (SecondTSI == nullptr); |
| 10480 | |
| 10481 | Diagnosed = true; |
| 10482 | break; |
| 10483 | } |
Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10484 | } |
| 10485 | |
Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 10486 | if (Diagnosed) |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 10487 | continue; |
| 10488 | |
Richard Trieu | 708859a | 2017-06-08 00:56:21 +0000 | [diff] [blame] | 10489 | Diag(FirstDecl->getLocation(), |
| 10490 | diag::err_module_odr_violation_mismatch_decl_unknown) |
| 10491 | << FirstRecord << FirstModule.empty() << FirstModule << FirstDiffType |
| 10492 | << FirstDecl->getSourceRange(); |
| 10493 | Diag(SecondDecl->getLocation(), |
| 10494 | diag::note_module_odr_violation_mismatch_decl_unknown) |
| 10495 | << SecondModule << FirstDiffType << SecondDecl->getSourceRange(); |
Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 10496 | Diagnosed = true; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 10497 | } |
| 10498 | |
| 10499 | if (!Diagnosed) { |
| 10500 | // All definitions are updates to the same declaration. This happens if a |
| 10501 | // module instantiates the declaration of a class template specialization |
| 10502 | // and two or more other modules instantiate its definition. |
| 10503 | // |
| 10504 | // FIXME: Indicate which modules had instantiations of this definition. |
| 10505 | // FIXME: How can this even happen? |
| 10506 | Diag(Merge.first->getLocation(), |
| 10507 | diag::err_module_odr_violation_different_instantiations) |
| 10508 | << Merge.first; |
| 10509 | } |
| 10510 | } |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 10511 | |
| 10512 | // Issue ODR failures diagnostics for functions. |
| 10513 | for (auto &Merge : FunctionOdrMergeFailures) { |
| 10514 | enum ODRFunctionDifference { |
| 10515 | ReturnType, |
| 10516 | ParameterName, |
| 10517 | ParameterType, |
| 10518 | ParameterSingleDefaultArgument, |
| 10519 | ParameterDifferentDefaultArgument, |
| 10520 | FunctionBody, |
| 10521 | }; |
| 10522 | |
| 10523 | FunctionDecl *FirstFunction = Merge.first; |
| 10524 | std::string FirstModule = getOwningModuleNameForDiagnostic(FirstFunction); |
| 10525 | |
| 10526 | bool Diagnosed = false; |
| 10527 | for (auto &SecondFunction : Merge.second) { |
| 10528 | |
| 10529 | if (FirstFunction == SecondFunction) |
| 10530 | continue; |
| 10531 | |
| 10532 | std::string SecondModule = |
| 10533 | getOwningModuleNameForDiagnostic(SecondFunction); |
| 10534 | |
| 10535 | auto ODRDiagError = [FirstFunction, &FirstModule, |
| 10536 | this](SourceLocation Loc, SourceRange Range, |
| 10537 | ODRFunctionDifference DiffType) { |
| 10538 | return Diag(Loc, diag::err_module_odr_violation_function) |
| 10539 | << FirstFunction << FirstModule.empty() << FirstModule << Range |
| 10540 | << DiffType; |
| 10541 | }; |
| 10542 | auto ODRDiagNote = [&SecondModule, this](SourceLocation Loc, |
| 10543 | SourceRange Range, |
| 10544 | ODRFunctionDifference DiffType) { |
| 10545 | return Diag(Loc, diag::note_module_odr_violation_function) |
| 10546 | << SecondModule << Range << DiffType; |
| 10547 | }; |
| 10548 | |
| 10549 | if (ComputeQualTypeODRHash(FirstFunction->getReturnType()) != |
| 10550 | ComputeQualTypeODRHash(SecondFunction->getReturnType())) { |
| 10551 | ODRDiagError(FirstFunction->getReturnTypeSourceRange().getBegin(), |
| 10552 | FirstFunction->getReturnTypeSourceRange(), ReturnType) |
| 10553 | << FirstFunction->getReturnType(); |
| 10554 | ODRDiagNote(SecondFunction->getReturnTypeSourceRange().getBegin(), |
| 10555 | SecondFunction->getReturnTypeSourceRange(), ReturnType) |
| 10556 | << SecondFunction->getReturnType(); |
| 10557 | Diagnosed = true; |
| 10558 | break; |
| 10559 | } |
| 10560 | |
| 10561 | assert(FirstFunction->param_size() == SecondFunction->param_size() && |
| 10562 | "Merged functions with different number of parameters"); |
| 10563 | |
| 10564 | auto ParamSize = FirstFunction->param_size(); |
| 10565 | bool ParameterMismatch = false; |
| 10566 | for (unsigned I = 0; I < ParamSize; ++I) { |
| 10567 | auto *FirstParam = FirstFunction->getParamDecl(I); |
| 10568 | auto *SecondParam = SecondFunction->getParamDecl(I); |
| 10569 | |
| 10570 | assert(getContext().hasSameType(FirstParam->getType(), |
| 10571 | SecondParam->getType()) && |
| 10572 | "Merged function has different parameter types."); |
| 10573 | |
| 10574 | if (FirstParam->getDeclName() != SecondParam->getDeclName()) { |
| 10575 | ODRDiagError(FirstParam->getLocation(), FirstParam->getSourceRange(), |
| 10576 | ParameterName) |
| 10577 | << I + 1 << FirstParam->getDeclName(); |
| 10578 | ODRDiagNote(SecondParam->getLocation(), SecondParam->getSourceRange(), |
| 10579 | ParameterName) |
| 10580 | << I + 1 << SecondParam->getDeclName(); |
| 10581 | ParameterMismatch = true; |
| 10582 | break; |
| 10583 | }; |
| 10584 | |
| 10585 | QualType FirstParamType = FirstParam->getType(); |
| 10586 | QualType SecondParamType = SecondParam->getType(); |
| 10587 | if (FirstParamType != SecondParamType && |
| 10588 | ComputeQualTypeODRHash(FirstParamType) != |
| 10589 | ComputeQualTypeODRHash(SecondParamType)) { |
| 10590 | if (const DecayedType *ParamDecayedType = |
| 10591 | FirstParamType->getAs<DecayedType>()) { |
| 10592 | ODRDiagError(FirstParam->getLocation(), |
| 10593 | FirstParam->getSourceRange(), ParameterType) |
| 10594 | << (I + 1) << FirstParamType << true |
| 10595 | << ParamDecayedType->getOriginalType(); |
| 10596 | } else { |
| 10597 | ODRDiagError(FirstParam->getLocation(), |
| 10598 | FirstParam->getSourceRange(), ParameterType) |
| 10599 | << (I + 1) << FirstParamType << false; |
| 10600 | } |
| 10601 | |
| 10602 | if (const DecayedType *ParamDecayedType = |
| 10603 | SecondParamType->getAs<DecayedType>()) { |
| 10604 | ODRDiagNote(SecondParam->getLocation(), |
| 10605 | SecondParam->getSourceRange(), ParameterType) |
| 10606 | << (I + 1) << SecondParamType << true |
| 10607 | << ParamDecayedType->getOriginalType(); |
| 10608 | } else { |
| 10609 | ODRDiagNote(SecondParam->getLocation(), |
| 10610 | SecondParam->getSourceRange(), ParameterType) |
| 10611 | << (I + 1) << SecondParamType << false; |
| 10612 | } |
| 10613 | ParameterMismatch = true; |
| 10614 | break; |
| 10615 | } |
| 10616 | |
| 10617 | const Expr *FirstInit = FirstParam->getInit(); |
| 10618 | const Expr *SecondInit = SecondParam->getInit(); |
| 10619 | if ((FirstInit == nullptr) != (SecondInit == nullptr)) { |
| 10620 | ODRDiagError(FirstParam->getLocation(), FirstParam->getSourceRange(), |
| 10621 | ParameterSingleDefaultArgument) |
| 10622 | << (I + 1) << (FirstInit == nullptr) |
| 10623 | << (FirstInit ? FirstInit->getSourceRange() : SourceRange()); |
| 10624 | ODRDiagNote(SecondParam->getLocation(), SecondParam->getSourceRange(), |
| 10625 | ParameterSingleDefaultArgument) |
| 10626 | << (I + 1) << (SecondInit == nullptr) |
| 10627 | << (SecondInit ? SecondInit->getSourceRange() : SourceRange()); |
| 10628 | ParameterMismatch = true; |
| 10629 | break; |
| 10630 | } |
| 10631 | |
| 10632 | if (FirstInit && SecondInit && |
| 10633 | ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) { |
| 10634 | ODRDiagError(FirstParam->getLocation(), FirstParam->getSourceRange(), |
| 10635 | ParameterDifferentDefaultArgument) |
| 10636 | << (I + 1) << FirstInit->getSourceRange(); |
| 10637 | ODRDiagNote(SecondParam->getLocation(), SecondParam->getSourceRange(), |
| 10638 | ParameterDifferentDefaultArgument) |
| 10639 | << (I + 1) << SecondInit->getSourceRange(); |
| 10640 | ParameterMismatch = true; |
| 10641 | break; |
| 10642 | } |
| 10643 | |
| 10644 | assert(ComputeSubDeclODRHash(FirstParam) == |
| 10645 | ComputeSubDeclODRHash(SecondParam) && |
| 10646 | "Undiagnosed parameter difference."); |
| 10647 | } |
| 10648 | |
| 10649 | if (ParameterMismatch) { |
| 10650 | Diagnosed = true; |
| 10651 | break; |
| 10652 | } |
| 10653 | |
| 10654 | // If no error has been generated before now, assume the problem is in |
| 10655 | // the body and generate a message. |
| 10656 | ODRDiagError(FirstFunction->getLocation(), |
| 10657 | FirstFunction->getSourceRange(), FunctionBody); |
| 10658 | ODRDiagNote(SecondFunction->getLocation(), |
| 10659 | SecondFunction->getSourceRange(), FunctionBody); |
| 10660 | Diagnosed = true; |
| 10661 | break; |
| 10662 | } |
Evgeny Stupachenko | bf25d67 | 2018-01-05 02:22:52 +0000 | [diff] [blame] | 10663 | (void)Diagnosed; |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 10664 | assert(Diagnosed && "Unable to emit ODR diagnostic."); |
| 10665 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10666 | } |
| 10667 | |
Richard Smith | ce18a18 | 2015-07-14 00:26:00 +0000 | [diff] [blame] | 10668 | void ASTReader::StartedDeserializing() { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 10669 | if (++NumCurrentElementsDeserializing == 1 && ReadTimer.get()) |
Richard Smith | ce18a18 | 2015-07-14 00:26:00 +0000 | [diff] [blame] | 10670 | ReadTimer->startTimer(); |
| 10671 | } |
| 10672 | |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10673 | void ASTReader::FinishedDeserializing() { |
| 10674 | assert(NumCurrentElementsDeserializing && |
| 10675 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 10676 | if (NumCurrentElementsDeserializing == 1) { |
| 10677 | // We decrease NumCurrentElementsDeserializing only after pending actions |
| 10678 | // are finished, to avoid recursively re-calling finishPendingActions(). |
| 10679 | finishPendingActions(); |
| 10680 | } |
| 10681 | --NumCurrentElementsDeserializing; |
| 10682 | |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 10683 | if (NumCurrentElementsDeserializing == 0) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 10684 | // Propagate exception specification updates along redeclaration chains. |
Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 10685 | while (!PendingExceptionSpecUpdates.empty()) { |
| 10686 | auto Updates = std::move(PendingExceptionSpecUpdates); |
| 10687 | PendingExceptionSpecUpdates.clear(); |
| 10688 | for (auto Update : Updates) { |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 10689 | ProcessingUpdatesRAIIObj ProcessingUpdates(*this); |
Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 10690 | auto *FPT = Update.second->getType()->castAs<FunctionProtoType>(); |
Richard Smith | 1d0f199 | 2015-08-19 21:09:32 +0000 | [diff] [blame] | 10691 | auto ESI = FPT->getExtProtoInfo().ExceptionSpec; |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 10692 | if (auto *Listener = getContext().getASTMutationListener()) |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 10693 | Listener->ResolvedExceptionSpec(cast<FunctionDecl>(Update.second)); |
Richard Smith | 1d0f199 | 2015-08-19 21:09:32 +0000 | [diff] [blame] | 10694 | for (auto *Redecl : Update.second->redecls()) |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 10695 | getContext().adjustExceptionSpec(cast<FunctionDecl>(Redecl), ESI); |
Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 10696 | } |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 10697 | } |
| 10698 | |
Richard Smith | ce18a18 | 2015-07-14 00:26:00 +0000 | [diff] [blame] | 10699 | if (ReadTimer) |
| 10700 | ReadTimer->stopTimer(); |
| 10701 | |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 10702 | diagnoseOdrViolations(); |
| 10703 | |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 10704 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 10705 | // decls to the consumer. |
Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 10706 | if (Consumer) |
| 10707 | PassInterestingDeclsToConsumer(); |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10708 | } |
| 10709 | } |
| 10710 | |
Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 10711 | void ASTReader::pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name) { |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 10712 | if (IdentifierInfo *II = Name.getAsIdentifierInfo()) { |
| 10713 | // Remove any fake results before adding any real ones. |
| 10714 | auto It = PendingFakeLookupResults.find(II); |
| 10715 | if (It != PendingFakeLookupResults.end()) { |
Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 10716 | for (auto *ND : It->second) |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 10717 | SemaObj->IdResolver.RemoveDecl(ND); |
Ben Langmuir | eb8bd2d | 2015-04-10 22:25:42 +0000 | [diff] [blame] | 10718 | // FIXME: this works around module+PCH performance issue. |
| 10719 | // Rather than erase the result from the map, which is O(n), just clear |
| 10720 | // the vector of NamedDecls. |
| 10721 | It->second.clear(); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 10722 | } |
| 10723 | } |
Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 10724 | |
| 10725 | if (SemaObj->IdResolver.tryAddTopLevelDecl(D, Name) && SemaObj->TUScope) { |
| 10726 | SemaObj->TUScope->AddDecl(D); |
| 10727 | } else if (SemaObj->TUScope) { |
| 10728 | // Adding the decl to IdResolver may have failed because it was already in |
| 10729 | // (even though it was not added in scope). If it is already in, make sure |
| 10730 | // it gets in the scope as well. |
| 10731 | if (std::find(SemaObj->IdResolver.begin(Name), |
| 10732 | SemaObj->IdResolver.end(), D) != SemaObj->IdResolver.end()) |
| 10733 | SemaObj->TUScope->AddDecl(D); |
| 10734 | } |
| 10735 | } |
| 10736 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 10737 | ASTReader::ASTReader(Preprocessor &PP, ASTContext *Context, |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 10738 | const PCHContainerReader &PCHContainerRdr, |
| 10739 | ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, |
| 10740 | StringRef isysroot, bool DisableValidation, |
| 10741 | bool AllowASTWithCompilerErrors, |
| 10742 | bool AllowConfigurationMismatch, bool ValidateSystemInputs, |
| 10743 | bool UseGlobalIndex, |
| 10744 | std::unique_ptr<llvm::Timer> ReadTimer) |
| 10745 | : Listener(DisableValidation |
| 10746 | ? cast<ASTReaderListener>(new SimpleASTReaderListener(PP)) |
| 10747 | : cast<ASTReaderListener>(new PCHValidator(PP, *this))), |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 10748 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
David Blaikie | 9d7c1ba | 2017-01-05 18:45:43 +0000 | [diff] [blame] | 10749 | PCHContainerRdr(PCHContainerRdr), Diags(PP.getDiagnostics()), PP(PP), |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 10750 | ContextObj(Context), |
Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 10751 | ModuleMgr(PP.getFileManager(), PP.getPCMCache(), PCHContainerRdr, |
| 10752 | PP.getHeaderSearchInfo()), |
Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 10753 | PCMCache(PP.getPCMCache()), DummyIdResolver(PP), |
| 10754 | ReadTimer(std::move(ReadTimer)), isysroot(isysroot), |
David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 10755 | DisableValidation(DisableValidation), |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 10756 | AllowASTWithCompilerErrors(AllowASTWithCompilerErrors), |
| 10757 | AllowConfigurationMismatch(AllowConfigurationMismatch), |
| 10758 | ValidateSystemInputs(ValidateSystemInputs), |
David Blaikie | 9d7c1ba | 2017-01-05 18:45:43 +0000 | [diff] [blame] | 10759 | UseGlobalIndex(UseGlobalIndex), CurrSwitchCaseStmts(&SwitchCaseStmts) { |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10760 | SourceMgr.setExternalSLocEntrySource(this); |
Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 10761 | |
| 10762 | for (const auto &Ext : Extensions) { |
| 10763 | auto BlockName = Ext->getExtensionMetadata().BlockName; |
| 10764 | auto Known = ModuleFileExtensions.find(BlockName); |
| 10765 | if (Known != ModuleFileExtensions.end()) { |
| 10766 | Diags.Report(diag::warn_duplicate_module_file_extension) |
| 10767 | << BlockName; |
| 10768 | continue; |
| 10769 | } |
| 10770 | |
| 10771 | ModuleFileExtensions.insert({BlockName, Ext}); |
| 10772 | } |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10773 | } |
| 10774 | |
| 10775 | ASTReader::~ASTReader() { |
Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 10776 | if (OwnsDeserializationListener) |
| 10777 | delete DeserializationListener; |
Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 10778 | } |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 10779 | |
| 10780 | IdentifierResolver &ASTReader::getIdResolver() { |
| 10781 | return SemaObj ? SemaObj->IdResolver : DummyIdResolver; |
| 10782 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 10783 | |
| 10784 | unsigned ASTRecordReader::readRecord(llvm::BitstreamCursor &Cursor, |
| 10785 | unsigned AbbrevID) { |
| 10786 | Idx = 0; |
| 10787 | Record.clear(); |
| 10788 | return Cursor.readRecord(AbbrevID, Record); |
| 10789 | } |