| 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 | // |
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines the ASTReader class, which reads AST files. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "clang/Serialization/ASTReader.h" |
| 14 | #include "ASTCommon.h" |
| 15 | #include "ASTReaderInternals.h" |
| 16 | #include "clang/AST/ASTConsumer.h" |
| 17 | #include "clang/AST/ASTContext.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTMutationListener.h" |
| 19 | #include "clang/AST/ASTUnresolvedSet.h" |
| 20 | #include "clang/AST/Decl.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclBase.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclCXX.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclFriend.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 24 | #include "clang/AST/DeclGroup.h" |
| 25 | #include "clang/AST/DeclObjC.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 26 | #include "clang/AST/DeclTemplate.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 27 | #include "clang/AST/DeclarationName.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 28 | #include "clang/AST/Expr.h" |
| 29 | #include "clang/AST/ExprCXX.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 30 | #include "clang/AST/ExternalASTSource.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 31 | #include "clang/AST/NestedNameSpecifier.h" |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 32 | #include "clang/AST/ODRHash.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 33 | #include "clang/AST/RawCommentList.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 34 | #include "clang/AST/TemplateBase.h" |
| 35 | #include "clang/AST/TemplateName.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 36 | #include "clang/AST/Type.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 37 | #include "clang/AST/TypeLoc.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 38 | #include "clang/AST/TypeLocVisitor.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 39 | #include "clang/AST/UnresolvedSet.h" |
| 40 | #include "clang/Basic/CommentOptions.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 41 | #include "clang/Basic/Diagnostic.h" |
| Benjamin Kramer | f3ca2698 | 2014-05-10 16:31:55 +0000 | [diff] [blame] | 42 | #include "clang/Basic/DiagnosticOptions.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 43 | #include "clang/Basic/ExceptionSpecificationType.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 44 | #include "clang/Basic/FileManager.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 45 | #include "clang/Basic/FileSystemOptions.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 46 | #include "clang/Basic/IdentifierTable.h" |
| 47 | #include "clang/Basic/LLVM.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 48 | #include "clang/Basic/LangOptions.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 49 | #include "clang/Basic/Module.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 50 | #include "clang/Basic/ObjCRuntime.h" |
| 51 | #include "clang/Basic/OperatorKinds.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 52 | #include "clang/Basic/PragmaKinds.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 53 | #include "clang/Basic/Sanitizers.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 54 | #include "clang/Basic/SourceLocation.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 55 | #include "clang/Basic/SourceManager.h" |
| 56 | #include "clang/Basic/SourceManagerInternals.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 57 | #include "clang/Basic/Specifiers.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 58 | #include "clang/Basic/TargetInfo.h" |
| 59 | #include "clang/Basic/TargetOptions.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 60 | #include "clang/Basic/TokenKinds.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 61 | #include "clang/Basic/Version.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 62 | #include "clang/Lex/HeaderSearch.h" |
| 63 | #include "clang/Lex/HeaderSearchOptions.h" |
| 64 | #include "clang/Lex/MacroInfo.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 65 | #include "clang/Lex/ModuleMap.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 66 | #include "clang/Lex/PreprocessingRecord.h" |
| 67 | #include "clang/Lex/Preprocessor.h" |
| 68 | #include "clang/Lex/PreprocessorOptions.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 69 | #include "clang/Lex/Token.h" |
| 70 | #include "clang/Sema/ObjCMethodList.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 71 | #include "clang/Sema/Scope.h" |
| 72 | #include "clang/Sema/Sema.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 73 | #include "clang/Sema/Weak.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 74 | #include "clang/Serialization/ASTBitCodes.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 75 | #include "clang/Serialization/ASTDeserializationListener.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 76 | #include "clang/Serialization/ContinuousRangeMap.h" |
| Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 77 | #include "clang/Serialization/GlobalModuleIndex.h" |
| Duncan P. N. Exon Smith | 8bef5cd | 2019-03-09 17:33:56 +0000 | [diff] [blame] | 78 | #include "clang/Serialization/InMemoryModuleCache.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 79 | #include "clang/Serialization/Module.h" |
| 80 | #include "clang/Serialization/ModuleFileExtension.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 81 | #include "clang/Serialization/ModuleManager.h" |
| Richard Trieu | f3b0046 | 2018-12-12 02:53:59 +0000 | [diff] [blame] | 82 | #include "clang/Serialization/PCHContainerOperations.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 83 | #include "clang/Serialization/SerializationDiagnostic.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 84 | #include "llvm/ADT/APFloat.h" |
| 85 | #include "llvm/ADT/APInt.h" |
| 86 | #include "llvm/ADT/APSInt.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 87 | #include "llvm/ADT/ArrayRef.h" |
| 88 | #include "llvm/ADT/DenseMap.h" |
| 89 | #include "llvm/ADT/FoldingSet.h" |
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 90 | #include "llvm/ADT/Hashing.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 91 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
| 92 | #include "llvm/ADT/None.h" |
| 93 | #include "llvm/ADT/Optional.h" |
| 94 | #include "llvm/ADT/STLExtras.h" |
| Duncan P. N. Exon Smith | 0a2be46 | 2019-03-09 17:44:01 +0000 | [diff] [blame] | 95 | #include "llvm/ADT/ScopeExit.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 96 | #include "llvm/ADT/SmallPtrSet.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 97 | #include "llvm/ADT/SmallString.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 98 | #include "llvm/ADT/SmallVector.h" |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 99 | #include "llvm/ADT/StringExtras.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 100 | #include "llvm/ADT/StringMap.h" |
| 101 | #include "llvm/ADT/StringRef.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 102 | #include "llvm/ADT/Triple.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 103 | #include "llvm/ADT/iterator_range.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 104 | #include "llvm/Bitcode/BitstreamReader.h" |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 105 | #include "llvm/Support/Casting.h" |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 106 | #include "llvm/Support/Compiler.h" |
| Pavel Labath | d8c6290 | 2018-06-11 10:28:04 +0000 | [diff] [blame] | 107 | #include "llvm/Support/Compression.h" |
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 108 | #include "llvm/Support/DJB.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" |
| Pavel Labath | d8c6290 | 2018-06-11 10:28:04 +0000 | [diff] [blame] | 117 | #include "llvm/Support/VersionTuple.h" |
| Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 118 | #include "llvm/Support/raw_ostream.h" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 119 | #include <algorithm> |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 120 | #include <cassert> |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 121 | #include <cstddef> |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 122 | #include <cstdint> |
| Chris Lattner | 91f373e | 2013-01-20 00:57:52 +0000 | [diff] [blame] | 123 | #include <cstdio> |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 124 | #include <ctime> |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 125 | #include <iterator> |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 126 | #include <limits> |
| 127 | #include <map> |
| 128 | #include <memory> |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 129 | #include <string> |
| Rafael Espindola | 8a8e554 | 2014-06-12 17:19:42 +0000 | [diff] [blame] | 130 | #include <system_error> |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 131 | #include <tuple> |
| 132 | #include <utility> |
| 133 | #include <vector> |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 134 | |
| 135 | using namespace clang; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 136 | using namespace clang::serialization; |
| 137 | using namespace clang::serialization::reader; |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 138 | using llvm::BitstreamCursor; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 139 | |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 140 | //===----------------------------------------------------------------------===// |
| 141 | // ChainedASTReaderListener implementation |
| 142 | //===----------------------------------------------------------------------===// |
| 143 | |
| 144 | bool |
| 145 | ChainedASTReaderListener::ReadFullVersionInformation(StringRef FullVersion) { |
| 146 | return First->ReadFullVersionInformation(FullVersion) || |
| 147 | Second->ReadFullVersionInformation(FullVersion); |
| 148 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 149 | |
| Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 150 | void ChainedASTReaderListener::ReadModuleName(StringRef ModuleName) { |
| 151 | First->ReadModuleName(ModuleName); |
| 152 | Second->ReadModuleName(ModuleName); |
| 153 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 154 | |
| Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 155 | void ChainedASTReaderListener::ReadModuleMapFile(StringRef ModuleMapPath) { |
| 156 | First->ReadModuleMapFile(ModuleMapPath); |
| 157 | Second->ReadModuleMapFile(ModuleMapPath); |
| 158 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 159 | |
| Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 160 | bool |
| 161 | ChainedASTReaderListener::ReadLanguageOptions(const LangOptions &LangOpts, |
| 162 | bool Complain, |
| 163 | bool AllowCompatibleDifferences) { |
| 164 | return First->ReadLanguageOptions(LangOpts, Complain, |
| 165 | AllowCompatibleDifferences) || |
| 166 | Second->ReadLanguageOptions(LangOpts, Complain, |
| 167 | AllowCompatibleDifferences); |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 168 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 169 | |
| Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 170 | bool ChainedASTReaderListener::ReadTargetOptions( |
| 171 | const TargetOptions &TargetOpts, bool Complain, |
| 172 | bool AllowCompatibleDifferences) { |
| 173 | return First->ReadTargetOptions(TargetOpts, Complain, |
| 174 | AllowCompatibleDifferences) || |
| 175 | Second->ReadTargetOptions(TargetOpts, Complain, |
| 176 | AllowCompatibleDifferences); |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 177 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 178 | |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 179 | bool ChainedASTReaderListener::ReadDiagnosticOptions( |
| Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 180 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) { |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 181 | return First->ReadDiagnosticOptions(DiagOpts, Complain) || |
| 182 | Second->ReadDiagnosticOptions(DiagOpts, Complain); |
| 183 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 184 | |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 185 | bool |
| 186 | ChainedASTReaderListener::ReadFileSystemOptions(const FileSystemOptions &FSOpts, |
| 187 | bool Complain) { |
| 188 | return First->ReadFileSystemOptions(FSOpts, Complain) || |
| 189 | Second->ReadFileSystemOptions(FSOpts, Complain); |
| 190 | } |
| 191 | |
| 192 | bool ChainedASTReaderListener::ReadHeaderSearchOptions( |
| Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 193 | const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, |
| 194 | bool Complain) { |
| 195 | return First->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 196 | Complain) || |
| 197 | Second->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 198 | Complain); |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 199 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 200 | |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 201 | bool ChainedASTReaderListener::ReadPreprocessorOptions( |
| 202 | const PreprocessorOptions &PPOpts, bool Complain, |
| 203 | std::string &SuggestedPredefines) { |
| 204 | return First->ReadPreprocessorOptions(PPOpts, Complain, |
| 205 | SuggestedPredefines) || |
| 206 | Second->ReadPreprocessorOptions(PPOpts, Complain, SuggestedPredefines); |
| 207 | } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 208 | |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 209 | void ChainedASTReaderListener::ReadCounter(const serialization::ModuleFile &M, |
| 210 | unsigned Value) { |
| 211 | First->ReadCounter(M, Value); |
| 212 | Second->ReadCounter(M, Value); |
| 213 | } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 214 | |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 215 | bool ChainedASTReaderListener::needsInputFileVisitation() { |
| 216 | return First->needsInputFileVisitation() || |
| 217 | Second->needsInputFileVisitation(); |
| 218 | } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 219 | |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 220 | bool ChainedASTReaderListener::needsSystemInputFileVisitation() { |
| 221 | return First->needsSystemInputFileVisitation() || |
| 222 | Second->needsSystemInputFileVisitation(); |
| 223 | } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 224 | |
| Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 225 | void ChainedASTReaderListener::visitModuleFile(StringRef Filename, |
| 226 | ModuleKind Kind) { |
| 227 | First->visitModuleFile(Filename, Kind); |
| 228 | Second->visitModuleFile(Filename, Kind); |
| Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 229 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 230 | |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 231 | bool ChainedASTReaderListener::visitInputFile(StringRef Filename, |
| Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 232 | bool isSystem, |
| Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 233 | bool isOverridden, |
| 234 | bool isExplicitModule) { |
| Justin Bogner | c65a66d | 2014-05-22 06:04:59 +0000 | [diff] [blame] | 235 | bool Continue = false; |
| 236 | if (First->needsInputFileVisitation() && |
| 237 | (!isSystem || First->needsSystemInputFileVisitation())) |
| Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 238 | Continue |= First->visitInputFile(Filename, isSystem, isOverridden, |
| 239 | isExplicitModule); |
| Justin Bogner | c65a66d | 2014-05-22 06:04:59 +0000 | [diff] [blame] | 240 | if (Second->needsInputFileVisitation() && |
| 241 | (!isSystem || Second->needsSystemInputFileVisitation())) |
| Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 242 | Continue |= Second->visitInputFile(Filename, isSystem, isOverridden, |
| 243 | isExplicitModule); |
| Justin Bogner | c65a66d | 2014-05-22 06:04:59 +0000 | [diff] [blame] | 244 | return Continue; |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 247 | void ChainedASTReaderListener::readModuleFileExtension( |
| 248 | const ModuleFileExtensionMetadata &Metadata) { |
| 249 | First->readModuleFileExtension(Metadata); |
| 250 | Second->readModuleFileExtension(Metadata); |
| 251 | } |
| 252 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 253 | //===----------------------------------------------------------------------===// |
| 254 | // PCH validator implementation |
| 255 | //===----------------------------------------------------------------------===// |
| 256 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 257 | ASTReaderListener::~ASTReaderListener() = default; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 258 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 259 | /// Compare the given set of language options against an existing set of |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 260 | /// language options. |
| 261 | /// |
| 262 | /// \param Diags If non-NULL, diagnostics will be emitted via this engine. |
| Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 263 | /// \param AllowCompatibleDifferences If true, differences between compatible |
| 264 | /// language options will be permitted. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 265 | /// |
| 266 | /// \returns true if the languagae options mis-match, false otherwise. |
| 267 | static bool checkLanguageOptions(const LangOptions &LangOpts, |
| 268 | const LangOptions &ExistingLangOpts, |
| Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 269 | DiagnosticsEngine *Diags, |
| 270 | bool AllowCompatibleDifferences = true) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 271 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 272 | if (ExistingLangOpts.Name != LangOpts.Name) { \ |
| 273 | if (Diags) \ |
| 274 | Diags->Report(diag::err_pch_langopt_mismatch) \ |
| 275 | << Description << LangOpts.Name << ExistingLangOpts.Name; \ |
| 276 | return true; \ |
| 277 | } |
| 278 | |
| 279 | #define VALUE_LANGOPT(Name, Bits, Default, Description) \ |
| 280 | if (ExistingLangOpts.Name != LangOpts.Name) { \ |
| 281 | if (Diags) \ |
| 282 | Diags->Report(diag::err_pch_langopt_value_mismatch) \ |
| 283 | << Description; \ |
| 284 | return true; \ |
| 285 | } |
| 286 | |
| 287 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 288 | if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \ |
| 289 | if (Diags) \ |
| 290 | Diags->Report(diag::err_pch_langopt_value_mismatch) \ |
| 291 | << Description; \ |
| 292 | return true; \ |
| 293 | } |
| 294 | |
| Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 295 | #define COMPATIBLE_LANGOPT(Name, Bits, Default, Description) \ |
| 296 | if (!AllowCompatibleDifferences) \ |
| 297 | LANGOPT(Name, Bits, Default, Description) |
| 298 | |
| 299 | #define COMPATIBLE_ENUM_LANGOPT(Name, Bits, Default, Description) \ |
| 300 | if (!AllowCompatibleDifferences) \ |
| 301 | ENUM_LANGOPT(Name, Bits, Default, Description) |
| 302 | |
| Richard Smith | a1ddf5e | 2016-04-07 20:47:37 +0000 | [diff] [blame] | 303 | #define COMPATIBLE_VALUE_LANGOPT(Name, Bits, Default, Description) \ |
| 304 | if (!AllowCompatibleDifferences) \ |
| 305 | VALUE_LANGOPT(Name, Bits, Default, Description) |
| 306 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 307 | #define BENIGN_LANGOPT(Name, Bits, Default, Description) |
| 308 | #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) |
| Richard Smith | a1ddf5e | 2016-04-07 20:47:37 +0000 | [diff] [blame] | 309 | #define BENIGN_VALUE_LANGOPT(Name, Type, Bits, Default, Description) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 310 | #include "clang/Basic/LangOptions.def" |
| 311 | |
| Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 312 | if (ExistingLangOpts.ModuleFeatures != LangOpts.ModuleFeatures) { |
| 313 | if (Diags) |
| 314 | Diags->Report(diag::err_pch_langopt_value_mismatch) << "module features"; |
| 315 | return true; |
| 316 | } |
| 317 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 318 | if (ExistingLangOpts.ObjCRuntime != LangOpts.ObjCRuntime) { |
| 319 | if (Diags) |
| 320 | Diags->Report(diag::err_pch_langopt_value_mismatch) |
| 321 | << "target Objective-C runtime"; |
| 322 | return true; |
| 323 | } |
| 324 | |
| Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 325 | if (ExistingLangOpts.CommentOpts.BlockCommandNames != |
| 326 | LangOpts.CommentOpts.BlockCommandNames) { |
| 327 | if (Diags) |
| 328 | Diags->Report(diag::err_pch_langopt_value_mismatch) |
| 329 | << "block command names"; |
| 330 | return true; |
| 331 | } |
| 332 | |
| Vedant Kumar | 85a83c2 | 2017-06-01 20:01:01 +0000 | [diff] [blame] | 333 | // Sanitizer feature mismatches are treated as compatible differences. If |
| 334 | // compatible differences aren't allowed, we still only want to check for |
| 335 | // mismatches of non-modular sanitizers (the only ones which can affect AST |
| 336 | // generation). |
| 337 | if (!AllowCompatibleDifferences) { |
| 338 | SanitizerMask ModularSanitizers = getPPTransparentSanitizers(); |
| 339 | SanitizerSet ExistingSanitizers = ExistingLangOpts.Sanitize; |
| 340 | SanitizerSet ImportedSanitizers = LangOpts.Sanitize; |
| 341 | ExistingSanitizers.clear(ModularSanitizers); |
| 342 | ImportedSanitizers.clear(ModularSanitizers); |
| 343 | if (ExistingSanitizers.Mask != ImportedSanitizers.Mask) { |
| 344 | const std::string Flag = "-fsanitize="; |
| 345 | if (Diags) { |
| 346 | #define SANITIZER(NAME, ID) \ |
| 347 | { \ |
| 348 | bool InExistingModule = ExistingSanitizers.has(SanitizerKind::ID); \ |
| 349 | bool InImportedModule = ImportedSanitizers.has(SanitizerKind::ID); \ |
| 350 | if (InExistingModule != InImportedModule) \ |
| 351 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) \ |
| 352 | << InExistingModule << (Flag + NAME); \ |
| 353 | } |
| 354 | #include "clang/Basic/Sanitizers.def" |
| 355 | } |
| 356 | return true; |
| 357 | } |
| 358 | } |
| 359 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 360 | return false; |
| 361 | } |
| 362 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 363 | /// Compare the given set of target options against an existing set of |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 364 | /// target options. |
| 365 | /// |
| 366 | /// \param Diags If non-NULL, diagnostics will be emitted via this engine. |
| 367 | /// |
| 368 | /// \returns true if the target options mis-match, false otherwise. |
| 369 | static bool checkTargetOptions(const TargetOptions &TargetOpts, |
| 370 | const TargetOptions &ExistingTargetOpts, |
| Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 371 | DiagnosticsEngine *Diags, |
| 372 | bool AllowCompatibleDifferences = true) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 373 | #define CHECK_TARGET_OPT(Field, Name) \ |
| 374 | if (TargetOpts.Field != ExistingTargetOpts.Field) { \ |
| 375 | if (Diags) \ |
| 376 | Diags->Report(diag::err_pch_targetopt_mismatch) \ |
| 377 | << Name << TargetOpts.Field << ExistingTargetOpts.Field; \ |
| 378 | return true; \ |
| 379 | } |
| 380 | |
| Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 381 | // The triple and ABI must match exactly. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 382 | CHECK_TARGET_OPT(Triple, "target"); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 383 | CHECK_TARGET_OPT(ABI, "target ABI"); |
| Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 384 | |
| 385 | // We can tolerate different CPUs in many cases, notably when one CPU |
| 386 | // supports a strict superset of another. When allowing compatible |
| 387 | // differences skip this check. |
| 388 | if (!AllowCompatibleDifferences) |
| 389 | CHECK_TARGET_OPT(CPU, "target CPU"); |
| 390 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 391 | #undef CHECK_TARGET_OPT |
| 392 | |
| 393 | // Compare feature sets. |
| 394 | SmallVector<StringRef, 4> ExistingFeatures( |
| 395 | ExistingTargetOpts.FeaturesAsWritten.begin(), |
| 396 | ExistingTargetOpts.FeaturesAsWritten.end()); |
| 397 | SmallVector<StringRef, 4> ReadFeatures(TargetOpts.FeaturesAsWritten.begin(), |
| 398 | TargetOpts.FeaturesAsWritten.end()); |
| Fangrui Song | 55fab26 | 2018-09-26 22:16:28 +0000 | [diff] [blame] | 399 | llvm::sort(ExistingFeatures); |
| 400 | llvm::sort(ReadFeatures); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 401 | |
| Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 402 | // We compute the set difference in both directions explicitly so that we can |
| 403 | // diagnose the differences differently. |
| 404 | SmallVector<StringRef, 4> UnmatchedExistingFeatures, UnmatchedReadFeatures; |
| 405 | std::set_difference( |
| 406 | ExistingFeatures.begin(), ExistingFeatures.end(), ReadFeatures.begin(), |
| 407 | ReadFeatures.end(), std::back_inserter(UnmatchedExistingFeatures)); |
| 408 | std::set_difference(ReadFeatures.begin(), ReadFeatures.end(), |
| 409 | ExistingFeatures.begin(), ExistingFeatures.end(), |
| 410 | std::back_inserter(UnmatchedReadFeatures)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 411 | |
| Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 412 | // If we are allowing compatible differences and the read feature set is |
| 413 | // a strict subset of the existing feature set, there is nothing to diagnose. |
| 414 | if (AllowCompatibleDifferences && UnmatchedReadFeatures.empty()) |
| 415 | return false; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 416 | |
| Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 417 | if (Diags) { |
| 418 | for (StringRef Feature : UnmatchedReadFeatures) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 419 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
| Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 420 | << /* is-existing-feature */ false << Feature; |
| 421 | for (StringRef Feature : UnmatchedExistingFeatures) |
| 422 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
| 423 | << /* is-existing-feature */ true << Feature; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 424 | } |
| 425 | |
| Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 426 | return !UnmatchedReadFeatures.empty() || !UnmatchedExistingFeatures.empty(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | bool |
| 430 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts, |
| Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 431 | bool Complain, |
| 432 | bool AllowCompatibleDifferences) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 433 | const LangOptions &ExistingLangOpts = PP.getLangOpts(); |
| 434 | return checkLanguageOptions(LangOpts, ExistingLangOpts, |
| Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 435 | Complain ? &Reader.Diags : nullptr, |
| 436 | AllowCompatibleDifferences); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | bool PCHValidator::ReadTargetOptions(const TargetOptions &TargetOpts, |
| Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 440 | bool Complain, |
| 441 | bool AllowCompatibleDifferences) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 442 | const TargetOptions &ExistingTargetOpts = PP.getTargetInfo().getTargetOpts(); |
| 443 | return checkTargetOptions(TargetOpts, ExistingTargetOpts, |
| Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 444 | Complain ? &Reader.Diags : nullptr, |
| 445 | AllowCompatibleDifferences); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | namespace { |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 449 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 450 | using MacroDefinitionsMap = |
| 451 | llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/>>; |
| 452 | using DeclsMap = llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8>>; |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 453 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 454 | } // namespace |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 455 | |
| Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 456 | static bool checkDiagnosticGroupMappings(DiagnosticsEngine &StoredDiags, |
| 457 | DiagnosticsEngine &Diags, |
| 458 | bool Complain) { |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 459 | using Level = DiagnosticsEngine::Level; |
| Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 460 | |
| 461 | // Check current mappings for new -Werror mappings, and the stored mappings |
| 462 | // for cases that were explicitly mapped to *not* be errors that are now |
| 463 | // errors because of options like -Werror. |
| 464 | DiagnosticsEngine *MappingSources[] = { &Diags, &StoredDiags }; |
| 465 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 466 | for (DiagnosticsEngine *MappingSource : MappingSources) { |
| Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 467 | for (auto DiagIDMappingPair : MappingSource->getDiagnosticMappings()) { |
| 468 | diag::kind DiagID = DiagIDMappingPair.first; |
| 469 | Level CurLevel = Diags.getDiagnosticLevel(DiagID, SourceLocation()); |
| 470 | if (CurLevel < DiagnosticsEngine::Error) |
| 471 | continue; // not significant |
| 472 | Level StoredLevel = |
| 473 | StoredDiags.getDiagnosticLevel(DiagID, SourceLocation()); |
| 474 | if (StoredLevel < DiagnosticsEngine::Error) { |
| 475 | if (Complain) |
| 476 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror=" + |
| 477 | Diags.getDiagnosticIDs()->getWarningOptionForDiag(DiagID).str(); |
| 478 | return true; |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | return false; |
| 484 | } |
| 485 | |
| Alp Toker | ac4e8e5 | 2014-06-22 21:58:33 +0000 | [diff] [blame] | 486 | static bool isExtHandlingFromDiagsError(DiagnosticsEngine &Diags) { |
| 487 | diag::Severity Ext = Diags.getExtensionHandlingBehavior(); |
| 488 | if (Ext == diag::Severity::Warning && Diags.getWarningsAsErrors()) |
| 489 | return true; |
| 490 | return Ext >= diag::Severity::Error; |
| Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | static bool checkDiagnosticMappings(DiagnosticsEngine &StoredDiags, |
| 494 | DiagnosticsEngine &Diags, |
| 495 | bool IsSystem, bool Complain) { |
| 496 | // Top-level options |
| 497 | if (IsSystem) { |
| 498 | if (Diags.getSuppressSystemWarnings()) |
| 499 | return false; |
| 500 | // If -Wsystem-headers was not enabled before, be conservative |
| 501 | if (StoredDiags.getSuppressSystemWarnings()) { |
| 502 | if (Complain) |
| 503 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Wsystem-headers"; |
| 504 | return true; |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | if (Diags.getWarningsAsErrors() && !StoredDiags.getWarningsAsErrors()) { |
| 509 | if (Complain) |
| 510 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror"; |
| 511 | return true; |
| 512 | } |
| 513 | |
| 514 | if (Diags.getWarningsAsErrors() && Diags.getEnableAllWarnings() && |
| 515 | !StoredDiags.getEnableAllWarnings()) { |
| 516 | if (Complain) |
| 517 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Weverything -Werror"; |
| 518 | return true; |
| 519 | } |
| 520 | |
| 521 | if (isExtHandlingFromDiagsError(Diags) && |
| 522 | !isExtHandlingFromDiagsError(StoredDiags)) { |
| 523 | if (Complain) |
| 524 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-pedantic-errors"; |
| 525 | return true; |
| 526 | } |
| 527 | |
| 528 | return checkDiagnosticGroupMappings(StoredDiags, Diags, Complain); |
| 529 | } |
| 530 | |
| Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 531 | /// Return the top import module if it is implicit, nullptr otherwise. |
| 532 | static Module *getTopImportImplicitModule(ModuleManager &ModuleMgr, |
| 533 | Preprocessor &PP) { |
| 534 | // If the original import came from a file explicitly generated by the user, |
| 535 | // don't check the diagnostic mappings. |
| 536 | // FIXME: currently this is approximated by checking whether this is not a |
| 537 | // module import of an implicitly-loaded module file. |
| 538 | // Note: ModuleMgr.rbegin() may not be the current module, but it must be in |
| 539 | // the transitive closure of its imports, since unrelated modules cannot be |
| 540 | // imported until after this module finishes validation. |
| 541 | ModuleFile *TopImport = &*ModuleMgr.rbegin(); |
| 542 | while (!TopImport->ImportedBy.empty()) |
| 543 | TopImport = TopImport->ImportedBy[0]; |
| 544 | if (TopImport->Kind != MK_ImplicitModule) |
| 545 | return nullptr; |
| 546 | |
| 547 | StringRef ModuleName = TopImport->ModuleName; |
| 548 | assert(!ModuleName.empty() && "diagnostic options read before module name"); |
| 549 | |
| 550 | Module *M = PP.getHeaderSearchInfo().lookupModule(ModuleName); |
| 551 | assert(M && "missing module"); |
| 552 | return M; |
| 553 | } |
| 554 | |
| Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 555 | bool PCHValidator::ReadDiagnosticOptions( |
| 556 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) { |
| 557 | DiagnosticsEngine &ExistingDiags = PP.getDiagnostics(); |
| 558 | IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(ExistingDiags.getDiagnosticIDs()); |
| 559 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags( |
| Alp Toker | f994cef | 2014-07-05 03:08:06 +0000 | [diff] [blame] | 560 | new DiagnosticsEngine(DiagIDs, DiagOpts.get())); |
| Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 561 | // This should never fail, because we would have processed these options |
| 562 | // before writing them to an ASTFile. |
| 563 | ProcessWarningOptions(*Diags, *DiagOpts, /*Report*/false); |
| 564 | |
| 565 | ModuleManager &ModuleMgr = Reader.getModuleManager(); |
| 566 | assert(ModuleMgr.size() >= 1 && "what ASTFile is this then"); |
| 567 | |
| Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 568 | Module *TopM = getTopImportImplicitModule(ModuleMgr, PP); |
| 569 | if (!TopM) |
| Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 570 | return false; |
| 571 | |
| Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 572 | // FIXME: if the diagnostics are incompatible, save a DiagnosticOptions that |
| 573 | // contains the union of their flags. |
| Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 574 | return checkDiagnosticMappings(*Diags, ExistingDiags, TopM->IsSystem, |
| 575 | Complain); |
| Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 576 | } |
| 577 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 578 | /// Collect the macro definitions provided by the given preprocessor |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 579 | /// options. |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 580 | static void |
| 581 | collectMacroDefinitions(const PreprocessorOptions &PPOpts, |
| 582 | MacroDefinitionsMap &Macros, |
| 583 | SmallVectorImpl<StringRef> *MacroNames = nullptr) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 584 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 585 | StringRef Macro = PPOpts.Macros[I].first; |
| 586 | bool IsUndef = PPOpts.Macros[I].second; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 587 | |
| 588 | std::pair<StringRef, StringRef> MacroPair = Macro.split('='); |
| 589 | StringRef MacroName = MacroPair.first; |
| 590 | StringRef MacroBody = MacroPair.second; |
| 591 | |
| 592 | // For an #undef'd macro, we only care about the name. |
| 593 | if (IsUndef) { |
| 594 | if (MacroNames && !Macros.count(MacroName)) |
| 595 | MacroNames->push_back(MacroName); |
| 596 | |
| 597 | Macros[MacroName] = std::make_pair("", true); |
| 598 | continue; |
| 599 | } |
| 600 | |
| 601 | // For a #define'd macro, figure out the actual definition. |
| 602 | if (MacroName.size() == Macro.size()) |
| 603 | MacroBody = "1"; |
| 604 | else { |
| 605 | // Note: GCC drops anything following an end-of-line character. |
| 606 | StringRef::size_type End = MacroBody.find_first_of("\n\r"); |
| 607 | MacroBody = MacroBody.substr(0, End); |
| 608 | } |
| 609 | |
| 610 | if (MacroNames && !Macros.count(MacroName)) |
| 611 | MacroNames->push_back(MacroName); |
| 612 | Macros[MacroName] = std::make_pair(MacroBody, false); |
| 613 | } |
| 614 | } |
| Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 615 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 616 | /// Check the preprocessor options deserialized from the control block |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 617 | /// against the preprocessor options in an existing preprocessor. |
| 618 | /// |
| 619 | /// \param Diags If non-null, produce diagnostics for any mismatches incurred. |
| Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 620 | /// \param Validate If true, validate preprocessor options. If false, allow |
| 621 | /// macros defined by \p ExistingPPOpts to override those defined by |
| 622 | /// \p PPOpts in SuggestedPredefines. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 623 | static bool checkPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 624 | const PreprocessorOptions &ExistingPPOpts, |
| 625 | DiagnosticsEngine *Diags, |
| 626 | FileManager &FileMgr, |
| Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 627 | std::string &SuggestedPredefines, |
| Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 628 | const LangOptions &LangOpts, |
| 629 | bool Validate = true) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 630 | // Check macro definitions. |
| 631 | MacroDefinitionsMap ASTFileMacros; |
| 632 | collectMacroDefinitions(PPOpts, ASTFileMacros); |
| 633 | MacroDefinitionsMap ExistingMacros; |
| 634 | SmallVector<StringRef, 4> ExistingMacroNames; |
| 635 | collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames); |
| 636 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 637 | for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 638 | // Dig out the macro definition in the existing preprocessor options. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 639 | StringRef MacroName = ExistingMacroNames[I]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 640 | std::pair<StringRef, bool> Existing = ExistingMacros[MacroName]; |
| 641 | |
| 642 | // Check whether we know anything about this macro name or not. |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 643 | llvm::StringMap<std::pair<StringRef, bool /*IsUndef*/>>::iterator Known = |
| 644 | ASTFileMacros.find(MacroName); |
| Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 645 | if (!Validate || Known == ASTFileMacros.end()) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 646 | // FIXME: Check whether this identifier was referenced anywhere in the |
| 647 | // AST file. If so, we should reject the AST file. Unfortunately, this |
| 648 | // information isn't in the control block. What shall we do about it? |
| 649 | |
| 650 | if (Existing.second) { |
| 651 | SuggestedPredefines += "#undef "; |
| 652 | SuggestedPredefines += MacroName.str(); |
| 653 | SuggestedPredefines += '\n'; |
| 654 | } else { |
| 655 | SuggestedPredefines += "#define "; |
| 656 | SuggestedPredefines += MacroName.str(); |
| 657 | SuggestedPredefines += ' '; |
| 658 | SuggestedPredefines += Existing.first.str(); |
| 659 | SuggestedPredefines += '\n'; |
| 660 | } |
| 661 | continue; |
| 662 | } |
| 663 | |
| 664 | // If the macro was defined in one but undef'd in the other, we have a |
| 665 | // conflict. |
| 666 | if (Existing.second != Known->second.second) { |
| 667 | if (Diags) { |
| 668 | Diags->Report(diag::err_pch_macro_def_undef) |
| 669 | << MacroName << Known->second.second; |
| 670 | } |
| 671 | return true; |
| 672 | } |
| 673 | |
| 674 | // If the macro was #undef'd in both, or if the macro bodies are identical, |
| 675 | // it's fine. |
| 676 | if (Existing.second || Existing.first == Known->second.first) |
| 677 | continue; |
| 678 | |
| 679 | // The macro bodies differ; complain. |
| 680 | if (Diags) { |
| 681 | Diags->Report(diag::err_pch_macro_def_conflict) |
| 682 | << MacroName << Known->second.first << Existing.first; |
| 683 | } |
| 684 | return true; |
| 685 | } |
| 686 | |
| 687 | // Check whether we're using predefines. |
| Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 688 | if (PPOpts.UsePredefines != ExistingPPOpts.UsePredefines && Validate) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 689 | if (Diags) { |
| 690 | Diags->Report(diag::err_pch_undef) << ExistingPPOpts.UsePredefines; |
| 691 | } |
| 692 | return true; |
| 693 | } |
| 694 | |
| Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 695 | // Detailed record is important since it is used for the module cache hash. |
| 696 | if (LangOpts.Modules && |
| Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 697 | PPOpts.DetailedRecord != ExistingPPOpts.DetailedRecord && Validate) { |
| Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 698 | if (Diags) { |
| 699 | Diags->Report(diag::err_pch_pp_detailed_record) << PPOpts.DetailedRecord; |
| 700 | } |
| 701 | return true; |
| 702 | } |
| 703 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 704 | // Compute the #include and #include_macros lines we need. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 705 | for (unsigned I = 0, N = ExistingPPOpts.Includes.size(); I != N; ++I) { |
| 706 | StringRef File = ExistingPPOpts.Includes[I]; |
| Erich Keane | 76675de | 2018-07-05 17:22:13 +0000 | [diff] [blame] | 707 | |
| 708 | if (!ExistingPPOpts.ImplicitPCHInclude.empty() && |
| 709 | !ExistingPPOpts.PCHThroughHeader.empty()) { |
| 710 | // In case the through header is an include, we must add all the includes |
| 711 | // to the predefines so the start point can be determined. |
| 712 | SuggestedPredefines += "#include \""; |
| 713 | SuggestedPredefines += File; |
| 714 | SuggestedPredefines += "\"\n"; |
| 715 | continue; |
| 716 | } |
| 717 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 718 | if (File == ExistingPPOpts.ImplicitPCHInclude) |
| 719 | continue; |
| 720 | |
| 721 | if (std::find(PPOpts.Includes.begin(), PPOpts.Includes.end(), File) |
| 722 | != PPOpts.Includes.end()) |
| 723 | continue; |
| 724 | |
| 725 | SuggestedPredefines += "#include \""; |
| 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"; |
| 728 | } |
| 729 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 730 | for (unsigned I = 0, N = ExistingPPOpts.MacroIncludes.size(); I != N; ++I) { |
| 731 | StringRef File = ExistingPPOpts.MacroIncludes[I]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 732 | if (std::find(PPOpts.MacroIncludes.begin(), PPOpts.MacroIncludes.end(), |
| 733 | File) |
| 734 | != PPOpts.MacroIncludes.end()) |
| 735 | continue; |
| 736 | |
| 737 | SuggestedPredefines += "#__include_macros \""; |
| Manuel Klimek | 9af34ae | 2014-08-12 08:25:57 +0000 | [diff] [blame] | 738 | SuggestedPredefines += File; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 739 | SuggestedPredefines += "\"\n##\n"; |
| 740 | } |
| 741 | |
| 742 | return false; |
| 743 | } |
| 744 | |
| 745 | bool PCHValidator::ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 746 | bool Complain, |
| 747 | std::string &SuggestedPredefines) { |
| 748 | const PreprocessorOptions &ExistingPPOpts = PP.getPreprocessorOpts(); |
| 749 | |
| 750 | return checkPreprocessorOptions(PPOpts, ExistingPPOpts, |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 751 | Complain? &Reader.Diags : nullptr, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 752 | PP.getFileManager(), |
| Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 753 | SuggestedPredefines, |
| 754 | PP.getLangOpts()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| Yaxun Liu | 43712e0 | 2016-09-07 18:40:20 +0000 | [diff] [blame] | 757 | bool SimpleASTReaderListener::ReadPreprocessorOptions( |
| 758 | const PreprocessorOptions &PPOpts, |
| 759 | bool Complain, |
| 760 | std::string &SuggestedPredefines) { |
| 761 | return checkPreprocessorOptions(PPOpts, |
| 762 | PP.getPreprocessorOpts(), |
| 763 | nullptr, |
| 764 | PP.getFileManager(), |
| 765 | SuggestedPredefines, |
| 766 | PP.getLangOpts(), |
| 767 | false); |
| 768 | } |
| 769 | |
| Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 770 | /// Check the header search options deserialized from the control block |
| 771 | /// against the header search options in an existing preprocessor. |
| 772 | /// |
| 773 | /// \param Diags If non-null, produce diagnostics for any mismatches incurred. |
| 774 | static bool checkHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 775 | StringRef SpecificModuleCachePath, |
| 776 | StringRef ExistingModuleCachePath, |
| 777 | DiagnosticsEngine *Diags, |
| 778 | const LangOptions &LangOpts) { |
| 779 | if (LangOpts.Modules) { |
| 780 | if (SpecificModuleCachePath != ExistingModuleCachePath) { |
| 781 | if (Diags) |
| 782 | Diags->Report(diag::err_pch_modulecache_mismatch) |
| 783 | << SpecificModuleCachePath << ExistingModuleCachePath; |
| 784 | return true; |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | return false; |
| 789 | } |
| 790 | |
| 791 | bool PCHValidator::ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 792 | StringRef SpecificModuleCachePath, |
| 793 | bool Complain) { |
| 794 | return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 795 | PP.getHeaderSearchInfo().getModuleCachePath(), |
| 796 | Complain ? &Reader.Diags : nullptr, |
| 797 | PP.getLangOpts()); |
| 798 | } |
| 799 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 800 | void PCHValidator::ReadCounter(const ModuleFile &M, unsigned Value) { |
| 801 | PP.setCounterValue(Value); |
| 802 | } |
| 803 | |
| 804 | //===----------------------------------------------------------------------===// |
| 805 | // AST reader implementation |
| 806 | //===----------------------------------------------------------------------===// |
| 807 | |
| Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 808 | void ASTReader::setDeserializationListener(ASTDeserializationListener *Listener, |
| 809 | bool TakeOwnership) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 810 | DeserializationListener = Listener; |
| Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 811 | OwnsDeserializationListener = TakeOwnership; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 812 | } |
| 813 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 814 | unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { |
| 815 | return serialization::ComputeHash(Sel); |
| 816 | } |
| 817 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 818 | std::pair<unsigned, unsigned> |
| 819 | ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 820 | using namespace llvm::support; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 821 | |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 822 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 823 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 824 | return std::make_pair(KeyLen, DataLen); |
| 825 | } |
| 826 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 827 | ASTSelectorLookupTrait::internal_key_type |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 828 | ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 829 | using namespace llvm::support; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 830 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 831 | SelectorTable &SelTable = Reader.getContext().Selectors; |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 832 | unsigned N = endian::readNext<uint16_t, little, unaligned>(d); |
| 833 | IdentifierInfo *FirstII = Reader.getLocalIdentifier( |
| 834 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 835 | if (N == 0) |
| 836 | return SelTable.getNullarySelector(FirstII); |
| 837 | else if (N == 1) |
| 838 | return SelTable.getUnarySelector(FirstII); |
| 839 | |
| 840 | SmallVector<IdentifierInfo *, 16> Args; |
| 841 | Args.push_back(FirstII); |
| 842 | for (unsigned I = 1; I != N; ++I) |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 843 | Args.push_back(Reader.getLocalIdentifier( |
| 844 | F, endian::readNext<uint32_t, little, unaligned>(d))); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 845 | |
| 846 | return SelTable.getSelector(N, Args.data()); |
| 847 | } |
| 848 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 849 | ASTSelectorLookupTrait::data_type |
| 850 | ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 851 | unsigned DataLen) { |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 852 | using namespace llvm::support; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 853 | |
| 854 | data_type Result; |
| 855 | |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 856 | Result.ID = Reader.getGlobalSelectorID( |
| 857 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
| Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 858 | unsigned FullInstanceBits = endian::readNext<uint16_t, little, unaligned>(d); |
| 859 | unsigned FullFactoryBits = endian::readNext<uint16_t, little, unaligned>(d); |
| 860 | Result.InstanceBits = FullInstanceBits & 0x3; |
| 861 | Result.InstanceHasMoreThanOneDecl = (FullInstanceBits >> 2) & 0x1; |
| 862 | Result.FactoryBits = FullFactoryBits & 0x3; |
| 863 | Result.FactoryHasMoreThanOneDecl = (FullFactoryBits >> 2) & 0x1; |
| 864 | unsigned NumInstanceMethods = FullInstanceBits >> 3; |
| 865 | unsigned NumFactoryMethods = FullFactoryBits >> 3; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 866 | |
| 867 | // Load instance methods |
| 868 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 869 | if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>( |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 870 | F, endian::readNext<uint32_t, little, unaligned>(d))) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 871 | Result.Instance.push_back(Method); |
| 872 | } |
| 873 | |
| 874 | // Load factory methods |
| 875 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 876 | if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>( |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 877 | F, endian::readNext<uint32_t, little, unaligned>(d))) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 878 | Result.Factory.push_back(Method); |
| 879 | } |
| 880 | |
| 881 | return Result; |
| 882 | } |
| 883 | |
| Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 884 | unsigned ASTIdentifierLookupTraitBase::ComputeHash(const internal_key_type& a) { |
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 885 | return llvm::djbHash(a); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | std::pair<unsigned, unsigned> |
| Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 889 | ASTIdentifierLookupTraitBase::ReadKeyDataLength(const unsigned char*& d) { |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 890 | using namespace llvm::support; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 891 | |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 892 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 893 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 894 | return std::make_pair(KeyLen, DataLen); |
| 895 | } |
| 896 | |
| Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 897 | ASTIdentifierLookupTraitBase::internal_key_type |
| 898 | ASTIdentifierLookupTraitBase::ReadKey(const unsigned char* d, unsigned n) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 899 | assert(n >= 2 && d[n-1] == '\0'); |
| Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 900 | return StringRef((const char*) d, n-1); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 901 | } |
| 902 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 903 | /// Whether the given identifier is "interesting". |
| Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 904 | static bool isInterestingIdentifier(ASTReader &Reader, IdentifierInfo &II, |
| 905 | bool IsModule) { |
| Richard Smith | cab8980 | 2015-07-17 20:19:56 +0000 | [diff] [blame] | 906 | return II.hadMacroDefinition() || |
| 907 | II.isPoisoned() || |
| Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 908 | (IsModule ? II.hasRevertedBuiltin() : II.getObjCOrBuiltinID()) || |
| Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 909 | II.hasRevertedTokenIDToIdentifier() || |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 910 | (!(IsModule && Reader.getPreprocessor().getLangOpts().CPlusPlus) && |
| Bruno Ricci | 366ba73 | 2018-09-21 12:53:22 +0000 | [diff] [blame] | 911 | II.getFETokenInfo()); |
| Douglas Gregor | dcf2508 | 2013-02-11 18:16:18 +0000 | [diff] [blame] | 912 | } |
| 913 | |
| Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 914 | static bool readBit(unsigned &Bits) { |
| 915 | bool Value = Bits & 0x1; |
| 916 | Bits >>= 1; |
| 917 | return Value; |
| 918 | } |
| 919 | |
| Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 920 | IdentID ASTIdentifierLookupTrait::ReadIdentifierID(const unsigned char *d) { |
| 921 | using namespace llvm::support; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 922 | |
| Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 923 | unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d); |
| 924 | return Reader.getGlobalIdentifierID(F, RawID >> 1); |
| 925 | } |
| 926 | |
| Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 927 | static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II) { |
| 928 | if (!II.isFromAST()) { |
| 929 | II.setIsFromAST(); |
| 930 | bool IsModule = Reader.getPreprocessor().getCurrentModule() != nullptr; |
| 931 | if (isInterestingIdentifier(Reader, II, IsModule)) |
| 932 | II.setChangedSinceDeserialization(); |
| 933 | } |
| 934 | } |
| 935 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 936 | IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, |
| 937 | const unsigned char* d, |
| 938 | unsigned DataLen) { |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 939 | using namespace llvm::support; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 940 | |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 941 | unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 942 | bool IsInteresting = RawID & 0x01; |
| 943 | |
| 944 | // Wipe out the "is interesting" bit. |
| 945 | RawID = RawID >> 1; |
| 946 | |
| Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 947 | // Build the IdentifierInfo and link the identifier ID with it. |
| 948 | IdentifierInfo *II = KnownII; |
| 949 | if (!II) { |
| 950 | II = &Reader.getIdentifierTable().getOwn(k); |
| 951 | KnownII = II; |
| 952 | } |
| Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 953 | markIdentifierFromAST(Reader, *II); |
| Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 954 | Reader.markIdentifierUpToDate(II); |
| 955 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 956 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
| 957 | if (!IsInteresting) { |
| Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 958 | // For uninteresting identifiers, there's nothing else to do. Just notify |
| 959 | // the reader that we've finished loading this identifier. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 960 | Reader.SetIdentifierInfo(ID, II); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 961 | return II; |
| 962 | } |
| 963 | |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 964 | unsigned ObjCOrBuiltinID = endian::readNext<uint16_t, little, unaligned>(d); |
| 965 | unsigned Bits = endian::readNext<uint16_t, little, unaligned>(d); |
| Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 966 | bool CPlusPlusOperatorKeyword = readBit(Bits); |
| 967 | bool HasRevertedTokenIDToIdentifier = readBit(Bits); |
| Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 968 | bool HasRevertedBuiltin = readBit(Bits); |
| Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 969 | bool Poisoned = readBit(Bits); |
| 970 | bool ExtensionToken = readBit(Bits); |
| 971 | bool HadMacroDefinition = readBit(Bits); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 972 | |
| 973 | assert(Bits == 0 && "Extra bits in the identifier?"); |
| 974 | DataLen -= 8; |
| 975 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 976 | // Set or check the various bits in the IdentifierInfo structure. |
| 977 | // Token IDs are read-only. |
| Argyrios Kyrtzidis | ddee8c9 | 2013-02-27 01:13:51 +0000 | [diff] [blame] | 978 | if (HasRevertedTokenIDToIdentifier && II->getTokenID() != tok::identifier) |
| Richard Smith | 9c25418 | 2015-07-19 21:41:12 +0000 | [diff] [blame] | 979 | II->revertTokenIDToIdentifier(); |
| 980 | if (!F.isModule()) |
| 981 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 982 | else if (HasRevertedBuiltin && II->getBuiltinID()) { |
| 983 | II->revertBuiltin(); |
| 984 | assert((II->hasRevertedBuiltin() || |
| 985 | II->getObjCOrBuiltinID() == ObjCOrBuiltinID) && |
| 986 | "Incorrect ObjC keyword or builtin ID"); |
| 987 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 988 | assert(II->isExtensionToken() == ExtensionToken && |
| 989 | "Incorrect extension token flag"); |
| 990 | (void)ExtensionToken; |
| 991 | if (Poisoned) |
| 992 | II->setIsPoisoned(true); |
| 993 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 994 | "Incorrect C++ operator keyword flag"); |
| 995 | (void)CPlusPlusOperatorKeyword; |
| 996 | |
| 997 | // If this identifier is a macro, deserialize the macro |
| 998 | // definition. |
| Richard Smith | 76c2f2c | 2015-07-17 20:09:43 +0000 | [diff] [blame] | 999 | if (HadMacroDefinition) { |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1000 | uint32_t MacroDirectivesOffset = |
| 1001 | endian::readNext<uint32_t, little, unaligned>(d); |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1002 | DataLen -= 4; |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1003 | |
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1004 | Reader.addPendingMacro(II, &F, MacroDirectivesOffset); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | Reader.SetIdentifierInfo(ID, II); |
| 1008 | |
| 1009 | // Read all of the declarations visible at global scope with this |
| 1010 | // name. |
| 1011 | if (DataLen > 0) { |
| 1012 | SmallVector<uint32_t, 4> DeclIDs; |
| 1013 | for (; DataLen > 0; DataLen -= 4) |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1014 | DeclIDs.push_back(Reader.getGlobalDeclID( |
| 1015 | F, endian::readNext<uint32_t, little, unaligned>(d))); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1016 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
| 1017 | } |
| 1018 | |
| 1019 | return II; |
| 1020 | } |
| 1021 | |
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1022 | DeclarationNameKey::DeclarationNameKey(DeclarationName Name) |
| 1023 | : Kind(Name.getNameKind()) { |
| 1024 | switch (Kind) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1025 | case DeclarationName::Identifier: |
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1026 | Data = (uint64_t)Name.getAsIdentifierInfo(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1027 | break; |
| 1028 | case DeclarationName::ObjCZeroArgSelector: |
| 1029 | case DeclarationName::ObjCOneArgSelector: |
| 1030 | case DeclarationName::ObjCMultiArgSelector: |
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1031 | Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1032 | break; |
| 1033 | case DeclarationName::CXXOperatorName: |
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1034 | Data = Name.getCXXOverloadedOperator(); |
| 1035 | break; |
| 1036 | case DeclarationName::CXXLiteralOperatorName: |
| 1037 | Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 1038 | break; |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1039 | case DeclarationName::CXXDeductionGuideName: |
| 1040 | Data = (uint64_t)Name.getCXXDeductionGuideTemplate() |
| 1041 | ->getDeclName().getAsIdentifierInfo(); |
| 1042 | break; |
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1043 | case DeclarationName::CXXConstructorName: |
| 1044 | case DeclarationName::CXXDestructorName: |
| 1045 | case DeclarationName::CXXConversionFunctionName: |
| 1046 | case DeclarationName::CXXUsingDirective: |
| 1047 | Data = 0; |
| 1048 | break; |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | unsigned DeclarationNameKey::getHash() const { |
| 1053 | llvm::FoldingSetNodeID ID; |
| 1054 | ID.AddInteger(Kind); |
| 1055 | |
| 1056 | switch (Kind) { |
| 1057 | case DeclarationName::Identifier: |
| 1058 | case DeclarationName::CXXLiteralOperatorName: |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1059 | case DeclarationName::CXXDeductionGuideName: |
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1060 | ID.AddString(((IdentifierInfo*)Data)->getName()); |
| 1061 | break; |
| 1062 | case DeclarationName::ObjCZeroArgSelector: |
| 1063 | case DeclarationName::ObjCOneArgSelector: |
| 1064 | case DeclarationName::ObjCMultiArgSelector: |
| 1065 | ID.AddInteger(serialization::ComputeHash(Selector(Data))); |
| 1066 | break; |
| 1067 | case DeclarationName::CXXOperatorName: |
| 1068 | ID.AddInteger((OverloadedOperatorKind)Data); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1069 | break; |
| 1070 | case DeclarationName::CXXConstructorName: |
| 1071 | case DeclarationName::CXXDestructorName: |
| 1072 | case DeclarationName::CXXConversionFunctionName: |
| 1073 | case DeclarationName::CXXUsingDirective: |
| 1074 | break; |
| 1075 | } |
| 1076 | |
| 1077 | return ID.ComputeHash(); |
| 1078 | } |
| 1079 | |
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1080 | ModuleFile * |
| 1081 | ASTDeclContextNameLookupTrait::ReadFileRef(const unsigned char *&d) { |
| 1082 | using namespace llvm::support; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1083 | |
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1084 | uint32_t ModuleFileID = endian::readNext<uint32_t, little, unaligned>(d); |
| 1085 | return Reader.getLocalModuleFile(F, ModuleFileID); |
| 1086 | } |
| 1087 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1088 | std::pair<unsigned, unsigned> |
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1089 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char *&d) { |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1090 | using namespace llvm::support; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1091 | |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1092 | unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d); |
| 1093 | unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1094 | return std::make_pair(KeyLen, DataLen); |
| 1095 | } |
| 1096 | |
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1097 | ASTDeclContextNameLookupTrait::internal_key_type |
| 1098 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char *d, unsigned) { |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1099 | using namespace llvm::support; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1100 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 1101 | auto Kind = (DeclarationName::NameKind)*d++; |
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1102 | uint64_t Data; |
| 1103 | switch (Kind) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1104 | case DeclarationName::Identifier: |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 1105 | case DeclarationName::CXXLiteralOperatorName: |
| 1106 | case DeclarationName::CXXDeductionGuideName: |
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1107 | Data = (uint64_t)Reader.getLocalIdentifier( |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1108 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1109 | break; |
| 1110 | case DeclarationName::ObjCZeroArgSelector: |
| 1111 | case DeclarationName::ObjCOneArgSelector: |
| 1112 | case DeclarationName::ObjCMultiArgSelector: |
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1113 | Data = |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1114 | (uint64_t)Reader.getLocalSelector( |
| 1115 | F, endian::readNext<uint32_t, little, unaligned>( |
| 1116 | d)).getAsOpaquePtr(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1117 | break; |
| 1118 | case DeclarationName::CXXOperatorName: |
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1119 | Data = *d++; // OverloadedOperatorKind |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1120 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1121 | case DeclarationName::CXXConstructorName: |
| 1122 | case DeclarationName::CXXDestructorName: |
| 1123 | case DeclarationName::CXXConversionFunctionName: |
| 1124 | case DeclarationName::CXXUsingDirective: |
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1125 | Data = 0; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1126 | break; |
| 1127 | } |
| 1128 | |
| Richard Smith | a06c7e6 | 2015-08-26 23:55:49 +0000 | [diff] [blame] | 1129 | return DeclarationNameKey(Kind, Data); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1132 | void ASTDeclContextNameLookupTrait::ReadDataInto(internal_key_type, |
| 1133 | const unsigned char *d, |
| 1134 | unsigned DataLen, |
| 1135 | data_type_builder &Val) { |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1136 | using namespace llvm::support; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1137 | |
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1138 | for (unsigned NumDecls = DataLen / 4; NumDecls; --NumDecls) { |
| 1139 | uint32_t LocalID = endian::readNext<uint32_t, little, unaligned>(d); |
| 1140 | Val.insert(Reader.getGlobalDeclID(F, LocalID)); |
| 1141 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
| Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1144 | bool ASTReader::ReadLexicalDeclContextStorage(ModuleFile &M, |
| 1145 | BitstreamCursor &Cursor, |
| 1146 | uint64_t Offset, |
| 1147 | DeclContext *DC) { |
| 1148 | assert(Offset != 0); |
| 1149 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1150 | SavedStreamPosition SavedPosition(Cursor); |
| Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1151 | Cursor.JumpToBit(Offset); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1152 | |
| Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1153 | RecordData Record; |
| 1154 | StringRef Blob; |
| 1155 | unsigned Code = Cursor.ReadCode(); |
| 1156 | unsigned RecCode = Cursor.readRecord(Code, Record, &Blob); |
| 1157 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 1158 | Error("Expected lexical block"); |
| 1159 | return true; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
| Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 1162 | assert(!isa<TranslationUnitDecl>(DC) && |
| 1163 | "expected a TU_UPDATE_LEXICAL record for TU"); |
| Richard Smith | 9c9173d | 2015-08-11 22:00:24 +0000 | [diff] [blame] | 1164 | // If we are handling a C++ class template instantiation, we can see multiple |
| 1165 | // lexical updates for the same record. It's important that we select only one |
| 1166 | // of them, so that field numbering works properly. Just pick the first one we |
| 1167 | // see. |
| 1168 | auto &Lex = LexicalDecls[DC]; |
| 1169 | if (!Lex.first) { |
| 1170 | Lex = std::make_pair( |
| 1171 | &M, llvm::makeArrayRef( |
| 1172 | reinterpret_cast<const llvm::support::unaligned_uint32_t *>( |
| 1173 | Blob.data()), |
| 1174 | Blob.size() / 4)); |
| 1175 | } |
| Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1176 | DC->setHasExternalLexicalStorage(true); |
| 1177 | return false; |
| 1178 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1179 | |
| Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1180 | bool ASTReader::ReadVisibleDeclContextStorage(ModuleFile &M, |
| 1181 | BitstreamCursor &Cursor, |
| 1182 | uint64_t Offset, |
| 1183 | DeclID ID) { |
| 1184 | assert(Offset != 0); |
| 1185 | |
| 1186 | SavedStreamPosition SavedPosition(Cursor); |
| 1187 | Cursor.JumpToBit(Offset); |
| 1188 | |
| 1189 | RecordData Record; |
| 1190 | StringRef Blob; |
| 1191 | unsigned Code = Cursor.ReadCode(); |
| 1192 | unsigned RecCode = Cursor.readRecord(Code, Record, &Blob); |
| 1193 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 1194 | Error("Expected visible lookup table block"); |
| 1195 | return true; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
| Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 1198 | // We can't safely determine the primary context yet, so delay attaching the |
| 1199 | // lookup table until we're done with recursive deserialization. |
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1200 | auto *Data = (const unsigned char*)Blob.data(); |
| 1201 | PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&M, Data}); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1202 | return false; |
| 1203 | } |
| 1204 | |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 1205 | void ASTReader::Error(StringRef Msg) const { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1206 | Error(diag::err_fe_pch_malformed, Msg); |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 1207 | if (PP.getLangOpts().Modules && !Diags.isDiagnosticInFlight() && |
| Richard Smith | fb1e7f7 | 2015-08-14 05:02:58 +0000 | [diff] [blame] | 1208 | !PP.getHeaderSearchInfo().getModuleCachePath().empty()) { |
| Douglas Gregor | 940e805 | 2013-05-10 22:15:13 +0000 | [diff] [blame] | 1209 | Diag(diag::note_module_cache_path) |
| 1210 | << PP.getHeaderSearchInfo().getModuleCachePath(); |
| 1211 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
| 1214 | void ASTReader::Error(unsigned DiagID, |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 1215 | StringRef Arg1, StringRef Arg2) const { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1216 | if (Diags.isDiagnosticInFlight()) |
| 1217 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2); |
| 1218 | else |
| 1219 | Diag(DiagID) << Arg1 << Arg2; |
| 1220 | } |
| 1221 | |
| 1222 | //===----------------------------------------------------------------------===// |
| 1223 | // Source Manager Deserialization |
| 1224 | //===----------------------------------------------------------------------===// |
| 1225 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1226 | /// Read the line table in the source manager block. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1227 | /// \returns true if there was an error. |
| 1228 | bool ASTReader::ParseLineTable(ModuleFile &F, |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1229 | const RecordData &Record) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1230 | unsigned Idx = 0; |
| 1231 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1232 | |
| 1233 | // Parse the file names |
| 1234 | std::map<int, int> FileIDs; |
| Hans Wennborg | 1448736 | 2017-12-04 22:28:45 +0000 | [diff] [blame] | 1235 | FileIDs[-1] = -1; // For unspecified filenames. |
| Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1236 | for (unsigned I = 0; Record[Idx]; ++I) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1237 | // Extract the file name |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1238 | auto Filename = ReadPath(F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1239 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
| 1240 | } |
| Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1241 | ++Idx; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1242 | |
| 1243 | // Parse the line entries |
| 1244 | std::vector<LineEntry> Entries; |
| 1245 | while (Idx < Record.size()) { |
| 1246 | int FID = Record[Idx++]; |
| 1247 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 1248 | // Remap FileID from 1-based old view. |
| 1249 | FID += F.SLocEntryBaseID - 1; |
| 1250 | |
| 1251 | // Extract the line entries |
| 1252 | unsigned NumEntries = Record[Idx++]; |
| Richard Smith | 6307849 | 2015-09-01 07:41:55 +0000 | [diff] [blame] | 1253 | assert(NumEntries && "no line entries for file ID"); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1254 | Entries.clear(); |
| 1255 | Entries.reserve(NumEntries); |
| 1256 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1257 | unsigned FileOffset = Record[Idx++]; |
| 1258 | unsigned LineNo = Record[Idx++]; |
| 1259 | int FilenameID = FileIDs[Record[Idx++]]; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 1260 | SrcMgr::CharacteristicKind FileKind |
| 1261 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1262 | unsigned IncludeOffset = Record[Idx++]; |
| 1263 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1264 | FileKind, IncludeOffset)); |
| 1265 | } |
| 1266 | LineTable.AddEntry(FileID::get(FID), Entries); |
| 1267 | } |
| 1268 | |
| 1269 | return false; |
| 1270 | } |
| 1271 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1272 | /// Read a source manager block |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1273 | bool ASTReader::ReadSourceManagerBlock(ModuleFile &F) { |
| 1274 | using namespace SrcMgr; |
| 1275 | |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1276 | BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1277 | |
| 1278 | // Set the source-location entry cursor to the current position in |
| 1279 | // the stream. This cursor will be used to read the contents of the |
| 1280 | // source manager block initially, and then lazily read |
| 1281 | // source-location entries as needed. |
| 1282 | SLocEntryCursor = F.Stream; |
| 1283 | |
| 1284 | // The stream itself is going to skip over the source manager block. |
| 1285 | if (F.Stream.SkipBlock()) { |
| 1286 | Error("malformed block record in AST file"); |
| 1287 | return true; |
| 1288 | } |
| 1289 | |
| 1290 | // Enter the source manager block. |
| 1291 | if (SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
| 1292 | Error("malformed source manager block record in AST file"); |
| 1293 | return true; |
| 1294 | } |
| 1295 | |
| 1296 | RecordData Record; |
| 1297 | while (true) { |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1298 | llvm::BitstreamEntry E = SLocEntryCursor.advanceSkippingSubblocks(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1299 | |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1300 | switch (E.Kind) { |
| 1301 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1302 | case llvm::BitstreamEntry::Error: |
| 1303 | Error("malformed block record in AST file"); |
| 1304 | return true; |
| 1305 | case llvm::BitstreamEntry::EndBlock: |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1306 | return false; |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1307 | case llvm::BitstreamEntry::Record: |
| 1308 | // The interesting case. |
| 1309 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1310 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1311 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1312 | // Read a record. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1313 | Record.clear(); |
| Chris Lattner | 15c3e7d | 2013-01-21 18:28:26 +0000 | [diff] [blame] | 1314 | StringRef Blob; |
| 1315 | switch (SLocEntryCursor.readRecord(E.ID, Record, &Blob)) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1316 | default: // Default behavior: ignore. |
| 1317 | break; |
| 1318 | |
| 1319 | case SM_SLOC_FILE_ENTRY: |
| 1320 | case SM_SLOC_BUFFER_ENTRY: |
| 1321 | case SM_SLOC_EXPANSION_ENTRY: |
| 1322 | // Once we hit one of the source location entries, we're done. |
| 1323 | return false; |
| 1324 | } |
| 1325 | } |
| 1326 | } |
| 1327 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1328 | /// If a header file is not found at the path that we expect it to be |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1329 | /// and the PCH file was moved from its original location, try to resolve the |
| 1330 | /// file by assuming that header+PCH were moved together and the header is in |
| 1331 | /// the same place relative to the PCH. |
| 1332 | static std::string |
| 1333 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1334 | const std::string &OriginalDir, |
| 1335 | const std::string &CurrDir) { |
| 1336 | assert(OriginalDir != CurrDir && |
| 1337 | "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] | 1338 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1339 | using namespace llvm::sys; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1340 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1341 | SmallString<128> filePath(Filename); |
| 1342 | fs::make_absolute(filePath); |
| 1343 | assert(path::is_absolute(OriginalDir)); |
| 1344 | SmallString<128> currPCHPath(CurrDir); |
| 1345 | |
| 1346 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1347 | fileDirE = path::end(path::parent_path(filePath)); |
| 1348 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1349 | origDirE = path::end(OriginalDir); |
| 1350 | // Skip the common path components from filePath and OriginalDir. |
| 1351 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1352 | *fileDirI == *origDirI) { |
| 1353 | ++fileDirI; |
| 1354 | ++origDirI; |
| 1355 | } |
| 1356 | for (; origDirI != origDirE; ++origDirI) |
| 1357 | path::append(currPCHPath, ".."); |
| 1358 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1359 | path::append(currPCHPath, path::filename(Filename)); |
| 1360 | return currPCHPath.str(); |
| 1361 | } |
| 1362 | |
| 1363 | bool ASTReader::ReadSLocEntry(int ID) { |
| 1364 | if (ID == 0) |
| 1365 | return false; |
| 1366 | |
| 1367 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
| 1368 | Error("source location entry ID out-of-range for AST file"); |
| 1369 | return true; |
| 1370 | } |
| 1371 | |
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1372 | // Local helper to read the (possibly-compressed) buffer data following the |
| 1373 | // entry record. |
| 1374 | auto ReadBuffer = [this]( |
| 1375 | BitstreamCursor &SLocEntryCursor, |
| 1376 | StringRef Name) -> std::unique_ptr<llvm::MemoryBuffer> { |
| 1377 | RecordData Record; |
| 1378 | StringRef Blob; |
| 1379 | unsigned Code = SLocEntryCursor.ReadCode(); |
| 1380 | unsigned RecCode = SLocEntryCursor.readRecord(Code, Record, &Blob); |
| 1381 | |
| 1382 | if (RecCode == SM_SLOC_BUFFER_BLOB_COMPRESSED) { |
| George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 1383 | if (!llvm::zlib::isAvailable()) { |
| 1384 | Error("zlib is not available"); |
| 1385 | return nullptr; |
| 1386 | } |
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1387 | SmallString<0> Uncompressed; |
| George Rimar | c39f549 | 2017-01-17 15:45:31 +0000 | [diff] [blame] | 1388 | if (llvm::Error E = |
| 1389 | llvm::zlib::uncompress(Blob, Uncompressed, Record[0])) { |
| 1390 | Error("could not decompress embedded file contents: " + |
| 1391 | llvm::toString(std::move(E))); |
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1392 | return nullptr; |
| 1393 | } |
| 1394 | return llvm::MemoryBuffer::getMemBufferCopy(Uncompressed, Name); |
| 1395 | } else if (RecCode == SM_SLOC_BUFFER_BLOB) { |
| 1396 | return llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), Name, true); |
| 1397 | } else { |
| 1398 | Error("AST record has invalid code"); |
| 1399 | return nullptr; |
| 1400 | } |
| 1401 | }; |
| 1402 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1403 | ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second; |
| 1404 | F->SLocEntryCursor.JumpToBit(F->SLocEntryOffsets[ID - F->SLocEntryBaseID]); |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1405 | BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1406 | unsigned BaseOffset = F->SLocEntryBaseOffset; |
| 1407 | |
| 1408 | ++NumSLocEntriesRead; |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1409 | llvm::BitstreamEntry Entry = SLocEntryCursor.advance(); |
| 1410 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1411 | Error("incorrectly-formatted source location entry in AST file"); |
| 1412 | return true; |
| 1413 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1414 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1415 | RecordData Record; |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1416 | StringRef Blob; |
| 1417 | switch (SLocEntryCursor.readRecord(Entry.ID, Record, &Blob)) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1418 | default: |
| 1419 | Error("incorrectly-formatted source location entry in AST file"); |
| 1420 | return true; |
| 1421 | |
| 1422 | case SM_SLOC_FILE_ENTRY: { |
| 1423 | // We will detect whether a file changed and return 'Failure' for it, but |
| 1424 | // we will also try to fail gracefully by setting up the SLocEntry. |
| 1425 | unsigned InputID = Record[4]; |
| 1426 | InputFile IF = getInputFile(*F, InputID); |
| Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 1427 | const FileEntry *File = IF.getFile(); |
| 1428 | bool OverriddenBuffer = IF.isOverridden(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1429 | |
| Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 1430 | // Note that we only check if a File was returned. If it was out-of-date |
| 1431 | // we have complained but we will continue creating a FileID to recover |
| 1432 | // gracefully. |
| 1433 | if (!File) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1434 | return true; |
| 1435 | |
| 1436 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
| 1437 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
| 1438 | // This is the module's main file. |
| 1439 | IncludeLoc = getImportLocation(F); |
| 1440 | } |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 1441 | SrcMgr::CharacteristicKind |
| 1442 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1443 | FileID FID = SourceMgr.createFileID(File, IncludeLoc, FileCharacter, |
| 1444 | ID, BaseOffset + Record[0]); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 1445 | SrcMgr::FileInfo &FileInfo = |
| 1446 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1447 | FileInfo.NumCreatedFIDs = Record[5]; |
| 1448 | if (Record[3]) |
| 1449 | FileInfo.setHasLineDirectives(); |
| 1450 | |
| 1451 | const DeclID *FirstDecl = F->FileSortedDecls + Record[6]; |
| 1452 | unsigned NumFileDecls = Record[7]; |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 1453 | if (NumFileDecls && ContextObj) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1454 | assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?"); |
| 1455 | FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl, |
| 1456 | NumFileDecls)); |
| 1457 | } |
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1458 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1459 | const SrcMgr::ContentCache *ContentCache |
| Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1460 | = SourceMgr.getOrCreateContentCache(File, isSystem(FileCharacter)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1461 | if (OverriddenBuffer && !ContentCache->BufferOverridden && |
| Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 1462 | ContentCache->ContentsEntry == ContentCache->OrigEntry && |
| 1463 | !ContentCache->getRawBuffer()) { |
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1464 | auto Buffer = ReadBuffer(SLocEntryCursor, File->getName()); |
| 1465 | if (!Buffer) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1466 | return true; |
| David Blaikie | 49cc318 | 2014-08-27 20:54:45 +0000 | [diff] [blame] | 1467 | SourceMgr.overrideFileContents(File, std::move(Buffer)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | break; |
| 1471 | } |
| 1472 | |
| 1473 | case SM_SLOC_BUFFER_ENTRY: { |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1474 | const char *Name = Blob.data(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1475 | unsigned Offset = Record[0]; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 1476 | SrcMgr::CharacteristicKind |
| 1477 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1478 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
| Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 1479 | if (IncludeLoc.isInvalid() && F->isModule()) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1480 | IncludeLoc = getImportLocation(F); |
| 1481 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1482 | |
| Richard Smith | aada85c | 2016-02-06 02:06:43 +0000 | [diff] [blame] | 1483 | auto Buffer = ReadBuffer(SLocEntryCursor, Name); |
| 1484 | if (!Buffer) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1485 | return true; |
| David Blaikie | 50a5f97 | 2014-08-29 07:59:55 +0000 | [diff] [blame] | 1486 | SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID, |
| Rafael Espindola | d87f8d7 | 2014-08-27 20:03:29 +0000 | [diff] [blame] | 1487 | BaseOffset + Offset, IncludeLoc); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1488 | break; |
| 1489 | } |
| 1490 | |
| 1491 | case SM_SLOC_EXPANSION_ENTRY: { |
| 1492 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
| 1493 | SourceMgr.createExpansionLoc(SpellingLoc, |
| 1494 | ReadSourceLocation(*F, Record[2]), |
| 1495 | ReadSourceLocation(*F, Record[3]), |
| Richard Smith | b5f8171 | 2018-04-30 05:25:48 +0000 | [diff] [blame] | 1496 | Record[5], |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1497 | Record[4], |
| 1498 | ID, |
| 1499 | BaseOffset + Record[0]); |
| 1500 | break; |
| 1501 | } |
| 1502 | } |
| 1503 | |
| 1504 | return false; |
| 1505 | } |
| 1506 | |
| 1507 | std::pair<SourceLocation, StringRef> ASTReader::getModuleImportLoc(int ID) { |
| 1508 | if (ID == 0) |
| 1509 | return std::make_pair(SourceLocation(), ""); |
| 1510 | |
| 1511 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
| 1512 | Error("source location entry ID out-of-range for AST file"); |
| 1513 | return std::make_pair(SourceLocation(), ""); |
| 1514 | } |
| 1515 | |
| 1516 | // Find which module file this entry lands in. |
| 1517 | ModuleFile *M = GlobalSLocEntryMap.find(-ID)->second; |
| Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 1518 | if (!M->isModule()) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1519 | return std::make_pair(SourceLocation(), ""); |
| 1520 | |
| 1521 | // FIXME: Can we map this down to a particular submodule? That would be |
| 1522 | // ideal. |
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1523 | return std::make_pair(M->ImportLoc, StringRef(M->ModuleName)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1526 | /// Find the location where the module F is imported. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1527 | SourceLocation ASTReader::getImportLocation(ModuleFile *F) { |
| 1528 | if (F->ImportLoc.isValid()) |
| 1529 | return F->ImportLoc; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1530 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1531 | // Otherwise we have a PCH. It's considered to be "imported" at the first |
| 1532 | // location of its includer. |
| 1533 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1534 | // Main file is the importer. |
| Yaron Keren | 8b56366 | 2015-10-03 10:46:20 +0000 | [diff] [blame] | 1535 | assert(SourceMgr.getMainFileID().isValid() && "missing main file"); |
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 1536 | return SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1537 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1538 | return F->ImportedBy[0]->FirstLoc; |
| 1539 | } |
| 1540 | |
| 1541 | /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the |
| 1542 | /// specified cursor. Read the abbreviations that are at the top of the block |
| 1543 | /// and then leave the cursor pointing into the block. |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1544 | bool ASTReader::ReadBlockAbbrevs(BitstreamCursor &Cursor, unsigned BlockID) { |
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 1545 | if (Cursor.EnterSubBlock(BlockID)) |
| 1546 | return true; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1547 | |
| 1548 | while (true) { |
| 1549 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
| 1550 | unsigned Code = Cursor.ReadCode(); |
| 1551 | |
| 1552 | // We expect all abbrevs to be at the start of the block. |
| 1553 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1554 | Cursor.JumpToBit(Offset); |
| 1555 | return false; |
| 1556 | } |
| 1557 | Cursor.ReadAbbrevRecord(); |
| 1558 | } |
| 1559 | } |
| 1560 | |
| Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 1561 | Token ASTReader::ReadToken(ModuleFile &F, const RecordDataImpl &Record, |
| John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1562 | unsigned &Idx) { |
| 1563 | Token Tok; |
| 1564 | Tok.startToken(); |
| 1565 | Tok.setLocation(ReadSourceLocation(F, Record, Idx)); |
| 1566 | Tok.setLength(Record[Idx++]); |
| 1567 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[Idx++])) |
| 1568 | Tok.setIdentifierInfo(II); |
| 1569 | Tok.setKind((tok::TokenKind)Record[Idx++]); |
| 1570 | Tok.setFlag((Token::TokenFlags)Record[Idx++]); |
| 1571 | return Tok; |
| 1572 | } |
| 1573 | |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1574 | MacroInfo *ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) { |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1575 | BitstreamCursor &Stream = F.MacroCursor; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1576 | |
| 1577 | // Keep track of where we are in the stream, then jump back there |
| 1578 | // after reading this macro. |
| 1579 | SavedStreamPosition SavedPosition(Stream); |
| 1580 | |
| 1581 | Stream.JumpToBit(Offset); |
| 1582 | RecordData Record; |
| Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame] | 1583 | SmallVector<IdentifierInfo*, 16> MacroParams; |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1584 | MacroInfo *Macro = nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1585 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1586 | while (true) { |
| Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1587 | // Advance to the next record, but if we get to the end of the block, don't |
| 1588 | // pop it (removing all the abbreviations from the cursor) since we want to |
| 1589 | // be able to reseek within the block and read entries. |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1590 | unsigned Flags = BitstreamCursor::AF_DontPopBlockAtEnd; |
| Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1591 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(Flags); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1592 | |
| Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1593 | switch (Entry.Kind) { |
| 1594 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1595 | case llvm::BitstreamEntry::Error: |
| 1596 | Error("malformed block record in AST file"); |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1597 | return Macro; |
| Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1598 | case llvm::BitstreamEntry::EndBlock: |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1599 | return Macro; |
| Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 1600 | case llvm::BitstreamEntry::Record: |
| 1601 | // The interesting case. |
| 1602 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | // Read a record. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1606 | Record.clear(); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 1607 | PreprocessorRecordTypes RecType = |
| 1608 | (PreprocessorRecordTypes)Stream.readRecord(Entry.ID, Record); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1609 | switch (RecType) { |
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1610 | case PP_MODULE_MACRO: |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1611 | case PP_MACRO_DIRECTIVE_HISTORY: |
| 1612 | return Macro; |
| 1613 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1614 | case PP_MACRO_OBJECT_LIKE: |
| 1615 | case PP_MACRO_FUNCTION_LIKE: { |
| 1616 | // If we already have a macro, that means that we've hit the end |
| 1617 | // of the definition of the macro we were looking for. We're |
| 1618 | // done. |
| 1619 | if (Macro) |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1620 | return Macro; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1621 | |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1622 | unsigned NextIndex = 1; // Skip identifier ID. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1623 | SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex); |
| Richard Smith | 3f6dd7a | 2017-05-12 23:40:52 +0000 | [diff] [blame] | 1624 | MacroInfo *MI = PP.AllocateMacroInfo(Loc); |
| Argyrios Kyrtzidis | 7572be2 | 2013-01-07 19:16:23 +0000 | [diff] [blame] | 1625 | MI->setDefinitionEndLoc(ReadSourceLocation(F, Record, NextIndex)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1626 | MI->setIsUsed(Record[NextIndex++]); |
| Argyrios Kyrtzidis | 9ef53ce | 2014-04-09 18:21:23 +0000 | [diff] [blame] | 1627 | MI->setUsedForHeaderGuard(Record[NextIndex++]); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1628 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1629 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
| 1630 | // Decode function-like macro info. |
| 1631 | bool isC99VarArgs = Record[NextIndex++]; |
| 1632 | bool isGNUVarArgs = Record[NextIndex++]; |
| 1633 | bool hasCommaPasting = Record[NextIndex++]; |
| Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame] | 1634 | MacroParams.clear(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1635 | unsigned NumArgs = Record[NextIndex++]; |
| 1636 | for (unsigned i = 0; i != NumArgs; ++i) |
| Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame] | 1637 | MacroParams.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1638 | |
| 1639 | // Install function-like macro info. |
| 1640 | MI->setIsFunctionLike(); |
| 1641 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1642 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
| 1643 | if (hasCommaPasting) MI->setHasCommaPasting(); |
| Faisal Vali | ac506d7 | 2017-07-17 17:18:43 +0000 | [diff] [blame] | 1644 | MI->setParameterList(MacroParams, PP.getPreprocessorAllocator()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1645 | } |
| 1646 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1647 | // Remember that we saw this macro last so that we add the tokens that |
| 1648 | // form its body to it. |
| 1649 | Macro = MI; |
| 1650 | |
| 1651 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() && |
| 1652 | Record[NextIndex]) { |
| 1653 | // We have a macro definition. Register the association |
| 1654 | PreprocessedEntityID |
| 1655 | GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]); |
| 1656 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 1657 | PreprocessingRecord::PPEntityID PPID = |
| 1658 | PPRec.getPPEntityID(GlobalID - 1, /*isLoaded=*/true); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 1659 | MacroDefinitionRecord *PPDef = cast_or_null<MacroDefinitionRecord>( |
| Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 1660 | PPRec.getPreprocessedEntity(PPID)); |
| Argyrios Kyrtzidis | 832de9f | 2013-02-22 18:35:59 +0000 | [diff] [blame] | 1661 | if (PPDef) |
| 1662 | PPRec.RegisterMacroDefinition(Macro, PPDef); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | ++NumMacrosRead; |
| 1666 | break; |
| 1667 | } |
| 1668 | |
| 1669 | case PP_TOKEN: { |
| 1670 | // If we see a TOKEN before a PP_MACRO_*, then the file is |
| 1671 | // erroneous, just pretend we didn't see this. |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1672 | if (!Macro) break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1673 | |
| John McCall | f413f5e | 2013-05-03 00:10:13 +0000 | [diff] [blame] | 1674 | unsigned Idx = 0; |
| 1675 | Token Tok = ReadToken(F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1676 | Macro->AddTokenToBody(Tok); |
| 1677 | break; |
| 1678 | } |
| 1679 | } |
| 1680 | } |
| 1681 | } |
| 1682 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1683 | PreprocessedEntityID |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 1684 | ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M, |
| 1685 | unsigned LocalID) const { |
| 1686 | if (!M.ModuleOffsetMap.empty()) |
| 1687 | ReadModuleOffsetMap(M); |
| 1688 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1689 | ContinuousRangeMap<uint32_t, int, 2>::const_iterator |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1690 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1691 | assert(I != M.PreprocessedEntityRemap.end() |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1692 | && "Invalid index into preprocessed entity index remap"); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1693 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1694 | return LocalID + I->second; |
| 1695 | } |
| 1696 | |
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1697 | unsigned HeaderFileInfoTrait::ComputeHash(internal_key_ref ikey) { |
| 1698 | return llvm::hash_combine(ikey.Size, ikey.ModTime); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1699 | } |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1700 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1701 | HeaderFileInfoTrait::internal_key_type |
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1702 | HeaderFileInfoTrait::GetInternalKey(const FileEntry *FE) { |
| Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1703 | internal_key_type ikey = {FE->getSize(), |
| 1704 | M.HasTimestamps ? FE->getModificationTime() : 0, |
| 1705 | FE->getName(), /*Imported*/ false}; |
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1706 | return ikey; |
| 1707 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1708 | |
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1709 | bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) { |
| Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 1710 | 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] | 1711 | return false; |
| 1712 | |
| Mehdi Amini | 004b9c7 | 2016-10-10 22:52:47 +0000 | [diff] [blame] | 1713 | if (llvm::sys::path::is_absolute(a.Filename) && a.Filename == b.Filename) |
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1714 | return true; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1715 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1716 | // Determine whether the actual files are equivalent. |
| Argyrios Kyrtzidis | 2a513e8 | 2013-03-04 20:33:40 +0000 | [diff] [blame] | 1717 | FileManager &FileMgr = Reader.getFileManager(); |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1718 | auto GetFile = [&](const internal_key_type &Key) -> const FileEntry* { |
| 1719 | if (!Key.Imported) |
| 1720 | return FileMgr.getFile(Key.Filename); |
| 1721 | |
| 1722 | std::string Resolved = Key.Filename; |
| 1723 | Reader.ResolveImportedPath(M, Resolved); |
| 1724 | return FileMgr.getFile(Resolved); |
| 1725 | }; |
| 1726 | |
| 1727 | const FileEntry *FEA = GetFile(a); |
| 1728 | const FileEntry *FEB = GetFile(b); |
| 1729 | return FEA && FEA == FEB; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1730 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1731 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1732 | std::pair<unsigned, unsigned> |
| 1733 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1734 | using namespace llvm::support; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1735 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 1736 | unsigned KeyLen = (unsigned) endian::readNext<uint16_t, little, unaligned>(d); |
| 1737 | unsigned DataLen = (unsigned) *d++; |
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1738 | return std::make_pair(KeyLen, DataLen); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1739 | } |
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1740 | |
| 1741 | HeaderFileInfoTrait::internal_key_type |
| 1742 | HeaderFileInfoTrait::ReadKey(const unsigned char *d, unsigned) { |
| 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 | |
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1745 | internal_key_type ikey; |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1746 | ikey.Size = off_t(endian::readNext<uint64_t, little, unaligned>(d)); |
| 1747 | ikey.ModTime = time_t(endian::readNext<uint64_t, little, unaligned>(d)); |
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1748 | ikey.Filename = (const char *)d; |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 1749 | ikey.Imported = true; |
| Argyrios Kyrtzidis | 5c2a345 | 2013-03-06 18:12:47 +0000 | [diff] [blame] | 1750 | return ikey; |
| 1751 | } |
| 1752 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1753 | HeaderFileInfoTrait::data_type |
| Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1754 | HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1755 | unsigned DataLen) { |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1756 | using namespace llvm::support; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1757 | |
| 1758 | const unsigned char *End = d + DataLen; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1759 | HeaderFileInfo HFI; |
| 1760 | unsigned Flags = *d++; |
| Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1761 | // FIXME: Refactor with mergeHeaderFileInfo in HeaderSearch.cpp. |
| Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 1762 | HFI.isImport |= (Flags >> 5) & 0x01; |
| 1763 | HFI.isPragmaOnce |= (Flags >> 4) & 0x01; |
| 1764 | HFI.DirInfo = (Flags >> 1) & 0x07; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1765 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
| Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1766 | // FIXME: Find a better way to handle this. Maybe just store a |
| 1767 | // "has been included" flag? |
| 1768 | HFI.NumIncludes = std::max(endian::readNext<uint16_t, little, unaligned>(d), |
| 1769 | HFI.NumIncludes); |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1770 | HFI.ControllingMacroID = Reader.getGlobalIdentifierID( |
| 1771 | M, endian::readNext<uint32_t, little, unaligned>(d)); |
| 1772 | if (unsigned FrameworkOffset = |
| 1773 | endian::readNext<uint32_t, little, unaligned>(d)) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1774 | // The framework offset is 1 greater than the actual offset, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1775 | // since 0 is used as an indicator for "no framework name". |
| 1776 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1777 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1778 | } |
| Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1779 | |
| 1780 | assert((End - d) % 4 == 0 && |
| 1781 | "Wrong data length in HeaderFileInfo deserialization"); |
| 1782 | while (d != End) { |
| Justin Bogner | 57ba0b2 | 2014-03-28 22:03:24 +0000 | [diff] [blame] | 1783 | uint32_t LocalSMID = endian::readNext<uint32_t, little, unaligned>(d); |
| Richard Smith | 386bb07 | 2015-08-18 23:42:23 +0000 | [diff] [blame] | 1784 | auto HeaderRole = static_cast<ModuleMap::ModuleHeaderRole>(LocalSMID & 3); |
| 1785 | LocalSMID >>= 2; |
| 1786 | |
| 1787 | // This header is part of a module. Associate it with the module to enable |
| 1788 | // implicit module import. |
| 1789 | SubmoduleID GlobalSMID = Reader.getGlobalSubmoduleID(M, LocalSMID); |
| 1790 | Module *Mod = Reader.getSubmodule(GlobalSMID); |
| 1791 | FileManager &FileMgr = Reader.getFileManager(); |
| 1792 | ModuleMap &ModMap = |
| 1793 | Reader.getPreprocessor().getHeaderSearchInfo().getModuleMap(); |
| 1794 | |
| 1795 | std::string Filename = key.Filename; |
| 1796 | if (key.Imported) |
| 1797 | Reader.ResolveImportedPath(M, Filename); |
| 1798 | // FIXME: This is not always the right filename-as-written, but we're not |
| 1799 | // going to use this information to rebuild the module, so it doesn't make |
| 1800 | // a lot of difference. |
| 1801 | Module::Header H = { key.Filename, FileMgr.getFile(Filename) }; |
| Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1802 | ModMap.addHeader(Mod, H, HeaderRole, /*Imported*/true); |
| 1803 | HFI.isModuleHeader |= !(HeaderRole & ModuleMap::TextualHeader); |
| Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1806 | // This HeaderFileInfo was externally loaded. |
| 1807 | HFI.External = true; |
| Richard Smith | d8879c8 | 2015-08-24 21:59:32 +0000 | [diff] [blame] | 1808 | HFI.IsValid = true; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1809 | return HFI; |
| 1810 | } |
| 1811 | |
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1812 | void ASTReader::addPendingMacro(IdentifierInfo *II, |
| 1813 | ModuleFile *M, |
| 1814 | uint64_t MacroDirectivesOffset) { |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1815 | assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard"); |
| 1816 | PendingMacroIDs[II].push_back(PendingMacroInfo(M, MacroDirectivesOffset)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1817 | } |
| 1818 | |
| 1819 | void ASTReader::ReadDefinedMacros() { |
| 1820 | // Note that we are loading defined macros. |
| 1821 | Deserializing Macros(this); |
| 1822 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 1823 | for (ModuleFile &I : llvm::reverse(ModuleMgr)) { |
| Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1824 | BitstreamCursor &MacroCursor = I.MacroCursor; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1825 | |
| 1826 | // If there was no preprocessor block, skip this file. |
| Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 1827 | if (MacroCursor.getBitcodeBytes().empty()) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1828 | continue; |
| 1829 | |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 1830 | BitstreamCursor Cursor = MacroCursor; |
| Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1831 | Cursor.JumpToBit(I.MacroStartOffset); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1832 | |
| 1833 | RecordData Record; |
| 1834 | while (true) { |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1835 | llvm::BitstreamEntry E = Cursor.advanceSkippingSubblocks(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1836 | |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1837 | switch (E.Kind) { |
| 1838 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 1839 | case llvm::BitstreamEntry::Error: |
| 1840 | Error("malformed block record in AST file"); |
| 1841 | return; |
| 1842 | case llvm::BitstreamEntry::EndBlock: |
| 1843 | goto NextCursor; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1844 | |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1845 | case llvm::BitstreamEntry::Record: |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1846 | Record.clear(); |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 1847 | switch (Cursor.readRecord(E.ID, Record)) { |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1848 | default: // Default behavior: ignore. |
| 1849 | break; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1850 | |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1851 | case PP_MACRO_OBJECT_LIKE: |
| Sean Callanan | f3682a7 | 2016-05-14 06:24:14 +0000 | [diff] [blame] | 1852 | case PP_MACRO_FUNCTION_LIKE: { |
| Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 1853 | IdentifierInfo *II = getLocalIdentifier(I, Record[0]); |
| Sean Callanan | f3682a7 | 2016-05-14 06:24:14 +0000 | [diff] [blame] | 1854 | if (II->isOutOfDate()) |
| 1855 | updateOutOfDateIdentifier(*II); |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1856 | break; |
| Sean Callanan | f3682a7 | 2016-05-14 06:24:14 +0000 | [diff] [blame] | 1857 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1858 | |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1859 | case PP_TOKEN: |
| 1860 | // Ignore tokens. |
| 1861 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1862 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1863 | break; |
| 1864 | } |
| 1865 | } |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 1866 | NextCursor: ; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1867 | } |
| 1868 | } |
| 1869 | |
| 1870 | namespace { |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1871 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1872 | /// Visitor class used to look up identifirs in an AST file. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1873 | class IdentifierLookupVisitor { |
| 1874 | StringRef Name; |
| Richard Smith | 3b63741 | 2015-07-14 18:42:41 +0000 | [diff] [blame] | 1875 | unsigned NameHash; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1876 | unsigned PriorGeneration; |
| Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1877 | unsigned &NumIdentifierLookups; |
| 1878 | unsigned &NumIdentifierLookupHits; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1879 | IdentifierInfo *Found = nullptr; |
| Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1880 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1881 | public: |
| Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1882 | IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration, |
| 1883 | unsigned &NumIdentifierLookups, |
| 1884 | unsigned &NumIdentifierLookupHits) |
| Richard Smith | 3b63741 | 2015-07-14 18:42:41 +0000 | [diff] [blame] | 1885 | : Name(Name), NameHash(ASTIdentifierLookupTrait::ComputeHash(Name)), |
| 1886 | PriorGeneration(PriorGeneration), |
| Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1887 | NumIdentifierLookups(NumIdentifierLookups), |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1888 | NumIdentifierLookupHits(NumIdentifierLookupHits) {} |
| Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 1889 | |
| 1890 | bool operator()(ModuleFile &M) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1891 | // If we've already searched this module file, skip it now. |
| Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1892 | if (M.Generation <= PriorGeneration) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1893 | return true; |
| Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1894 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 1895 | ASTIdentifierLookupTable *IdTable |
| 1896 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1897 | if (!IdTable) |
| 1898 | return false; |
| Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 1899 | |
| 1900 | ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), M, |
| Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1901 | Found); |
| 1902 | ++NumIdentifierLookups; |
| Richard Smith | 3b63741 | 2015-07-14 18:42:41 +0000 | [diff] [blame] | 1903 | ASTIdentifierLookupTable::iterator Pos = |
| Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1904 | IdTable->find_hashed(Name, NameHash, &Trait); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1905 | if (Pos == IdTable->end()) |
| 1906 | return false; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1907 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1908 | // Dereferencing the iterator has the effect of building the |
| 1909 | // IdentifierInfo node and populating it with the various |
| 1910 | // declarations it needs. |
| Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 1911 | ++NumIdentifierLookupHits; |
| 1912 | Found = *Pos; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1913 | return true; |
| 1914 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1915 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1916 | // Retrieve the identifier info found within the module |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1917 | // files. |
| 1918 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 1919 | }; |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 1920 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 1921 | } // namespace |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1922 | |
| 1923 | void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { |
| 1924 | // Note that we are loading an identifier. |
| 1925 | Deserializing AnIdentifier(this); |
| 1926 | |
| 1927 | unsigned PriorGeneration = 0; |
| 1928 | if (getContext().getLangOpts().Modules) |
| 1929 | PriorGeneration = IdentifierGeneration[&II]; |
| Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1930 | |
| 1931 | // If there is a global index, look there first to determine which modules |
| 1932 | // provably do not have any results for this identifier. |
| Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1933 | GlobalModuleIndex::HitSet Hits; |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1934 | GlobalModuleIndex::HitSet *HitsPtr = nullptr; |
| Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1935 | if (!loadGlobalIndex()) { |
| Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1936 | if (GlobalIndex->lookupIdentifier(II.getName(), Hits)) { |
| 1937 | HitsPtr = &Hits; |
| Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 1938 | } |
| 1939 | } |
| 1940 | |
| Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 1941 | IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration, |
| Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 1942 | NumIdentifierLookups, |
| 1943 | NumIdentifierLookupHits); |
| Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 1944 | ModuleMgr.visit(Visitor, HitsPtr); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1945 | markIdentifierUpToDate(&II); |
| 1946 | } |
| 1947 | |
| 1948 | void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { |
| 1949 | if (!II) |
| 1950 | return; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1951 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1952 | II->setOutOfDate(false); |
| 1953 | |
| 1954 | // Update the generation for this identifier. |
| 1955 | if (getContext().getLangOpts().Modules) |
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1956 | IdentifierGeneration[II] = getGeneration(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 1957 | } |
| 1958 | |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1959 | void ASTReader::resolvePendingMacro(IdentifierInfo *II, |
| 1960 | const PendingMacroInfo &PMInfo) { |
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1961 | ModuleFile &M = *PMInfo.M; |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1962 | |
| 1963 | BitstreamCursor &Cursor = M.MacroCursor; |
| 1964 | SavedStreamPosition SavedPosition(Cursor); |
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1965 | Cursor.JumpToBit(PMInfo.MacroDirectivesOffset); |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1966 | |
| Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1967 | struct ModuleMacroRecord { |
| 1968 | SubmoduleID SubModID; |
| 1969 | MacroInfo *MI; |
| 1970 | SmallVector<SubmoduleID, 8> Overrides; |
| 1971 | }; |
| 1972 | llvm::SmallVector<ModuleMacroRecord, 8> ModuleMacros; |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1973 | |
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1974 | // We expect to see a sequence of PP_MODULE_MACRO records listing exported |
| 1975 | // macros, followed by a PP_MACRO_DIRECTIVE_HISTORY record with the complete |
| 1976 | // macro histroy. |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 1977 | RecordData Record; |
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1978 | while (true) { |
| 1979 | llvm::BitstreamEntry Entry = |
| 1980 | Cursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd); |
| 1981 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| 1982 | Error("malformed block record in AST file"); |
| 1983 | return; |
| 1984 | } |
| 1985 | |
| 1986 | Record.clear(); |
| Aaron Ballman | c75a192 | 2015-04-22 15:25:05 +0000 | [diff] [blame] | 1987 | switch ((PreprocessorRecordTypes)Cursor.readRecord(Entry.ID, Record)) { |
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1988 | case PP_MACRO_DIRECTIVE_HISTORY: |
| 1989 | break; |
| 1990 | |
| 1991 | case PP_MODULE_MACRO: { |
| Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1992 | ModuleMacros.push_back(ModuleMacroRecord()); |
| 1993 | auto &Info = ModuleMacros.back(); |
| Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 1994 | Info.SubModID = getGlobalSubmoduleID(M, Record[0]); |
| 1995 | Info.MI = getMacro(getGlobalMacroID(M, Record[1])); |
| Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 1996 | for (int I = 2, N = Record.size(); I != N; ++I) |
| 1997 | Info.Overrides.push_back(getGlobalSubmoduleID(M, Record[I])); |
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 1998 | continue; |
| 1999 | } |
| 2000 | |
| 2001 | default: |
| 2002 | Error("malformed block record in AST file"); |
| 2003 | return; |
| 2004 | } |
| 2005 | |
| 2006 | // We found the macro directive history; that's the last record |
| 2007 | // for this macro. |
| 2008 | break; |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2009 | } |
| 2010 | |
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2011 | // Module macros are listed in reverse dependency order. |
| Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 2012 | { |
| 2013 | std::reverse(ModuleMacros.begin(), ModuleMacros.end()); |
| Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 2014 | llvm::SmallVector<ModuleMacro*, 8> Overrides; |
| Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2015 | for (auto &MMR : ModuleMacros) { |
| Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 2016 | Overrides.clear(); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 2017 | for (unsigned ModID : MMR.Overrides) { |
| Richard Smith | b8b2ed6 | 2015-04-23 18:18:26 +0000 | [diff] [blame] | 2018 | Module *Mod = getSubmodule(ModID); |
| 2019 | auto *Macro = PP.getModuleMacro(Mod, II); |
| Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 2020 | assert(Macro && "missing definition for overridden macro"); |
| Richard Smith | 5dbef92 | 2015-04-22 02:09:43 +0000 | [diff] [blame] | 2021 | Overrides.push_back(Macro); |
| Richard Smith | e56c8bc | 2015-04-22 00:26:11 +0000 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | bool Inserted = false; |
| Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2025 | Module *Owner = getSubmodule(MMR.SubModID); |
| Richard Smith | 20e883e | 2015-04-29 23:20:19 +0000 | [diff] [blame] | 2026 | PP.addModuleMacro(Owner, II, MMR.MI, Overrides, Inserted); |
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2027 | } |
| 2028 | } |
| 2029 | |
| 2030 | // Don't read the directive history for a module; we don't have anywhere |
| 2031 | // to put it. |
| Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2032 | if (M.isModule()) |
| Richard Smith | d732939 | 2015-04-21 21:46:32 +0000 | [diff] [blame] | 2033 | return; |
| 2034 | |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2035 | // Deserialize the macro directives history in reverse source-order. |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 2036 | MacroDirective *Latest = nullptr, *Earliest = nullptr; |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2037 | unsigned Idx = 0, N = Record.size(); |
| 2038 | while (Idx < N) { |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 2039 | MacroDirective *MD = nullptr; |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2040 | SourceLocation Loc = ReadSourceLocation(M, Record, Idx); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 2041 | MacroDirective::Kind K = (MacroDirective::Kind)Record[Idx++]; |
| Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2042 | switch (K) { |
| 2043 | case MacroDirective::MD_Define: { |
| Richard Smith | 713369b | 2015-04-23 20:40:50 +0000 | [diff] [blame] | 2044 | MacroInfo *MI = getMacro(getGlobalMacroID(M, Record[Idx++])); |
| Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 2045 | MD = PP.AllocateDefMacroDirective(MI, Loc); |
| Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2046 | break; |
| 2047 | } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 2048 | case MacroDirective::MD_Undefine: |
| Richard Smith | 3981b17 | 2015-04-30 02:16:23 +0000 | [diff] [blame] | 2049 | MD = PP.AllocateUndefMacroDirective(Loc); |
| Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2050 | break; |
| Richard Smith | daa69e0 | 2014-07-25 04:40:03 +0000 | [diff] [blame] | 2051 | case MacroDirective::MD_Visibility: |
| Argyrios Kyrtzidis | b6210df | 2013-03-26 17:17:01 +0000 | [diff] [blame] | 2052 | bool isPublic = Record[Idx++]; |
| 2053 | MD = PP.AllocateVisibilityMacroDirective(Loc, isPublic); |
| 2054 | break; |
| 2055 | } |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2056 | |
| 2057 | if (!Latest) |
| 2058 | Latest = MD; |
| 2059 | if (Earliest) |
| 2060 | Earliest->setPrevious(MD); |
| 2061 | Earliest = MD; |
| 2062 | } |
| 2063 | |
| Richard Smith | d6e8c0d | 2015-05-04 19:58:00 +0000 | [diff] [blame] | 2064 | if (Latest) |
| Nico Weber | fd87070 | 2016-12-09 17:32:52 +0000 | [diff] [blame] | 2065 | PP.setLoadedMacroDirective(II, Earliest, Latest); |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 2066 | } |
| 2067 | |
| Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 2068 | ASTReader::InputFileInfo |
| 2069 | ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) { |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2070 | // Go find this input file. |
| 2071 | BitstreamCursor &Cursor = F.InputFilesCursor; |
| 2072 | SavedStreamPosition SavedPosition(Cursor); |
| 2073 | Cursor.JumpToBit(F.InputFileOffsets[ID-1]); |
| 2074 | |
| 2075 | unsigned Code = Cursor.ReadCode(); |
| 2076 | RecordData Record; |
| 2077 | StringRef Blob; |
| 2078 | |
| 2079 | unsigned Result = Cursor.readRecord(Code, Record, &Blob); |
| 2080 | assert(static_cast<InputFileRecordTypes>(Result) == INPUT_FILE && |
| 2081 | "invalid record type for input file"); |
| 2082 | (void)Result; |
| 2083 | |
| 2084 | assert(Record[0] == ID && "Bogus stored ID or offset"); |
| Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2085 | InputFileInfo R; |
| 2086 | R.StoredSize = static_cast<off_t>(Record[1]); |
| 2087 | R.StoredTime = static_cast<time_t>(Record[2]); |
| 2088 | R.Overridden = static_cast<bool>(Record[3]); |
| 2089 | R.Transient = static_cast<bool>(Record[4]); |
| Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 2090 | R.TopLevelModuleMap = static_cast<bool>(Record[5]); |
| Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2091 | R.Filename = Blob; |
| 2092 | ResolveImportedPath(F, R.Filename); |
| Hans Wennborg | 7394514 | 2014-03-14 17:45:06 +0000 | [diff] [blame] | 2093 | return R; |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2094 | } |
| 2095 | |
| Manman Ren | c8c9415 | 2016-10-21 23:35:03 +0000 | [diff] [blame] | 2096 | static unsigned moduleKindForDiagnostic(ModuleKind Kind); |
| Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2097 | InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2098 | // If this ID is bogus, just return an empty input file. |
| 2099 | if (ID == 0 || ID > F.InputFilesLoaded.size()) |
| 2100 | return InputFile(); |
| 2101 | |
| 2102 | // If we've already loaded this input file, return it. |
| Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2103 | if (F.InputFilesLoaded[ID-1].getFile()) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2104 | return F.InputFilesLoaded[ID-1]; |
| 2105 | |
| Argyrios Kyrtzidis | 9308f0a | 2014-01-08 19:13:34 +0000 | [diff] [blame] | 2106 | if (F.InputFilesLoaded[ID-1].isNotFound()) |
| 2107 | return InputFile(); |
| 2108 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2109 | // Go find this input file. |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2110 | BitstreamCursor &Cursor = F.InputFilesCursor; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2111 | SavedStreamPosition SavedPosition(Cursor); |
| 2112 | Cursor.JumpToBit(F.InputFileOffsets[ID-1]); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2113 | |
| Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 2114 | InputFileInfo FI = readInputFileInfo(F, ID); |
| 2115 | off_t StoredSize = FI.StoredSize; |
| 2116 | time_t StoredTime = FI.StoredTime; |
| 2117 | bool Overridden = FI.Overridden; |
| Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2118 | bool Transient = FI.Transient; |
| Argyrios Kyrtzidis | ce9b49e | 2014-03-14 02:26:27 +0000 | [diff] [blame] | 2119 | StringRef Filename = FI.Filename; |
| Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2120 | |
| Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2121 | const FileEntry *File = FileMgr.getFile(Filename, /*OpenFile=*/false); |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2122 | // If we didn't find the file, resolve it relative to the |
| 2123 | // original directory from which this AST file was created. |
| Manuel Klimek | 1b29b4f | 2017-07-25 10:22:06 +0000 | [diff] [blame] | 2124 | if (File == nullptr && !F.OriginalDir.empty() && !F.BaseDirectory.empty() && |
| 2125 | F.OriginalDir != F.BaseDirectory) { |
| 2126 | std::string Resolved = resolveFileRelativeToOriginalDir( |
| 2127 | Filename, F.OriginalDir, F.BaseDirectory); |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2128 | if (!Resolved.empty()) |
| 2129 | File = FileMgr.getFile(Resolved); |
| 2130 | } |
| 2131 | |
| 2132 | // For an overridden file, create a virtual file with the stored |
| 2133 | // size/timestamp. |
| Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2134 | if ((Overridden || Transient) && File == nullptr) |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2135 | File = FileMgr.getVirtualFile(Filename, StoredSize, StoredTime); |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2136 | |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 2137 | if (File == nullptr) { |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2138 | if (Complain) { |
| 2139 | std::string ErrorStr = "could not find file '"; |
| 2140 | ErrorStr += Filename; |
| Richard Smith | 6814221 | 2015-10-13 01:26:26 +0000 | [diff] [blame] | 2141 | ErrorStr += "' referenced by AST file '"; |
| 2142 | ErrorStr += F.FileName; |
| 2143 | ErrorStr += "'"; |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2144 | Error(ErrorStr); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2145 | } |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2146 | // Record that we didn't find the file. |
| 2147 | F.InputFilesLoaded[ID-1] = InputFile::getNotFound(); |
| 2148 | return InputFile(); |
| 2149 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2150 | |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2151 | // Check if there was a request to override the contents of the file |
| Alexander Kornienko | 2a8c18d | 2018-04-06 15:14:32 +0000 | [diff] [blame] | 2152 | // that was part of the precompiled header. Overriding such a file |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2153 | // can lead to problems when lexing using the source locations from the |
| 2154 | // PCH. |
| 2155 | SourceManager &SM = getSourceManager(); |
| Richard Smith | 64daf7b | 2015-12-01 03:32:49 +0000 | [diff] [blame] | 2156 | // FIXME: Reject if the overrides are different. |
| 2157 | if ((!Overridden && !Transient) && SM.isFileOverridden(File)) { |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2158 | if (Complain) |
| 2159 | Error(diag::err_fe_pch_file_overridden, Filename); |
| 2160 | // After emitting the diagnostic, recover by disabling the override so |
| 2161 | // that the original file will be used. |
| Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2162 | // |
| 2163 | // FIXME: This recovery is just as broken as the original state; there may |
| 2164 | // be another precompiled module that's using the overridden contents, or |
| 2165 | // we might be half way through parsing it. Instead, we should treat the |
| 2166 | // overridden contents as belonging to a separate FileEntry. |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2167 | SM.disableFileContentsOverride(File); |
| 2168 | // The FileEntry is a virtual file entry with the size of the contents |
| 2169 | // that would override the original contents. Set it to the original's |
| 2170 | // size/time. |
| 2171 | FileMgr.modifyFileEntry(const_cast<FileEntry*>(File), |
| 2172 | StoredSize, StoredTime); |
| 2173 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2174 | |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2175 | bool IsOutOfDate = false; |
| 2176 | |
| 2177 | // For an overridden file, there is nothing to validate. |
| Richard Smith | 96fdab6 | 2014-10-28 16:24:08 +0000 | [diff] [blame] | 2178 | if (!Overridden && // |
| 2179 | (StoredSize != File->getSize() || |
| Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 2180 | (StoredTime && StoredTime != File->getModificationTime() && |
| 2181 | !DisableValidation) |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2182 | )) { |
| 2183 | if (Complain) { |
| 2184 | // Build a list of the PCH imports that got us here (in reverse). |
| 2185 | SmallVector<ModuleFile *, 4> ImportStack(1, &F); |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 2186 | while (!ImportStack.back()->ImportedBy.empty()) |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2187 | ImportStack.push_back(ImportStack.back()->ImportedBy[0]); |
| Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 2188 | |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2189 | // The top-level PCH is stale. |
| 2190 | StringRef TopLevelPCHName(ImportStack.back()->FileName); |
| Manman Ren | c8c9415 | 2016-10-21 23:35:03 +0000 | [diff] [blame] | 2191 | unsigned DiagnosticKind = moduleKindForDiagnostic(ImportStack.back()->Kind); |
| 2192 | if (DiagnosticKind == 0) |
| 2193 | Error(diag::err_fe_pch_file_modified, Filename, TopLevelPCHName); |
| 2194 | else if (DiagnosticKind == 1) |
| 2195 | Error(diag::err_fe_module_file_modified, Filename, TopLevelPCHName); |
| 2196 | else |
| 2197 | Error(diag::err_fe_ast_file_modified, Filename, TopLevelPCHName); |
| Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 2198 | |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2199 | // Print the import stack. |
| 2200 | if (ImportStack.size() > 1 && !Diags.isDiagnosticInFlight()) { |
| 2201 | Diag(diag::note_pch_required_by) |
| 2202 | << Filename << ImportStack[0]->FileName; |
| 2203 | for (unsigned I = 1; I < ImportStack.size(); ++I) |
| Ben Langmuir | e82630d | 2014-01-17 00:19:09 +0000 | [diff] [blame] | 2204 | Diag(diag::note_pch_required_by) |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2205 | << ImportStack[I-1]->FileName << ImportStack[I]->FileName; |
| Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 2206 | } |
| 2207 | |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2208 | if (!Diags.isDiagnosticInFlight()) |
| 2209 | Diag(diag::note_pch_rebuild_required) << TopLevelPCHName; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2210 | } |
| 2211 | |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2212 | IsOutOfDate = true; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2213 | } |
| Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2214 | // FIXME: If the file is overridden and we've already opened it, |
| 2215 | // issue an error (or split it into a separate FileEntry). |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2216 | |
| Richard Smith | a8cfffa | 2015-11-26 02:04:16 +0000 | [diff] [blame] | 2217 | InputFile IF = InputFile(File, Overridden || Transient, IsOutOfDate); |
| Ben Langmuir | 198c168 | 2014-03-07 07:27:49 +0000 | [diff] [blame] | 2218 | |
| 2219 | // Note that we've loaded this input file. |
| 2220 | F.InputFilesLoaded[ID-1] = IF; |
| 2221 | return IF; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2222 | } |
| 2223 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2224 | /// If we are loading a relocatable PCH or module file, and the filename |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2225 | /// is not an absolute path, add the system or module root to the beginning of |
| 2226 | /// the file name. |
| 2227 | void ASTReader::ResolveImportedPath(ModuleFile &M, std::string &Filename) { |
| 2228 | // Resolve relative to the base directory, if we have one. |
| 2229 | if (!M.BaseDirectory.empty()) |
| 2230 | return ResolveImportedPath(Filename, M.BaseDirectory); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2231 | } |
| 2232 | |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2233 | void ASTReader::ResolveImportedPath(std::string &Filename, StringRef Prefix) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2234 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
| 2235 | return; |
| 2236 | |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2237 | SmallString<128> Buffer; |
| 2238 | llvm::sys::path::append(Buffer, Prefix, Filename); |
| 2239 | Filename.assign(Buffer.begin(), Buffer.end()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2240 | } |
| 2241 | |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2242 | static bool isDiagnosedResult(ASTReader::ASTReadResult ARR, unsigned Caps) { |
| 2243 | switch (ARR) { |
| 2244 | case ASTReader::Failure: return true; |
| 2245 | case ASTReader::Missing: return !(Caps & ASTReader::ARR_Missing); |
| 2246 | case ASTReader::OutOfDate: return !(Caps & ASTReader::ARR_OutOfDate); |
| 2247 | case ASTReader::VersionMismatch: return !(Caps & ASTReader::ARR_VersionMismatch); |
| 2248 | case ASTReader::ConfigurationMismatch: |
| 2249 | return !(Caps & ASTReader::ARR_ConfigurationMismatch); |
| 2250 | case ASTReader::HadErrors: return true; |
| 2251 | case ASTReader::Success: return false; |
| 2252 | } |
| 2253 | |
| 2254 | llvm_unreachable("unknown ASTReadResult"); |
| 2255 | } |
| 2256 | |
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2257 | ASTReader::ASTReadResult ASTReader::ReadOptionsBlock( |
| 2258 | BitstreamCursor &Stream, unsigned ClientLoadCapabilities, |
| 2259 | bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener, |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2260 | std::string &SuggestedPredefines) { |
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2261 | if (Stream.EnterSubBlock(OPTIONS_BLOCK_ID)) |
| 2262 | return Failure; |
| 2263 | |
| 2264 | // Read all of the records in the options block. |
| 2265 | RecordData Record; |
| 2266 | ASTReadResult Result = Success; |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2267 | while (true) { |
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2268 | llvm::BitstreamEntry Entry = Stream.advance(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2269 | |
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2270 | switch (Entry.Kind) { |
| 2271 | case llvm::BitstreamEntry::Error: |
| 2272 | case llvm::BitstreamEntry::SubBlock: |
| 2273 | return Failure; |
| 2274 | |
| 2275 | case llvm::BitstreamEntry::EndBlock: |
| 2276 | return Result; |
| 2277 | |
| 2278 | case llvm::BitstreamEntry::Record: |
| 2279 | // The interesting case. |
| 2280 | break; |
| 2281 | } |
| 2282 | |
| 2283 | // Read and process a record. |
| 2284 | Record.clear(); |
| 2285 | switch ((OptionsRecordTypes)Stream.readRecord(Entry.ID, Record)) { |
| 2286 | case LANGUAGE_OPTIONS: { |
| 2287 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2288 | if (ParseLanguageOptions(Record, Complain, Listener, |
| 2289 | AllowCompatibleConfigurationMismatch)) |
| 2290 | Result = ConfigurationMismatch; |
| 2291 | break; |
| 2292 | } |
| 2293 | |
| 2294 | case TARGET_OPTIONS: { |
| 2295 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2296 | if (ParseTargetOptions(Record, Complain, Listener, |
| 2297 | AllowCompatibleConfigurationMismatch)) |
| 2298 | Result = ConfigurationMismatch; |
| 2299 | break; |
| 2300 | } |
| 2301 | |
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2302 | case FILE_SYSTEM_OPTIONS: { |
| 2303 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2304 | if (!AllowCompatibleConfigurationMismatch && |
| 2305 | ParseFileSystemOptions(Record, Complain, Listener)) |
| 2306 | Result = ConfigurationMismatch; |
| 2307 | break; |
| 2308 | } |
| 2309 | |
| 2310 | case HEADER_SEARCH_OPTIONS: { |
| 2311 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2312 | if (!AllowCompatibleConfigurationMismatch && |
| 2313 | ParseHeaderSearchOptions(Record, Complain, Listener)) |
| 2314 | Result = ConfigurationMismatch; |
| 2315 | break; |
| 2316 | } |
| 2317 | |
| 2318 | case PREPROCESSOR_OPTIONS: |
| 2319 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2320 | if (!AllowCompatibleConfigurationMismatch && |
| 2321 | ParsePreprocessorOptions(Record, Complain, Listener, |
| 2322 | SuggestedPredefines)) |
| 2323 | Result = ConfigurationMismatch; |
| 2324 | break; |
| 2325 | } |
| 2326 | } |
| 2327 | } |
| 2328 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2329 | ASTReader::ASTReadResult |
| 2330 | ASTReader::ReadControlBlock(ModuleFile &F, |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 2331 | SmallVectorImpl<ImportedModule> &Loaded, |
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2332 | const ModuleFile *ImportedBy, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2333 | unsigned ClientLoadCapabilities) { |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2334 | BitstreamCursor &Stream = F.Stream; |
| Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2335 | ASTReadResult Result = Success; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2336 | |
| 2337 | if (Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
| 2338 | Error("malformed block record in AST file"); |
| 2339 | return Failure; |
| 2340 | } |
| 2341 | |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2342 | // Lambda to read the unhashed control block the first time it's called. |
| 2343 | // |
| 2344 | // For PCM files, the unhashed control block cannot be read until after the |
| 2345 | // MODULE_NAME record. However, PCH files have no MODULE_NAME, and yet still |
| 2346 | // need to look ahead before reading the IMPORTS record. For consistency, |
| 2347 | // this block is always read somehow (see BitstreamEntry::EndBlock). |
| 2348 | bool HasReadUnhashedControlBlock = false; |
| 2349 | auto readUnhashedControlBlockOnce = [&]() { |
| 2350 | if (!HasReadUnhashedControlBlock) { |
| 2351 | HasReadUnhashedControlBlock = true; |
| 2352 | if (ASTReadResult Result = |
| 2353 | readUnhashedControlBlock(F, ImportedBy, ClientLoadCapabilities)) |
| 2354 | return Result; |
| 2355 | } |
| 2356 | return Success; |
| 2357 | }; |
| 2358 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2359 | // Read all of the records and blocks in the control block. |
| 2360 | RecordData Record; |
| Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2361 | unsigned NumInputs = 0; |
| 2362 | unsigned NumUserInputs = 0; |
| Duncan P. N. Exon Smith | 0a2be46 | 2019-03-09 17:44:01 +0000 | [diff] [blame] | 2363 | StringRef BaseDirectoryAsWritten; |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2364 | while (true) { |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2365 | llvm::BitstreamEntry Entry = Stream.advance(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2366 | |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2367 | switch (Entry.Kind) { |
| 2368 | case llvm::BitstreamEntry::Error: |
| 2369 | Error("malformed block record in AST file"); |
| 2370 | return Failure; |
| Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2371 | case llvm::BitstreamEntry::EndBlock: { |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2372 | // Validate the module before returning. This call catches an AST with |
| 2373 | // no module name and no imports. |
| 2374 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2375 | return Result; |
| 2376 | |
| Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2377 | // Validate input files. |
| 2378 | const HeaderSearchOptions &HSOpts = |
| 2379 | PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2380 | |
| Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2381 | // All user input files reside at the index range [0, NumUserInputs), and |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2382 | // system input files reside at [NumUserInputs, NumInputs). For explicitly |
| 2383 | // loaded module files, ignore missing inputs. |
| Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2384 | if (!DisableValidation && F.Kind != MK_ExplicitModule && |
| 2385 | F.Kind != MK_PrebuiltModule) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2386 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2387 | |
| Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2388 | // If we are reading a module, we will create a verification timestamp, |
| 2389 | // so we verify all input files. Otherwise, verify only user input |
| 2390 | // files. |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2391 | |
| 2392 | unsigned N = NumUserInputs; |
| 2393 | if (ValidateSystemInputs || |
| Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 2394 | (HSOpts.ModulesValidateOncePerBuildSession && |
| Ben Langmuir | acb803e | 2014-11-10 22:13:10 +0000 | [diff] [blame] | 2395 | F.InputFilesValidationTimestamp <= HSOpts.BuildSessionTimestamp && |
| Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 2396 | F.Kind == MK_ImplicitModule)) |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2397 | N = NumInputs; |
| 2398 | |
| Ben Langmuir | 3d4417c | 2014-02-07 17:31:11 +0000 | [diff] [blame] | 2399 | for (unsigned I = 0; I < N; ++I) { |
| Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2400 | InputFile IF = getInputFile(F, I+1, Complain); |
| 2401 | if (!IF.getFile() || IF.isOutOfDate()) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2402 | return OutOfDate; |
| Argyrios Kyrtzidis | 61c3d87 | 2013-03-01 03:26:04 +0000 | [diff] [blame] | 2403 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2404 | } |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2405 | |
| Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 2406 | if (Listener) |
| Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 2407 | Listener->visitModuleFile(F.FileName, F.Kind); |
| Argyrios Kyrtzidis | 6d0753d | 2014-03-14 03:07:38 +0000 | [diff] [blame] | 2408 | |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2409 | if (Listener && Listener->needsInputFileVisitation()) { |
| 2410 | unsigned N = Listener->needsSystemInputFileVisitation() ? NumInputs |
| 2411 | : NumUserInputs; |
| Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 2412 | for (unsigned I = 0; I < N; ++I) { |
| 2413 | bool IsSystem = I >= NumUserInputs; |
| 2414 | InputFileInfo FI = readInputFileInfo(F, I+1); |
| Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 2415 | Listener->visitInputFile(FI.Filename, IsSystem, FI.Overridden, |
| Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2416 | F.Kind == MK_ExplicitModule || |
| 2417 | F.Kind == MK_PrebuiltModule); |
| Argyrios Kyrtzidis | 68ccbe0 | 2014-03-14 02:26:31 +0000 | [diff] [blame] | 2418 | } |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 2419 | } |
| 2420 | |
| Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2421 | return Result; |
| Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 2422 | } |
| 2423 | |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2424 | case llvm::BitstreamEntry::SubBlock: |
| 2425 | switch (Entry.ID) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2426 | case INPUT_FILES_BLOCK_ID: |
| 2427 | F.InputFilesCursor = Stream; |
| 2428 | if (Stream.SkipBlock() || // Skip with the main cursor |
| 2429 | // Read the abbreviations |
| 2430 | ReadBlockAbbrevs(F.InputFilesCursor, INPUT_FILES_BLOCK_ID)) { |
| 2431 | Error("malformed block record in AST file"); |
| 2432 | return Failure; |
| 2433 | } |
| 2434 | continue; |
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2435 | |
| 2436 | case OPTIONS_BLOCK_ID: |
| 2437 | // If we're reading the first module for this group, check its options |
| 2438 | // are compatible with ours. For modules it imports, no further checking |
| 2439 | // is required, because we checked them when we built it. |
| 2440 | if (Listener && !ImportedBy) { |
| 2441 | // Should we allow the configuration of the module file to differ from |
| 2442 | // the configuration of the current translation unit in a compatible |
| 2443 | // way? |
| 2444 | // |
| 2445 | // FIXME: Allow this for files explicitly specified with -include-pch. |
| 2446 | bool AllowCompatibleConfigurationMismatch = |
| Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 2447 | F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule; |
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2448 | |
| Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2449 | Result = ReadOptionsBlock(Stream, ClientLoadCapabilities, |
| 2450 | AllowCompatibleConfigurationMismatch, |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2451 | *Listener, SuggestedPredefines); |
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2452 | if (Result == Failure) { |
| 2453 | Error("malformed block record in AST file"); |
| 2454 | return Result; |
| 2455 | } |
| 2456 | |
| Richard Smith | 8a308ec | 2015-11-05 00:54:55 +0000 | [diff] [blame] | 2457 | if (DisableValidation || |
| 2458 | (AllowConfigurationMismatch && Result == ConfigurationMismatch)) |
| 2459 | Result = Success; |
| 2460 | |
| Ben Langmuir | 9b1e442e | 2016-02-11 18:54:02 +0000 | [diff] [blame] | 2461 | // If we can't load the module, exit early since we likely |
| 2462 | // will rebuild the module anyway. The stream may be in the |
| 2463 | // middle of a block. |
| 2464 | if (Result != Success) |
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 2465 | return Result; |
| 2466 | } else if (Stream.SkipBlock()) { |
| 2467 | Error("malformed block record in AST file"); |
| 2468 | return Failure; |
| 2469 | } |
| 2470 | continue; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2471 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2472 | default: |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2473 | if (Stream.SkipBlock()) { |
| 2474 | Error("malformed block record in AST file"); |
| 2475 | return Failure; |
| 2476 | } |
| 2477 | continue; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2478 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2479 | |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2480 | case llvm::BitstreamEntry::Record: |
| 2481 | // The interesting case. |
| 2482 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2483 | } |
| 2484 | |
| 2485 | // Read and process a record. |
| 2486 | Record.clear(); |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2487 | StringRef Blob; |
| 2488 | switch ((ControlRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob)) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2489 | case METADATA: { |
| 2490 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 2491 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
| Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 2492 | Diag(Record[0] < VERSION_MAJOR? diag::err_pch_version_too_old |
| 2493 | : diag::err_pch_version_too_new); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2494 | return VersionMismatch; |
| 2495 | } |
| 2496 | |
| Hans Wennborg | 08c5a7b | 2018-06-25 13:23:49 +0000 | [diff] [blame] | 2497 | bool hasErrors = Record[7]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2498 | if (hasErrors && !DisableValidation && !AllowASTWithCompilerErrors) { |
| 2499 | Diag(diag::err_pch_with_compiler_errors); |
| 2500 | return HadErrors; |
| 2501 | } |
| Argyrios Kyrtzidis | 70ec1c7 | 2016-07-13 20:35:26 +0000 | [diff] [blame] | 2502 | if (hasErrors) { |
| 2503 | Diags.ErrorOccurred = true; |
| 2504 | Diags.UncompilableErrorOccurred = true; |
| 2505 | Diags.UnrecoverableErrorOccurred = true; |
| 2506 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2507 | |
| 2508 | F.RelocatablePCH = Record[4]; |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2509 | // Relative paths in a relocatable PCH are relative to our sysroot. |
| 2510 | if (F.RelocatablePCH) |
| 2511 | F.BaseDirectory = isysroot.empty() ? "/" : isysroot; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2512 | |
| Richard Smith | e75ee0f | 2015-08-17 07:13:32 +0000 | [diff] [blame] | 2513 | F.HasTimestamps = Record[5]; |
| 2514 | |
| Hans Wennborg | 08c5a7b | 2018-06-25 13:23:49 +0000 | [diff] [blame] | 2515 | F.PCHHasObjectFile = Record[6]; |
| 2516 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2517 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2518 | StringRef ASTBranch = Blob; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2519 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2520 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
| Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 2521 | Diag(diag::err_pch_different_branch) << ASTBranch << CurBranch; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2522 | return VersionMismatch; |
| 2523 | } |
| 2524 | break; |
| 2525 | } |
| 2526 | |
| 2527 | case IMPORTS: { |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2528 | // Validate the AST before processing any imports (otherwise, untangling |
| 2529 | // them can be error-prone and expensive). A module will have a name and |
| 2530 | // will already have been validated, but this catches the PCH case. |
| 2531 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2532 | return Result; |
| 2533 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2534 | // Load each of the imported PCH files. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2535 | unsigned Idx = 0, N = Record.size(); |
| 2536 | while (Idx < N) { |
| 2537 | // Read information about the AST file. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 2538 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2539 | // The import location will be the local one for now; we will adjust |
| 2540 | // all import locations of module imports after the global source |
| Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2541 | // location info are setup, in ReadAST. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2542 | SourceLocation ImportLoc = |
| Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 2543 | ReadUntranslatedSourceLocation(Record[Idx++]); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 2544 | off_t StoredSize = (off_t)Record[Idx++]; |
| 2545 | time_t StoredModTime = (time_t)Record[Idx++]; |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2546 | ASTFileSignature StoredSignature = { |
| 2547 | {{(uint32_t)Record[Idx++], (uint32_t)Record[Idx++], |
| 2548 | (uint32_t)Record[Idx++], (uint32_t)Record[Idx++], |
| 2549 | (uint32_t)Record[Idx++]}}}; |
| Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 2550 | |
| 2551 | std::string ImportedName = ReadString(Record, Idx); |
| 2552 | std::string ImportedFile; |
| 2553 | |
| 2554 | // For prebuilt and explicit modules first consult the file map for |
| 2555 | // an override. Note that here we don't search prebuilt module |
| 2556 | // directories, only the explicit name to file mappings. Also, we will |
| 2557 | // still verify the size/signature making sure it is essentially the |
| 2558 | // same file but perhaps in a different location. |
| 2559 | if (ImportedKind == MK_PrebuiltModule || ImportedKind == MK_ExplicitModule) |
| 2560 | ImportedFile = PP.getHeaderSearchInfo().getPrebuiltModuleFileName( |
| 2561 | ImportedName, /*FileMapOnly*/ true); |
| 2562 | |
| 2563 | if (ImportedFile.empty()) |
| Duncan P. N. Exon Smith | 0a2be46 | 2019-03-09 17:44:01 +0000 | [diff] [blame] | 2564 | // Use BaseDirectoryAsWritten to ensure we use the same path in the |
| 2565 | // ModuleCache as when writing. |
| 2566 | ImportedFile = ReadPath(BaseDirectoryAsWritten, Record, Idx); |
| Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 2567 | else |
| 2568 | SkipPath(Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2569 | |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2570 | // If our client can't cope with us being out of date, we can't cope with |
| 2571 | // our dependency being missing. |
| 2572 | unsigned Capabilities = ClientLoadCapabilities; |
| 2573 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 2574 | Capabilities &= ~ARR_Missing; |
| 2575 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2576 | // Load the AST file. |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 2577 | auto Result = ReadASTCore(ImportedFile, ImportedKind, ImportLoc, &F, |
| 2578 | Loaded, StoredSize, StoredModTime, |
| 2579 | StoredSignature, Capabilities); |
| 2580 | |
| 2581 | // If we diagnosed a problem, produce a backtrace. |
| 2582 | if (isDiagnosedResult(Result, Capabilities)) |
| 2583 | Diag(diag::note_module_file_imported_by) |
| 2584 | << F.FileName << !F.ModuleName.empty() << F.ModuleName; |
| 2585 | |
| 2586 | switch (Result) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2587 | case Failure: return Failure; |
| 2588 | // 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] | 2589 | case Missing: |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2590 | case OutOfDate: return OutOfDate; |
| 2591 | case VersionMismatch: return VersionMismatch; |
| 2592 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 2593 | case HadErrors: return HadErrors; |
| 2594 | case Success: break; |
| 2595 | } |
| 2596 | } |
| 2597 | break; |
| 2598 | } |
| 2599 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2600 | case ORIGINAL_FILE: |
| 2601 | F.OriginalSourceFileID = FileID::get(Record[0]); |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2602 | F.ActualOriginalSourceFileName = Blob; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2603 | F.OriginalSourceFileName = F.ActualOriginalSourceFileName; |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2604 | ResolveImportedPath(F, F.OriginalSourceFileName); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2605 | break; |
| 2606 | |
| 2607 | case ORIGINAL_FILE_ID: |
| 2608 | F.OriginalSourceFileID = FileID::get(Record[0]); |
| 2609 | break; |
| 2610 | |
| 2611 | case ORIGINAL_PCH_DIR: |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2612 | F.OriginalDir = Blob; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2613 | break; |
| 2614 | |
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2615 | case MODULE_NAME: |
| 2616 | F.ModuleName = Blob; |
| Duncan P. N. Exon Smith | 9dda8f5 | 2019-03-06 02:50:46 +0000 | [diff] [blame] | 2617 | Diag(diag::remark_module_import) |
| 2618 | << F.ModuleName << F.FileName << (ImportedBy ? true : false) |
| 2619 | << (ImportedBy ? StringRef(ImportedBy->ModuleName) : StringRef()); |
| Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 2620 | if (Listener) |
| 2621 | Listener->ReadModuleName(F.ModuleName); |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 2622 | |
| 2623 | // Validate the AST as soon as we have a name so we can exit early on |
| 2624 | // failure. |
| 2625 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2626 | return Result; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 2627 | |
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2628 | break; |
| 2629 | |
| Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2630 | case MODULE_DIRECTORY: { |
| Duncan P. N. Exon Smith | 0a2be46 | 2019-03-09 17:44:01 +0000 | [diff] [blame] | 2631 | // Save the BaseDirectory as written in the PCM for computing the module |
| 2632 | // filename for the ModuleCache. |
| 2633 | BaseDirectoryAsWritten = Blob; |
| Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2634 | assert(!F.ModuleName.empty() && |
| 2635 | "MODULE_DIRECTORY found before MODULE_NAME"); |
| 2636 | // If we've already loaded a module map file covering this module, we may |
| 2637 | // have a better path for it (relative to the current build). |
| Bruno Cardoso Lopes | 52431f3 | 2018-07-18 23:21:19 +0000 | [diff] [blame] | 2638 | Module *M = PP.getHeaderSearchInfo().lookupModule( |
| 2639 | F.ModuleName, /*AllowSearch*/ true, |
| 2640 | /*AllowExtraModuleMapSearch*/ true); |
| Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2641 | if (M && M->Directory) { |
| 2642 | // If we're implicitly loading a module, the base directory can't |
| 2643 | // change between the build and use. |
| Yuka Takahashi | d8baec2 | 2018-08-01 09:50:02 +0000 | [diff] [blame] | 2644 | // Don't emit module relocation error if we have -fno-validate-pch |
| 2645 | if (!PP.getPreprocessorOpts().DisablePCHValidation && |
| 2646 | F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) { |
| Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2647 | const DirectoryEntry *BuildDir = |
| 2648 | PP.getFileManager().getDirectory(Blob); |
| 2649 | if (!BuildDir || BuildDir != M->Directory) { |
| 2650 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 2651 | Diag(diag::err_imported_module_relocated) |
| 2652 | << F.ModuleName << Blob << M->Directory->getName(); |
| 2653 | return OutOfDate; |
| 2654 | } |
| 2655 | } |
| 2656 | F.BaseDirectory = M->Directory->getName(); |
| 2657 | } else { |
| 2658 | F.BaseDirectory = Blob; |
| 2659 | } |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2660 | break; |
| Richard Smith | 223d3f2 | 2014-12-06 03:21:08 +0000 | [diff] [blame] | 2661 | } |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 2662 | |
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 2663 | case MODULE_MAP_FILE: |
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 2664 | if (ASTReadResult Result = |
| 2665 | ReadModuleMapFileBlock(Record, F, ImportedBy, ClientLoadCapabilities)) |
| 2666 | return Result; |
| Ben Langmuir | 264ea15 | 2014-11-08 00:06:39 +0000 | [diff] [blame] | 2667 | break; |
| 2668 | |
| Justin Bogner | ca9c0cc | 2015-06-21 20:32:36 +0000 | [diff] [blame] | 2669 | case INPUT_FILE_OFFSETS: |
| Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2670 | NumInputs = Record[0]; |
| 2671 | NumUserInputs = Record[1]; |
| Justin Bogner | 4c18324 | 2015-06-21 20:32:40 +0000 | [diff] [blame] | 2672 | F.InputFileOffsets = |
| 2673 | (const llvm::support::unaligned_uint64_t *)Blob.data(); |
| Richard Smith | a182530 | 2014-10-23 22:18:29 +0000 | [diff] [blame] | 2674 | F.InputFilesLoaded.resize(NumInputs); |
| Argyrios Kyrtzidis | a38cb20 | 2017-01-30 06:05:58 +0000 | [diff] [blame] | 2675 | F.NumUserInputFiles = NumUserInputs; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2676 | break; |
| 2677 | } |
| 2678 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2679 | } |
| 2680 | |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2681 | ASTReader::ASTReadResult |
| 2682 | ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2683 | BitstreamCursor &Stream = F.Stream; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2684 | |
| 2685 | if (Stream.EnterSubBlock(AST_BLOCK_ID)) { |
| 2686 | Error("malformed block record in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2687 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | // Read all of the records and blocks for the AST file. |
| 2691 | RecordData Record; |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 2692 | while (true) { |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2693 | llvm::BitstreamEntry Entry = Stream.advance(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2694 | |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2695 | switch (Entry.Kind) { |
| 2696 | case llvm::BitstreamEntry::Error: |
| 2697 | Error("error at end of module block in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2698 | return Failure; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 2699 | case llvm::BitstreamEntry::EndBlock: |
| Richard Smith | c0fbba7 | 2013-04-03 22:49:41 +0000 | [diff] [blame] | 2700 | // Outside of C++, we do not store a lookup map for the translation unit. |
| 2701 | // Instead, mark it as needing a lookup map to be built if this module |
| 2702 | // contains any declarations lexically within it (which it always does!). |
| 2703 | // This usually has no cost, since we very rarely need the lookup map for |
| 2704 | // the translation unit outside C++. |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2705 | if (ASTContext *Ctx = ContextObj) { |
| 2706 | DeclContext *DC = Ctx->getTranslationUnitDecl(); |
| 2707 | if (DC->hasExternalLexicalStorage() && !Ctx->getLangOpts().CPlusPlus) |
| 2708 | DC->setMustBuildLookupTable(); |
| 2709 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2710 | |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2711 | return Success; |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2712 | case llvm::BitstreamEntry::SubBlock: |
| 2713 | switch (Entry.ID) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2714 | case DECLTYPES_BLOCK_ID: |
| 2715 | // We lazily load the decls block, but we want to set up the |
| 2716 | // DeclsCursor cursor to point into it. Clone our current bitcode |
| 2717 | // cursor to it, enter the block and read the abbrevs in that block. |
| 2718 | // With the main cursor, we just skip over it. |
| 2719 | F.DeclsCursor = Stream; |
| 2720 | if (Stream.SkipBlock() || // Skip with the main cursor. |
| 2721 | // Read the abbrevs. |
| 2722 | ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID)) { |
| 2723 | Error("malformed block record in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2724 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2725 | } |
| 2726 | break; |
| Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 2727 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2728 | case PREPROCESSOR_BLOCK_ID: |
| 2729 | F.MacroCursor = Stream; |
| 2730 | if (!PP.getExternalSource()) |
| 2731 | PP.setExternalSource(this); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2732 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2733 | if (Stream.SkipBlock() || |
| 2734 | ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
| 2735 | Error("malformed block record in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2736 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2737 | } |
| 2738 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
| 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 PREPROCESSOR_DETAIL_BLOCK_ID: |
| 2742 | F.PreprocessorDetailCursor = Stream; |
| 2743 | if (Stream.SkipBlock() || |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2744 | ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2745 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2746 | Error("malformed preprocessor detail record in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2747 | return Failure; |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2748 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2749 | F.PreprocessorDetailStartOffset |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2750 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 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 | if (!PP.getPreprocessingRecord()) |
| 2753 | PP.createPreprocessingRecord(); |
| 2754 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 2755 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 2756 | break; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2757 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2758 | case SOURCE_MANAGER_BLOCK_ID: |
| 2759 | if (ReadSourceManagerBlock(F)) |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2760 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2761 | break; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2762 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2763 | case SUBMODULE_BLOCK_ID: |
| David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2764 | if (ASTReadResult Result = |
| 2765 | ReadSubmoduleBlock(F, ClientLoadCapabilities)) |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2766 | return Result; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2767 | break; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2768 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2769 | case COMMENTS_BLOCK_ID: { |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 2770 | BitstreamCursor C = Stream; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2771 | if (Stream.SkipBlock() || |
| 2772 | ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) { |
| 2773 | Error("malformed comments block in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2774 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2775 | } |
| 2776 | CommentsCursors.push_back(std::make_pair(C, &F)); |
| 2777 | break; |
| 2778 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2779 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2780 | default: |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2781 | if (Stream.SkipBlock()) { |
| 2782 | Error("malformed block record in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2783 | return Failure; |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2784 | } |
| 2785 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2786 | } |
| 2787 | continue; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2788 | |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 2789 | case llvm::BitstreamEntry::Record: |
| 2790 | // The interesting case. |
| 2791 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2792 | } |
| 2793 | |
| 2794 | // Read and process a record. |
| 2795 | Record.clear(); |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2796 | StringRef Blob; |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2797 | auto RecordType = |
| 2798 | (ASTRecordTypes)Stream.readRecord(Entry.ID, Record, &Blob); |
| 2799 | |
| 2800 | // If we're not loading an AST context, we don't care about most records. |
| 2801 | if (!ContextObj) { |
| 2802 | switch (RecordType) { |
| 2803 | case IDENTIFIER_TABLE: |
| 2804 | case IDENTIFIER_OFFSET: |
| 2805 | case INTERESTING_IDENTIFIERS: |
| 2806 | case STATISTICS: |
| 2807 | case PP_CONDITIONAL_STACK: |
| 2808 | case PP_COUNTER_VALUE: |
| 2809 | case SOURCE_LOCATION_OFFSETS: |
| 2810 | case MODULE_OFFSET_MAP: |
| 2811 | case SOURCE_MANAGER_LINE_TABLE: |
| 2812 | case SOURCE_LOCATION_PRELOADS: |
| 2813 | case PPD_ENTITIES_OFFSETS: |
| 2814 | case HEADER_SEARCH_TABLE: |
| 2815 | case IMPORTED_MODULES: |
| 2816 | case MACRO_OFFSET: |
| 2817 | break; |
| 2818 | default: |
| 2819 | continue; |
| 2820 | } |
| 2821 | } |
| 2822 | |
| 2823 | switch (RecordType) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2824 | default: // Default behavior: ignore. |
| 2825 | break; |
| 2826 | |
| 2827 | case TYPE_OFFSET: { |
| 2828 | if (F.LocalNumTypes != 0) { |
| 2829 | Error("duplicate TYPE_OFFSET record in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2830 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2831 | } |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2832 | F.TypeOffsets = (const uint32_t *)Blob.data(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2833 | F.LocalNumTypes = Record[0]; |
| 2834 | unsigned LocalBaseTypeIndex = Record[1]; |
| 2835 | F.BaseTypeIndex = getTotalNumTypes(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2836 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2837 | if (F.LocalNumTypes > 0) { |
| 2838 | // Introduce the global -> local mapping for types within this module. |
| 2839 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2840 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2841 | // Introduce the local -> global mapping for types within this module. |
| 2842 | F.TypeRemap.insertOrReplace( |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2843 | std::make_pair(LocalBaseTypeIndex, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2844 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
| Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2845 | |
| 2846 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2847 | } |
| 2848 | break; |
| 2849 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2850 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2851 | case DECL_OFFSET: { |
| 2852 | if (F.LocalNumDecls != 0) { |
| 2853 | Error("duplicate DECL_OFFSET record in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2854 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2855 | } |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2856 | F.DeclOffsets = (const DeclOffset *)Blob.data(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2857 | F.LocalNumDecls = Record[0]; |
| 2858 | unsigned LocalBaseDeclID = Record[1]; |
| 2859 | F.BaseDeclID = getTotalNumDecls(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2860 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2861 | if (F.LocalNumDecls > 0) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2862 | // Introduce the global -> local mapping for declarations within this |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2863 | // module. |
| 2864 | GlobalDeclMap.insert( |
| 2865 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2866 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2867 | // Introduce the local -> global mapping for declarations within this |
| 2868 | // module. |
| 2869 | F.DeclRemap.insertOrReplace( |
| 2870 | std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID)); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2871 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2872 | // Introduce the global -> local mapping for declarations within this |
| 2873 | // module. |
| 2874 | F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID; |
| Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 2875 | |
| Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2876 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 2877 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2878 | break; |
| 2879 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2880 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2881 | case TU_UPDATE_LEXICAL: { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2882 | DeclContext *TU = ContextObj->getTranslationUnitDecl(); |
| Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 2883 | LexicalContents Contents( |
| 2884 | reinterpret_cast<const llvm::support::unaligned_uint32_t *>( |
| 2885 | Blob.data()), |
| 2886 | static_cast<unsigned int>(Blob.size() / 4)); |
| 2887 | TULexicalDecls.push_back(std::make_pair(&F, Contents)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2888 | TU->setHasExternalLexicalStorage(true); |
| 2889 | break; |
| 2890 | } |
| 2891 | |
| 2892 | case UPDATE_VISIBLE: { |
| 2893 | unsigned Idx = 0; |
| 2894 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
| Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 2895 | auto *Data = (const unsigned char*)Blob.data(); |
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 2896 | PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&F, Data}); |
| Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 2897 | // If we've already loaded the decl, perform the updates when we finish |
| 2898 | // loading this block. |
| 2899 | if (Decl *D = GetExistingDecl(ID)) |
| Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 2900 | PendingUpdateRecords.push_back( |
| 2901 | PendingUpdateRecord(ID, D, /*JustLoaded=*/false)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2902 | break; |
| 2903 | } |
| 2904 | |
| 2905 | case IDENTIFIER_TABLE: |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2906 | F.IdentifierTableData = Blob.data(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2907 | if (Record[0]) { |
| Justin Bogner | da4e650 | 2014-04-14 16:34:29 +0000 | [diff] [blame] | 2908 | F.IdentifierLookupTable = ASTIdentifierLookupTable::Create( |
| 2909 | (const unsigned char *)F.IdentifierTableData + Record[0], |
| 2910 | (const unsigned char *)F.IdentifierTableData + sizeof(uint32_t), |
| 2911 | (const unsigned char *)F.IdentifierTableData, |
| 2912 | ASTIdentifierLookupTrait(*this, F)); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2913 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2914 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
| 2915 | } |
| 2916 | break; |
| 2917 | |
| 2918 | case IDENTIFIER_OFFSET: { |
| 2919 | if (F.LocalNumIdentifiers != 0) { |
| 2920 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2921 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2922 | } |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 2923 | F.IdentifierOffsets = (const uint32_t *)Blob.data(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2924 | F.LocalNumIdentifiers = Record[0]; |
| 2925 | unsigned LocalBaseIdentifierID = Record[1]; |
| 2926 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2927 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2928 | if (F.LocalNumIdentifiers > 0) { |
| 2929 | // Introduce the global -> local mapping for identifiers within this |
| 2930 | // module. |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2931 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2932 | &F)); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2933 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2934 | // Introduce the local -> global mapping for identifiers within this |
| 2935 | // module. |
| 2936 | F.IdentifierRemap.insertOrReplace( |
| 2937 | std::make_pair(LocalBaseIdentifierID, |
| 2938 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
| Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 2939 | |
| Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 2940 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 2941 | + F.LocalNumIdentifiers); |
| 2942 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2943 | break; |
| 2944 | } |
| 2945 | |
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 2946 | case INTERESTING_IDENTIFIERS: |
| 2947 | F.PreloadIdentifierOffsets.assign(Record.begin(), Record.end()); |
| 2948 | break; |
| 2949 | |
| Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2950 | case EAGERLY_DESERIALIZED_DECLS: |
| Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 2951 | // FIXME: Skip reading this record if our ASTConsumer doesn't care |
| 2952 | // about "interesting" decls (for instance, if we're building a module). |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2953 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2954 | EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I])); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2955 | break; |
| 2956 | |
| David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 2957 | case MODULAR_CODEGEN_DECLS: |
| 2958 | // FIXME: Skip reading this record if our ASTConsumer doesn't care about |
| 2959 | // them (ie: if we're not codegenerating this module). |
| 2960 | if (F.Kind == MK_MainFile) |
| 2961 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2962 | EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2963 | break; |
| 2964 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2965 | case SPECIAL_TYPES: |
| Douglas Gregor | 44180f8 | 2013-02-01 23:45:03 +0000 | [diff] [blame] | 2966 | if (SpecialTypes.empty()) { |
| 2967 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2968 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
| 2969 | break; |
| 2970 | } |
| 2971 | |
| 2972 | if (SpecialTypes.size() != Record.size()) { |
| 2973 | Error("invalid special-types record"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 2974 | return Failure; |
| Douglas Gregor | 44180f8 | 2013-02-01 23:45:03 +0000 | [diff] [blame] | 2975 | } |
| 2976 | |
| 2977 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 2978 | serialization::TypeID ID = getGlobalTypeID(F, Record[I]); |
| 2979 | if (!SpecialTypes[I]) |
| 2980 | SpecialTypes[I] = ID; |
| 2981 | // FIXME: If ID && SpecialTypes[I] != ID, do we need a separate |
| 2982 | // merge step? |
| 2983 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 2984 | break; |
| 2985 | |
| 2986 | case STATISTICS: |
| 2987 | TotalNumStatements += Record[0]; |
| 2988 | TotalNumMacros += Record[1]; |
| 2989 | TotalLexicalDeclContexts += Record[2]; |
| 2990 | TotalVisibleDeclContexts += Record[3]; |
| 2991 | break; |
| 2992 | |
| 2993 | case UNUSED_FILESCOPED_DECLS: |
| 2994 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 2995 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 2996 | break; |
| 2997 | |
| 2998 | case DELEGATING_CTORS: |
| 2999 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3000 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 3001 | break; |
| 3002 | |
| 3003 | case WEAK_UNDECLARED_IDENTIFIERS: |
| 3004 | if (Record.size() % 4 != 0) { |
| 3005 | Error("invalid weak identifiers record"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3006 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3007 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3008 | |
| 3009 | // FIXME: Ignore weak undeclared identifiers from non-original PCH |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3010 | // files. This isn't the way to do it :) |
| 3011 | WeakUndeclaredIdentifiers.clear(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3012 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3013 | // Translate the weak, undeclared identifiers into global IDs. |
| 3014 | for (unsigned I = 0, N = Record.size(); I < N; /* in loop */) { |
| 3015 | WeakUndeclaredIdentifiers.push_back( |
| 3016 | getGlobalIdentifierID(F, Record[I++])); |
| 3017 | WeakUndeclaredIdentifiers.push_back( |
| 3018 | getGlobalIdentifierID(F, Record[I++])); |
| 3019 | WeakUndeclaredIdentifiers.push_back( |
| 3020 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3021 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 3022 | } |
| 3023 | break; |
| 3024 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3025 | case SELECTOR_OFFSETS: { |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3026 | F.SelectorOffsets = (const uint32_t *)Blob.data(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3027 | F.LocalNumSelectors = Record[0]; |
| 3028 | unsigned LocalBaseSelectorID = Record[1]; |
| 3029 | F.BaseSelectorID = getTotalNumSelectors(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3030 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3031 | if (F.LocalNumSelectors > 0) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3032 | // Introduce the global -> local mapping for selectors within this |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3033 | // module. |
| 3034 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3035 | |
| 3036 | // Introduce the local -> global mapping for selectors within this |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3037 | // module. |
| 3038 | F.SelectorRemap.insertOrReplace( |
| 3039 | std::make_pair(LocalBaseSelectorID, |
| 3040 | F.BaseSelectorID - LocalBaseSelectorID)); |
| Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3041 | |
| 3042 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3043 | } |
| 3044 | break; |
| 3045 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3046 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3047 | case METHOD_POOL: |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3048 | F.SelectorLookupTableData = (const unsigned char *)Blob.data(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3049 | if (Record[0]) |
| 3050 | F.SelectorLookupTable |
| 3051 | = ASTSelectorLookupTable::Create( |
| 3052 | F.SelectorLookupTableData + Record[0], |
| 3053 | F.SelectorLookupTableData, |
| 3054 | ASTSelectorLookupTrait(*this, F)); |
| 3055 | TotalNumMethodPoolEntries += Record[1]; |
| 3056 | break; |
| 3057 | |
| 3058 | case REFERENCED_SELECTOR_POOL: |
| 3059 | if (!Record.empty()) { |
| 3060 | 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] | 3061 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3062 | Record[Idx++])); |
| 3063 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 3064 | getRawEncoding()); |
| 3065 | } |
| 3066 | } |
| 3067 | break; |
| 3068 | |
| Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 3069 | case PP_CONDITIONAL_STACK: |
| 3070 | if (!Record.empty()) { |
| Erik Verbruggen | 4d1eb2d | 2017-11-03 09:40:07 +0000 | [diff] [blame] | 3071 | unsigned Idx = 0, End = Record.size() - 1; |
| 3072 | bool ReachedEOFWhileSkipping = Record[Idx++]; |
| 3073 | llvm::Optional<Preprocessor::PreambleSkipInfo> SkipInfo; |
| 3074 | if (ReachedEOFWhileSkipping) { |
| 3075 | SourceLocation HashToken = ReadSourceLocation(F, Record, Idx); |
| 3076 | SourceLocation IfTokenLoc = ReadSourceLocation(F, Record, Idx); |
| 3077 | bool FoundNonSkipPortion = Record[Idx++]; |
| 3078 | bool FoundElse = Record[Idx++]; |
| 3079 | SourceLocation ElseLoc = ReadSourceLocation(F, Record, Idx); |
| 3080 | SkipInfo.emplace(HashToken, IfTokenLoc, FoundNonSkipPortion, |
| 3081 | FoundElse, ElseLoc); |
| 3082 | } |
| Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 3083 | SmallVector<PPConditionalInfo, 4> ConditionalStack; |
| Erik Verbruggen | 4d1eb2d | 2017-11-03 09:40:07 +0000 | [diff] [blame] | 3084 | while (Idx < End) { |
| Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 3085 | auto Loc = ReadSourceLocation(F, Record, Idx); |
| 3086 | bool WasSkipping = Record[Idx++]; |
| 3087 | bool FoundNonSkip = Record[Idx++]; |
| 3088 | bool FoundElse = Record[Idx++]; |
| 3089 | ConditionalStack.push_back( |
| 3090 | {Loc, WasSkipping, FoundNonSkip, FoundElse}); |
| 3091 | } |
| Erik Verbruggen | 4d1eb2d | 2017-11-03 09:40:07 +0000 | [diff] [blame] | 3092 | PP.setReplayablePreambleConditionalStack(ConditionalStack, SkipInfo); |
| Erik Verbruggen | b34c79f | 2017-05-30 11:54:55 +0000 | [diff] [blame] | 3093 | } |
| 3094 | break; |
| 3095 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3096 | case PP_COUNTER_VALUE: |
| 3097 | if (!Record.empty() && Listener) |
| 3098 | Listener->ReadCounter(F, Record[0]); |
| 3099 | break; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3100 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3101 | case FILE_SORTED_DECLS: |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3102 | F.FileSortedDecls = (const DeclID *)Blob.data(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3103 | F.NumFileSortedDecls = Record[0]; |
| 3104 | break; |
| 3105 | |
| 3106 | case SOURCE_LOCATION_OFFSETS: { |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3107 | F.SLocEntryOffsets = (const uint32_t *)Blob.data(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3108 | F.LocalNumSLocEntries = Record[0]; |
| 3109 | unsigned SLocSpaceSize = Record[1]; |
| Benjamin Kramer | 867ea1d | 2014-03-02 13:01:17 +0000 | [diff] [blame] | 3110 | std::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
| Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3111 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3112 | SLocSpaceSize); |
| Richard Smith | 78d81ec | 2015-08-12 22:25:24 +0000 | [diff] [blame] | 3113 | if (!F.SLocEntryBaseID) { |
| 3114 | Error("ran out of source locations"); |
| 3115 | break; |
| 3116 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3117 | // Make our entry in the range map. BaseID is negative and growing, so |
| 3118 | // we invert it. Because we invert it, though, we need the other end of |
| 3119 | // the range. |
| 3120 | unsigned RangeStart = |
| 3121 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 3122 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 3123 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 3124 | |
| 3125 | // SLocEntryBaseOffset is lower than MaxLoadedOffset and decreasing. |
| 3126 | assert((F.SLocEntryBaseOffset & (1U << 31U)) == 0); |
| 3127 | GlobalSLocOffsetMap.insert( |
| 3128 | std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset |
| 3129 | - SLocSpaceSize,&F)); |
| 3130 | |
| 3131 | // Initialize the remapping table. |
| 3132 | // Invalid stays invalid. |
| Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 3133 | F.SLocRemap.insertOrReplace(std::make_pair(0U, 0)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3134 | // This module. Base was 2 when being compiled. |
| Richard Smith | b9eab6d | 2014-03-20 19:44:17 +0000 | [diff] [blame] | 3135 | F.SLocRemap.insertOrReplace(std::make_pair(2U, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3136 | static_cast<int>(F.SLocEntryBaseOffset - 2))); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3137 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3138 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
| 3139 | break; |
| 3140 | } |
| 3141 | |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3142 | case MODULE_OFFSET_MAP: |
| 3143 | F.ModuleOffsetMap = Blob; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3144 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3145 | |
| 3146 | case SOURCE_MANAGER_LINE_TABLE: |
| 3147 | if (ParseLineTable(F, Record)) |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3148 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3149 | break; |
| 3150 | |
| 3151 | case SOURCE_LOCATION_PRELOADS: { |
| 3152 | // Need to transform from the local view (1-based IDs) to the global view, |
| 3153 | // which is based off F.SLocEntryBaseID. |
| 3154 | if (!F.PreloadSLocEntries.empty()) { |
| 3155 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3156 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3157 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3158 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3159 | F.PreloadSLocEntries.swap(Record); |
| 3160 | break; |
| 3161 | } |
| 3162 | |
| 3163 | case EXT_VECTOR_DECLS: |
| 3164 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3165 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 3166 | break; |
| 3167 | |
| 3168 | case VTABLE_USES: |
| 3169 | if (Record.size() % 3 != 0) { |
| 3170 | Error("Invalid VTABLE_USES record"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3171 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3172 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3173 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3174 | // Later tables overwrite earlier ones. |
| 3175 | // FIXME: Modules will have some trouble with this. This is clearly not |
| 3176 | // the right way to do this. |
| 3177 | VTableUses.clear(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3178 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3179 | for (unsigned Idx = 0, N = Record.size(); Idx != N; /* In loop */) { |
| 3180 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 3181 | VTableUses.push_back( |
| 3182 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 3183 | VTableUses.push_back(Record[Idx++]); |
| 3184 | } |
| 3185 | break; |
| 3186 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3187 | case PENDING_IMPLICIT_INSTANTIATIONS: |
| 3188 | if (PendingInstantiations.size() % 2 != 0) { |
| 3189 | Error("Invalid existing PendingInstantiations"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3190 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | if (Record.size() % 2 != 0) { |
| 3194 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3195 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| 3199 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 3200 | PendingInstantiations.push_back( |
| 3201 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3202 | } |
| 3203 | break; |
| 3204 | |
| 3205 | case SEMA_DECL_REFS: |
| Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 3206 | if (Record.size() != 3) { |
| Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 3207 | Error("Invalid SEMA_DECL_REFS block"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3208 | return Failure; |
| Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 3209 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3210 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3211 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
| 3212 | break; |
| 3213 | |
| 3214 | case PPD_ENTITIES_OFFSETS: { |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3215 | F.PreprocessedEntityOffsets = (const PPEntityOffset *)Blob.data(); |
| 3216 | assert(Blob.size() % sizeof(PPEntityOffset) == 0); |
| 3217 | F.NumPreprocessedEntities = Blob.size() / sizeof(PPEntityOffset); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3218 | |
| 3219 | unsigned LocalBasePreprocessedEntityID = Record[0]; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3220 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3221 | unsigned StartingID; |
| 3222 | if (!PP.getPreprocessingRecord()) |
| 3223 | PP.createPreprocessingRecord(); |
| 3224 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 3225 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3226 | StartingID |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3227 | = PP.getPreprocessingRecord() |
| Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3228 | ->allocateLoadedEntities(F.NumPreprocessedEntities); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3229 | F.BasePreprocessedEntityID = StartingID; |
| 3230 | |
| 3231 | if (F.NumPreprocessedEntities > 0) { |
| 3232 | // Introduce the global -> local mapping for preprocessed entities in |
| 3233 | // this module. |
| 3234 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3235 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3236 | // Introduce the local -> global mapping for preprocessed entities in |
| 3237 | // this module. |
| 3238 | F.PreprocessedEntityRemap.insertOrReplace( |
| 3239 | std::make_pair(LocalBasePreprocessedEntityID, |
| 3240 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 3241 | } |
| 3242 | |
| 3243 | break; |
| 3244 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3245 | |
| Cameron Desrochers | b60f1b6 | 2018-01-15 19:14:16 +0000 | [diff] [blame] | 3246 | case PPD_SKIPPED_RANGES: { |
| 3247 | F.PreprocessedSkippedRangeOffsets = (const PPSkippedRange*)Blob.data(); |
| 3248 | assert(Blob.size() % sizeof(PPSkippedRange) == 0); |
| 3249 | F.NumPreprocessedSkippedRanges = Blob.size() / sizeof(PPSkippedRange); |
| 3250 | |
| 3251 | if (!PP.getPreprocessingRecord()) |
| 3252 | PP.createPreprocessingRecord(); |
| 3253 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 3254 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 3255 | F.BasePreprocessedSkippedRangeID = PP.getPreprocessingRecord() |
| 3256 | ->allocateSkippedRanges(F.NumPreprocessedSkippedRanges); |
| Jonas Devlieghere | 560ce2c | 2018-02-26 15:16:42 +0000 | [diff] [blame] | 3257 | |
| Cameron Desrochers | b60f1b6 | 2018-01-15 19:14:16 +0000 | [diff] [blame] | 3258 | if (F.NumPreprocessedSkippedRanges > 0) |
| 3259 | GlobalSkippedRangeMap.insert( |
| 3260 | std::make_pair(F.BasePreprocessedSkippedRangeID, &F)); |
| 3261 | break; |
| 3262 | } |
| 3263 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 3264 | case DECL_UPDATE_OFFSETS: |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3265 | if (Record.size() % 2 != 0) { |
| 3266 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3267 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3268 | } |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3269 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) { |
| 3270 | GlobalDeclID ID = getGlobalDeclID(F, Record[I]); |
| 3271 | DeclUpdateOffsets[ID].push_back(std::make_pair(&F, Record[I + 1])); |
| 3272 | |
| 3273 | // If we've already loaded the decl, perform the updates when we finish |
| 3274 | // loading this block. |
| 3275 | if (Decl *D = GetExistingDecl(ID)) |
| Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3276 | PendingUpdateRecords.push_back( |
| 3277 | PendingUpdateRecord(ID, D, /*JustLoaded=*/false)); |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3278 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3279 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3280 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 3281 | case OBJC_CATEGORIES_MAP: |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3282 | if (F.LocalNumObjCCategoriesInMap != 0) { |
| 3283 | Error("duplicate OBJC_CATEGORIES_MAP record in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3284 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3285 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3286 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3287 | F.LocalNumObjCCategoriesInMap = Record[0]; |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3288 | F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)Blob.data(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3289 | break; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3290 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3291 | case OBJC_CATEGORIES: |
| 3292 | F.ObjCCategories.swap(Record); |
| 3293 | break; |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 3294 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3295 | case CUDA_SPECIAL_DECL_REFS: |
| 3296 | // Later tables overwrite earlier ones. |
| 3297 | // FIXME: Modules will have trouble with this. |
| 3298 | CUDASpecialDeclRefs.clear(); |
| 3299 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3300 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
| 3301 | break; |
| 3302 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 3303 | case HEADER_SEARCH_TABLE: |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3304 | F.HeaderFileInfoTableData = Blob.data(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3305 | F.LocalNumHeaderFileInfos = Record[1]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3306 | if (Record[0]) { |
| 3307 | F.HeaderFileInfoTable |
| 3308 | = HeaderFileInfoLookupTable::Create( |
| 3309 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 3310 | (const unsigned char *)F.HeaderFileInfoTableData, |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3311 | HeaderFileInfoTrait(*this, F, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3312 | &PP.getHeaderSearchInfo(), |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3313 | Blob.data() + Record[2])); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3314 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3315 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 3316 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 3317 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
| 3318 | } |
| 3319 | break; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3320 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3321 | case FP_PRAGMA_OPTIONS: |
| 3322 | // Later tables overwrite earlier ones. |
| 3323 | FPPragmaOptions.swap(Record); |
| 3324 | break; |
| 3325 | |
| 3326 | case OPENCL_EXTENSIONS: |
| Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3327 | for (unsigned I = 0, E = Record.size(); I != E; ) { |
| 3328 | auto Name = ReadString(Record, I); |
| 3329 | auto &Opt = OpenCLExtensions.OptMap[Name]; |
| Yaxun Liu | cc2741c | 2016-12-18 06:35:06 +0000 | [diff] [blame] | 3330 | Opt.Supported = Record[I++] != 0; |
| 3331 | Opt.Enabled = Record[I++] != 0; |
| Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 3332 | Opt.Avail = Record[I++]; |
| 3333 | Opt.Core = Record[I++]; |
| 3334 | } |
| 3335 | break; |
| 3336 | |
| 3337 | case OPENCL_EXTENSION_TYPES: |
| 3338 | for (unsigned I = 0, E = Record.size(); I != E;) { |
| 3339 | auto TypeID = static_cast<::TypeID>(Record[I++]); |
| 3340 | auto *Type = GetType(TypeID).getTypePtr(); |
| 3341 | auto NumExt = static_cast<unsigned>(Record[I++]); |
| 3342 | for (unsigned II = 0; II != NumExt; ++II) { |
| 3343 | auto Ext = ReadString(Record, I); |
| 3344 | OpenCLTypeExtMap[Type].insert(Ext); |
| 3345 | } |
| 3346 | } |
| 3347 | break; |
| 3348 | |
| 3349 | case OPENCL_EXTENSION_DECLS: |
| 3350 | for (unsigned I = 0, E = Record.size(); I != E;) { |
| 3351 | auto DeclID = static_cast<::DeclID>(Record[I++]); |
| 3352 | auto *Decl = GetDecl(DeclID); |
| 3353 | auto NumExt = static_cast<unsigned>(Record[I++]); |
| 3354 | for (unsigned II = 0; II != NumExt; ++II) { |
| 3355 | auto Ext = ReadString(Record, I); |
| 3356 | OpenCLDeclExtMap[Decl].insert(Ext); |
| 3357 | } |
| 3358 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3359 | break; |
| 3360 | |
| 3361 | case TENTATIVE_DEFINITIONS: |
| 3362 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3363 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
| 3364 | break; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3365 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3366 | case KNOWN_NAMESPACES: |
| 3367 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3368 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
| 3369 | break; |
| Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3370 | |
| Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3371 | case UNDEFINED_BUT_USED: |
| 3372 | if (UndefinedButUsed.size() % 2 != 0) { |
| 3373 | Error("Invalid existing UndefinedButUsed"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3374 | return Failure; |
| Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | if (Record.size() % 2 != 0) { |
| Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3378 | Error("invalid undefined-but-used record"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3379 | return Failure; |
| Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3380 | } |
| 3381 | for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) { |
| Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 3382 | UndefinedButUsed.push_back(getGlobalDeclID(F, Record[I++])); |
| 3383 | UndefinedButUsed.push_back( |
| Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3384 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3385 | } |
| 3386 | break; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 3387 | |
| Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 3388 | case DELETE_EXPRS_TO_ANALYZE: |
| 3389 | for (unsigned I = 0, N = Record.size(); I != N;) { |
| 3390 | DelayedDeleteExprs.push_back(getGlobalDeclID(F, Record[I++])); |
| 3391 | const uint64_t Count = Record[I++]; |
| 3392 | DelayedDeleteExprs.push_back(Count); |
| 3393 | for (uint64_t C = 0; C < Count; ++C) { |
| 3394 | DelayedDeleteExprs.push_back(ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3395 | bool IsArrayForm = Record[I++] == 1; |
| 3396 | DelayedDeleteExprs.push_back(IsArrayForm); |
| 3397 | } |
| 3398 | } |
| 3399 | break; |
| Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 3400 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 3401 | case IMPORTED_MODULES: |
| Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 3402 | if (!F.isModule()) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3403 | // If we aren't loading a module (which has its own exports), make |
| 3404 | // all of the imported modules visible. |
| 3405 | // FIXME: Deal with macros-only imports. |
| Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 3406 | for (unsigned I = 0, N = Record.size(); I != N; /**/) { |
| 3407 | unsigned GlobalID = getGlobalSubmoduleID(F, Record[I++]); |
| 3408 | SourceLocation Loc = ReadSourceLocation(F, Record, I); |
| Graydon Hoare | 9c98244 | 2017-01-18 20:36:59 +0000 | [diff] [blame] | 3409 | if (GlobalID) { |
| Aaron Ballman | 4f45b71 | 2014-03-21 15:22:56 +0000 | [diff] [blame] | 3410 | ImportedModules.push_back(ImportedSubmodule(GlobalID, Loc)); |
| Graydon Hoare | 9c98244 | 2017-01-18 20:36:59 +0000 | [diff] [blame] | 3411 | if (DeserializationListener) |
| 3412 | DeserializationListener->ModuleImportRead(GlobalID, Loc); |
| 3413 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3414 | } |
| 3415 | } |
| 3416 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3417 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3418 | case MACRO_OFFSET: { |
| 3419 | if (F.LocalNumMacros != 0) { |
| 3420 | Error("duplicate MACRO_OFFSET record in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3421 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3422 | } |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 3423 | F.MacroOffsets = (const uint32_t *)Blob.data(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3424 | F.LocalNumMacros = Record[0]; |
| 3425 | unsigned LocalBaseMacroID = Record[1]; |
| 3426 | F.BaseMacroID = getTotalNumMacros(); |
| 3427 | |
| 3428 | if (F.LocalNumMacros > 0) { |
| 3429 | // Introduce the global -> local mapping for macros within this module. |
| 3430 | GlobalMacroMap.insert(std::make_pair(getTotalNumMacros() + 1, &F)); |
| 3431 | |
| 3432 | // Introduce the local -> global mapping for macros within this module. |
| 3433 | F.MacroRemap.insertOrReplace( |
| 3434 | std::make_pair(LocalBaseMacroID, |
| 3435 | F.BaseMacroID - LocalBaseMacroID)); |
| Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 3436 | |
| 3437 | MacrosLoaded.resize(MacrosLoaded.size() + F.LocalNumMacros); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3438 | } |
| 3439 | break; |
| 3440 | } |
| 3441 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 3442 | case LATE_PARSED_TEMPLATE: |
| Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 3443 | LateParsedTemplates.append(Record.begin(), Record.end()); |
| 3444 | break; |
| Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 3445 | |
| 3446 | case OPTIMIZE_PRAGMA_OPTIONS: |
| 3447 | if (Record.size() != 1) { |
| 3448 | Error("invalid pragma optimize record"); |
| 3449 | return Failure; |
| 3450 | } |
| 3451 | OptimizeOffPragmaLocation = ReadSourceLocation(F, Record[0]); |
| 3452 | break; |
| Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 3453 | |
| Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 3454 | case MSSTRUCT_PRAGMA_OPTIONS: |
| 3455 | if (Record.size() != 1) { |
| 3456 | Error("invalid pragma ms_struct record"); |
| 3457 | return Failure; |
| 3458 | } |
| 3459 | PragmaMSStructState = Record[0]; |
| 3460 | break; |
| 3461 | |
| Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 3462 | case POINTERS_TO_MEMBERS_PRAGMA_OPTIONS: |
| 3463 | if (Record.size() != 2) { |
| 3464 | Error("invalid pragma ms_struct record"); |
| 3465 | return Failure; |
| 3466 | } |
| 3467 | PragmaMSPointersToMembersState = Record[0]; |
| 3468 | PointersToMembersPragmaLocation = ReadSourceLocation(F, Record[1]); |
| 3469 | break; |
| 3470 | |
| Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 3471 | case UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES: |
| 3472 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3473 | UnusedLocalTypedefNameCandidates.push_back( |
| 3474 | getGlobalDeclID(F, Record[I])); |
| 3475 | break; |
| Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 3476 | |
| 3477 | case CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH: |
| 3478 | if (Record.size() != 1) { |
| 3479 | Error("invalid cuda pragma options record"); |
| 3480 | return Failure; |
| 3481 | } |
| 3482 | ForceCUDAHostDeviceDepth = Record[0]; |
| 3483 | break; |
| Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 3484 | |
| 3485 | case PACK_PRAGMA_OPTIONS: { |
| 3486 | if (Record.size() < 3) { |
| 3487 | Error("invalid pragma pack record"); |
| 3488 | return Failure; |
| 3489 | } |
| 3490 | PragmaPackCurrentValue = Record[0]; |
| 3491 | PragmaPackCurrentLocation = ReadSourceLocation(F, Record[1]); |
| 3492 | unsigned NumStackEntries = Record[2]; |
| 3493 | unsigned Idx = 3; |
| 3494 | // Reset the stack when importing a new module. |
| 3495 | PragmaPackStack.clear(); |
| 3496 | for (unsigned I = 0; I < NumStackEntries; ++I) { |
| 3497 | PragmaPackStackEntry Entry; |
| 3498 | Entry.Value = Record[Idx++]; |
| 3499 | Entry.Location = ReadSourceLocation(F, Record[Idx++]); |
| Alex Lorenz | 45b4014 | 2017-07-28 14:41:21 +0000 | [diff] [blame] | 3500 | Entry.PushLocation = ReadSourceLocation(F, Record[Idx++]); |
| Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 3501 | PragmaPackStrings.push_back(ReadString(Record, Idx)); |
| 3502 | Entry.SlotLabel = PragmaPackStrings.back(); |
| 3503 | PragmaPackStack.push_back(Entry); |
| 3504 | } |
| 3505 | break; |
| 3506 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3507 | } |
| 3508 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3509 | } |
| 3510 | |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3511 | void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const { |
| 3512 | assert(!F.ModuleOffsetMap.empty() && "no module offset map to read"); |
| 3513 | |
| 3514 | // Additional remapping information. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 3515 | const unsigned char *Data = (const unsigned char*)F.ModuleOffsetMap.data(); |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3516 | const unsigned char *DataEnd = Data + F.ModuleOffsetMap.size(); |
| 3517 | F.ModuleOffsetMap = StringRef(); |
| 3518 | |
| 3519 | // If we see this entry before SOURCE_LOCATION_OFFSETS, add placeholders. |
| 3520 | if (F.SLocRemap.find(0) == F.SLocRemap.end()) { |
| 3521 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 3522 | F.SLocRemap.insert(std::make_pair(2U, 1)); |
| 3523 | } |
| 3524 | |
| 3525 | // Continuous range maps we may be updating in our module. |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 3526 | using RemapBuilder = ContinuousRangeMap<uint32_t, int, 2>::Builder; |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3527 | RemapBuilder SLocRemap(F.SLocRemap); |
| 3528 | RemapBuilder IdentifierRemap(F.IdentifierRemap); |
| 3529 | RemapBuilder MacroRemap(F.MacroRemap); |
| 3530 | RemapBuilder PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 3531 | RemapBuilder SubmoduleRemap(F.SubmoduleRemap); |
| 3532 | RemapBuilder SelectorRemap(F.SelectorRemap); |
| 3533 | RemapBuilder DeclRemap(F.DeclRemap); |
| 3534 | RemapBuilder TypeRemap(F.TypeRemap); |
| 3535 | |
| 3536 | while (Data < DataEnd) { |
| Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 3537 | // FIXME: Looking up dependency modules by filename is horrible. Let's |
| 3538 | // start fixing this with prebuilt and explicit modules and see how it |
| 3539 | // goes... |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3540 | using namespace llvm::support; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 3541 | ModuleKind Kind = static_cast<ModuleKind>( |
| 3542 | endian::readNext<uint8_t, little, unaligned>(Data)); |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3543 | uint16_t Len = endian::readNext<uint16_t, little, unaligned>(Data); |
| 3544 | StringRef Name = StringRef((const char*)Data, Len); |
| 3545 | Data += Len; |
| Boris Kolpackov | d30446f | 2017-08-31 06:26:43 +0000 | [diff] [blame] | 3546 | ModuleFile *OM = (Kind == MK_PrebuiltModule || Kind == MK_ExplicitModule |
| 3547 | ? ModuleMgr.lookupByModuleName(Name) |
| 3548 | : ModuleMgr.lookupByFileName(Name)); |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 3549 | if (!OM) { |
| 3550 | std::string Msg = |
| 3551 | "SourceLocation remap refers to unknown module, cannot find "; |
| 3552 | Msg.append(Name); |
| 3553 | Error(Msg); |
| 3554 | return; |
| 3555 | } |
| 3556 | |
| 3557 | uint32_t SLocOffset = |
| 3558 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3559 | uint32_t IdentifierIDOffset = |
| 3560 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3561 | uint32_t MacroIDOffset = |
| 3562 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3563 | uint32_t PreprocessedEntityIDOffset = |
| 3564 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3565 | uint32_t SubmoduleIDOffset = |
| 3566 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3567 | uint32_t SelectorIDOffset = |
| 3568 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3569 | uint32_t DeclIDOffset = |
| 3570 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3571 | uint32_t TypeIndexOffset = |
| 3572 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3573 | |
| 3574 | uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 3575 | |
| 3576 | auto mapOffset = [&](uint32_t Offset, uint32_t BaseOffset, |
| 3577 | RemapBuilder &Remap) { |
| 3578 | if (Offset != None) |
| 3579 | Remap.insert(std::make_pair(Offset, |
| 3580 | static_cast<int>(BaseOffset - Offset))); |
| 3581 | }; |
| 3582 | mapOffset(SLocOffset, OM->SLocEntryBaseOffset, SLocRemap); |
| 3583 | mapOffset(IdentifierIDOffset, OM->BaseIdentifierID, IdentifierRemap); |
| 3584 | mapOffset(MacroIDOffset, OM->BaseMacroID, MacroRemap); |
| 3585 | mapOffset(PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID, |
| 3586 | PreprocessedEntityRemap); |
| 3587 | mapOffset(SubmoduleIDOffset, OM->BaseSubmoduleID, SubmoduleRemap); |
| 3588 | mapOffset(SelectorIDOffset, OM->BaseSelectorID, SelectorRemap); |
| 3589 | mapOffset(DeclIDOffset, OM->BaseDeclID, DeclRemap); |
| 3590 | mapOffset(TypeIndexOffset, OM->BaseTypeIndex, TypeRemap); |
| 3591 | |
| 3592 | // Global -> local mappings. |
| 3593 | F.GlobalToLocalDeclIDs[OM] = DeclIDOffset; |
| 3594 | } |
| 3595 | } |
| 3596 | |
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3597 | ASTReader::ASTReadResult |
| 3598 | ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, |
| 3599 | const ModuleFile *ImportedBy, |
| 3600 | unsigned ClientLoadCapabilities) { |
| 3601 | unsigned Idx = 0; |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3602 | F.ModuleMapPath = ReadPath(F, Record, Idx); |
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3603 | |
| 3604 | // Try to resolve ModuleName in the current header search context and |
| 3605 | // verify that it is found in the same module map file as we saved. If the |
| 3606 | // top-level AST file is a main file, skip this check because there is no |
| 3607 | // usable header search context. |
| 3608 | assert(!F.ModuleName.empty() && |
| Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3609 | "MODULE_NAME should come before MODULE_MAP_FILE"); |
| Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 3610 | if (F.Kind == MK_ImplicitModule && ModuleMgr.begin()->Kind != MK_MainFile) { |
| Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3611 | // An implicitly-loaded module file should have its module listed in some |
| 3612 | // module map file that we've already loaded. |
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3613 | Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName); |
| Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3614 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
| 3615 | const FileEntry *ModMap = M ? Map.getModuleMapFileForUniquing(M) : nullptr; |
| Yuka Takahashi | d8baec2 | 2018-08-01 09:50:02 +0000 | [diff] [blame] | 3616 | // Don't emit module relocation error if we have -fno-validate-pch |
| 3617 | if (!PP.getPreprocessorOpts().DisablePCHValidation && !ModMap) { |
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3618 | assert(ImportedBy && "top-level import should be verified"); |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3619 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) { |
| Bruno Cardoso Lopes | a66a325 | 2017-11-17 03:24:11 +0000 | [diff] [blame] | 3620 | if (auto *ASTFE = M ? M->getASTFile() : nullptr) { |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3621 | // This module was defined by an imported (explicit) module. |
| 3622 | Diag(diag::err_module_file_conflict) << F.ModuleName << F.FileName |
| 3623 | << ASTFE->getName(); |
| Bruno Cardoso Lopes | a66a325 | 2017-11-17 03:24:11 +0000 | [diff] [blame] | 3624 | } else { |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3625 | // This module was built with a different module map. |
| 3626 | Diag(diag::err_imported_module_not_found) |
| 3627 | << F.ModuleName << F.FileName << ImportedBy->FileName |
| 3628 | << F.ModuleMapPath; |
| Bruno Cardoso Lopes | a66a325 | 2017-11-17 03:24:11 +0000 | [diff] [blame] | 3629 | // In case it was imported by a PCH, there's a chance the user is |
| 3630 | // just missing to include the search path to the directory containing |
| 3631 | // the modulemap. |
| 3632 | if (ImportedBy->Kind == MK_PCH) |
| 3633 | Diag(diag::note_imported_by_pch_module_not_found) |
| 3634 | << llvm::sys::path::parent_path(F.ModuleMapPath); |
| 3635 | } |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 3636 | } |
| 3637 | return OutOfDate; |
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3638 | } |
| 3639 | |
| Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 3640 | assert(M->Name == F.ModuleName && "found module with different name"); |
| 3641 | |
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3642 | // Check the primary module map file. |
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3643 | const FileEntry *StoredModMap = FileMgr.getFile(F.ModuleMapPath); |
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3644 | if (StoredModMap == nullptr || StoredModMap != ModMap) { |
| 3645 | assert(ModMap && "found module is missing module map file"); |
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3646 | assert(ImportedBy && "top-level import should be verified"); |
| 3647 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3648 | Diag(diag::err_imported_module_modmap_changed) |
| 3649 | << F.ModuleName << ImportedBy->FileName |
| 3650 | << ModMap->getName() << F.ModuleMapPath; |
| 3651 | return OutOfDate; |
| 3652 | } |
| 3653 | |
| 3654 | llvm::SmallPtrSet<const FileEntry *, 1> AdditionalStoredMaps; |
| 3655 | for (unsigned I = 0, N = Record[Idx++]; I < N; ++I) { |
| 3656 | // FIXME: we should use input files rather than storing names. |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 3657 | std::string Filename = ReadPath(F, Record, Idx); |
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3658 | const FileEntry *F = |
| 3659 | FileMgr.getFile(Filename, false, false); |
| 3660 | if (F == nullptr) { |
| 3661 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3662 | Error("could not find file '" + Filename +"' referenced by AST file"); |
| 3663 | return OutOfDate; |
| 3664 | } |
| 3665 | AdditionalStoredMaps.insert(F); |
| 3666 | } |
| 3667 | |
| 3668 | // Check any additional module map files (e.g. module.private.modulemap) |
| 3669 | // that are not in the pcm. |
| 3670 | if (auto *AdditionalModuleMaps = Map.getAdditionalModuleMapFiles(M)) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 3671 | for (const FileEntry *ModMap : *AdditionalModuleMaps) { |
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3672 | // Remove files that match |
| 3673 | // Note: SmallPtrSet::erase is really remove |
| 3674 | if (!AdditionalStoredMaps.erase(ModMap)) { |
| 3675 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3676 | Diag(diag::err_module_different_modmap) |
| 3677 | << F.ModuleName << /*new*/0 << ModMap->getName(); |
| 3678 | return OutOfDate; |
| 3679 | } |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | // Check any additional module map files that are in the pcm, but not |
| 3684 | // found in header search. Cases that match are already removed. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 3685 | for (const FileEntry *ModMap : AdditionalStoredMaps) { |
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 3686 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 3687 | Diag(diag::err_module_different_modmap) |
| 3688 | << F.ModuleName << /*not new*/1 << ModMap->getName(); |
| 3689 | return OutOfDate; |
| 3690 | } |
| 3691 | } |
| 3692 | |
| 3693 | if (Listener) |
| 3694 | Listener->ReadModuleMapFile(F.ModuleMapPath); |
| 3695 | return Success; |
| 3696 | } |
| 3697 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3698 | /// Move the given method to the back of the global list of methods. |
| Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3699 | static void moveMethodToBackOfGlobalList(Sema &S, ObjCMethodDecl *Method) { |
| 3700 | // Find the entry for this selector in the method pool. |
| 3701 | Sema::GlobalMethodPool::iterator Known |
| 3702 | = S.MethodPool.find(Method->getSelector()); |
| 3703 | if (Known == S.MethodPool.end()) |
| 3704 | return; |
| 3705 | |
| 3706 | // Retrieve the appropriate method list. |
| 3707 | ObjCMethodList &Start = Method->isInstanceMethod()? Known->second.first |
| 3708 | : Known->second.second; |
| 3709 | bool Found = false; |
| Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3710 | for (ObjCMethodList *List = &Start; List; List = List->getNext()) { |
| Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3711 | if (!Found) { |
| Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3712 | if (List->getMethod() == Method) { |
| Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3713 | Found = true; |
| 3714 | } else { |
| 3715 | // Keep searching. |
| 3716 | continue; |
| 3717 | } |
| 3718 | } |
| 3719 | |
| Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 3720 | if (List->getNext()) |
| Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3721 | List->setMethod(List->getNext()->getMethod()); |
| Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3722 | else |
| Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 3723 | List->setMethod(Method); |
| Douglas Gregor | c148956 | 2013-02-12 23:36:21 +0000 | [diff] [blame] | 3724 | } |
| 3725 | } |
| 3726 | |
| Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 3727 | void ASTReader::makeNamesVisible(const HiddenNames &Names, Module *Owner) { |
| Richard Smith | 10434f3 | 2015-05-02 02:08:26 +0000 | [diff] [blame] | 3728 | assert(Owner->NameVisibility != Module::Hidden && "nothing to make visible?"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 3729 | for (Decl *D : Names) { |
| Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 3730 | bool wasHidden = D->isHidden(); |
| 3731 | D->setVisibleDespiteOwningModule(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3732 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 3733 | if (wasHidden && SemaObj) { |
| 3734 | if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D)) { |
| Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3735 | moveMethodToBackOfGlobalList(*SemaObj, Method); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 3736 | } |
| 3737 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3738 | } |
| 3739 | } |
| 3740 | |
| Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3741 | void ASTReader::makeModuleVisible(Module *Mod, |
| Argyrios Kyrtzidis | 125df05 | 2013-02-01 16:36:12 +0000 | [diff] [blame] | 3742 | Module::NameVisibilityKind NameVisibility, |
| Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 3743 | SourceLocation ImportLoc) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3744 | llvm::SmallPtrSet<Module *, 4> Visited; |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3745 | SmallVector<Module *, 4> Stack; |
| Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3746 | Stack.push_back(Mod); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3747 | while (!Stack.empty()) { |
| Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3748 | Mod = Stack.pop_back_val(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3749 | |
| 3750 | if (NameVisibility <= Mod->NameVisibility) { |
| Robert Wilhelm | 25284cc | 2013-08-23 16:11:15 +0000 | [diff] [blame] | 3751 | // This module already has this level of visibility (or greater), so |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3752 | // there is nothing more to do. |
| 3753 | continue; |
| 3754 | } |
| Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3755 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3756 | if (!Mod->isAvailable()) { |
| 3757 | // Modules that aren't available cannot be made visible. |
| 3758 | continue; |
| 3759 | } |
| 3760 | |
| 3761 | // Update the module's name visibility. |
| 3762 | Mod->NameVisibility = NameVisibility; |
| Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 3763 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3764 | // If we've already deserialized any names from this module, |
| 3765 | // mark them as visible. |
| 3766 | HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod); |
| 3767 | if (Hidden != HiddenNamesMap.end()) { |
| Richard Smith | 57721ac | 2014-07-21 04:10:40 +0000 | [diff] [blame] | 3768 | auto HiddenNames = std::move(*Hidden); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3769 | HiddenNamesMap.erase(Hidden); |
| Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 3770 | makeNamesVisible(HiddenNames.second, HiddenNames.first); |
| Richard Smith | 57721ac | 2014-07-21 04:10:40 +0000 | [diff] [blame] | 3771 | assert(HiddenNamesMap.find(Mod) == HiddenNamesMap.end() && |
| 3772 | "making names visible added hidden names"); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3773 | } |
| Dmitri Gribenko | e9bcf5b | 2013-11-04 21:51:33 +0000 | [diff] [blame] | 3774 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3775 | // Push any exported modules onto the stack to be marked as visible. |
| Argyrios Kyrtzidis | 8739f7b | 2013-02-19 19:34:40 +0000 | [diff] [blame] | 3776 | SmallVector<Module *, 16> Exports; |
| 3777 | Mod->getExportedModules(Exports); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 3778 | for (SmallVectorImpl<Module *>::iterator |
| 3779 | I = Exports.begin(), E = Exports.end(); I != E; ++I) { |
| 3780 | Module *Exported = *I; |
| David Blaikie | 82e95a3 | 2014-11-19 07:49:47 +0000 | [diff] [blame] | 3781 | if (Visited.insert(Exported).second) |
| Argyrios Kyrtzidis | 8739f7b | 2013-02-19 19:34:40 +0000 | [diff] [blame] | 3782 | Stack.push_back(Exported); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 3783 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3784 | } |
| 3785 | } |
| 3786 | |
| Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 3787 | /// We've merged the definition \p MergedDef into the existing definition |
| 3788 | /// \p Def. Ensure that \p Def is made visible whenever \p MergedDef is made |
| 3789 | /// visible. |
| 3790 | void ASTReader::mergeDefinitionVisibility(NamedDecl *Def, |
| 3791 | NamedDecl *MergedDef) { |
| Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 3792 | if (Def->isHidden()) { |
| 3793 | // If MergedDef is visible or becomes visible, make the definition visible. |
| Benjamin Kramer | a72a70a | 2016-10-17 13:00:44 +0000 | [diff] [blame] | 3794 | if (!MergedDef->isHidden()) |
| Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 3795 | Def->setVisibleDespiteOwningModule(); |
| Richard Smith | 13897eb | 2018-09-12 23:37:00 +0000 | [diff] [blame] | 3796 | else { |
| Benjamin Kramer | a72a70a | 2016-10-17 13:00:44 +0000 | [diff] [blame] | 3797 | getContext().mergeDefinitionIntoModule( |
| 3798 | Def, MergedDef->getImportedOwningModule(), |
| 3799 | /*NotifyListeners*/ false); |
| 3800 | PendingMergedDefinitionsToDeduplicate.insert(Def); |
| Benjamin Kramer | a72a70a | 2016-10-17 13:00:44 +0000 | [diff] [blame] | 3801 | } |
| Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 3802 | } |
| 3803 | } |
| 3804 | |
| Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3805 | bool ASTReader::loadGlobalIndex() { |
| 3806 | if (GlobalIndex) |
| 3807 | return false; |
| 3808 | |
| 3809 | if (TriedLoadingGlobalIndex || !UseGlobalIndex || |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3810 | !PP.getLangOpts().Modules) |
| Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3811 | return true; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3812 | |
| Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3813 | // Try to load the global index. |
| 3814 | TriedLoadingGlobalIndex = true; |
| 3815 | StringRef ModuleCachePath |
| 3816 | = getPreprocessor().getHeaderSearchInfo().getModuleCachePath(); |
| 3817 | std::pair<GlobalModuleIndex *, GlobalModuleIndex::ErrorCode> Result |
| Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3818 | = GlobalModuleIndex::readIndex(ModuleCachePath); |
| Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3819 | if (!Result.first) |
| 3820 | return true; |
| 3821 | |
| 3822 | GlobalIndex.reset(Result.first); |
| Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 3823 | ModuleMgr.setGlobalIndex(GlobalIndex.get()); |
| Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3824 | return false; |
| 3825 | } |
| 3826 | |
| 3827 | bool ASTReader::isGlobalIndexUnavailable() const { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3828 | return PP.getLangOpts().Modules && UseGlobalIndex && |
| Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3829 | !hasGlobalIndex() && TriedLoadingGlobalIndex; |
| 3830 | } |
| 3831 | |
| Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3832 | static void updateModuleTimestamp(ModuleFile &MF) { |
| 3833 | // Overwrite the timestamp file contents so that file's mtime changes. |
| 3834 | std::string TimestampFilename = MF.getTimestampFilename(); |
| Rafael Espindola | dae941a | 2014-08-25 18:17:04 +0000 | [diff] [blame] | 3835 | std::error_code EC; |
| 3836 | llvm::raw_fd_ostream OS(TimestampFilename, EC, llvm::sys::fs::F_Text); |
| 3837 | if (EC) |
| Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3838 | return; |
| 3839 | OS << "Timestamp file\n"; |
| Alex Lorenz | 0bafa02 | 2017-06-02 10:36:56 +0000 | [diff] [blame] | 3840 | OS.close(); |
| 3841 | OS.clear_error(); // Avoid triggering a fatal error. |
| Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 3842 | } |
| 3843 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3844 | /// Given a cursor at the start of an AST file, scan ahead and drop the |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3845 | /// cursor into the start of the given block ID, returning false on success and |
| 3846 | /// true on failure. |
| 3847 | static bool SkipCursorToBlock(BitstreamCursor &Cursor, unsigned BlockID) { |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 3848 | while (true) { |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3849 | llvm::BitstreamEntry Entry = Cursor.advance(); |
| 3850 | switch (Entry.Kind) { |
| 3851 | case llvm::BitstreamEntry::Error: |
| 3852 | case llvm::BitstreamEntry::EndBlock: |
| 3853 | return true; |
| 3854 | |
| 3855 | case llvm::BitstreamEntry::Record: |
| 3856 | // Ignore top-level records. |
| 3857 | Cursor.skipRecord(Entry.ID); |
| 3858 | break; |
| 3859 | |
| 3860 | case llvm::BitstreamEntry::SubBlock: |
| 3861 | if (Entry.ID == BlockID) { |
| 3862 | if (Cursor.EnterSubBlock(BlockID)) |
| 3863 | return true; |
| 3864 | // Found it! |
| 3865 | return false; |
| 3866 | } |
| 3867 | |
| 3868 | if (Cursor.SkipBlock()) |
| 3869 | return true; |
| 3870 | } |
| 3871 | } |
| 3872 | } |
| 3873 | |
| Benjamin Kramer | 0772c42 | 2016-02-13 13:42:54 +0000 | [diff] [blame] | 3874 | ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3875 | ModuleKind Type, |
| 3876 | SourceLocation ImportLoc, |
| Graydon Hoare | e7196af | 2016-12-09 21:45:49 +0000 | [diff] [blame] | 3877 | unsigned ClientLoadCapabilities, |
| 3878 | SmallVectorImpl<ImportedSubmodule> *Imported) { |
| Argyrios Kyrtzidis | dc9fdaf | 2013-05-24 05:44:08 +0000 | [diff] [blame] | 3879 | llvm::SaveAndRestore<SourceLocation> |
| 3880 | SetCurImportLocRAII(CurrentImportLoc, ImportLoc); |
| 3881 | |
| Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 3882 | // Defer any pending actions until we get to the end of reading the AST file. |
| 3883 | Deserializing AnASTFile(this); |
| 3884 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3885 | // Bump the generation number. |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3886 | unsigned PreviousGeneration = 0; |
| 3887 | if (ContextObj) |
| 3888 | PreviousGeneration = incrementGeneration(*ContextObj); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3889 | |
| 3890 | unsigned NumModules = ModuleMgr.size(); |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 3891 | SmallVector<ImportedModule, 4> Loaded; |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 3892 | switch (ASTReadResult ReadResult = |
| 3893 | ReadASTCore(FileName, Type, ImportLoc, |
| 3894 | /*ImportedBy=*/nullptr, Loaded, 0, 0, |
| 3895 | ASTFileSignature(), ClientLoadCapabilities)) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3896 | case Failure: |
| Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 3897 | case Missing: |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3898 | case OutOfDate: |
| 3899 | case VersionMismatch: |
| 3900 | case ConfigurationMismatch: |
| Ben Langmuir | 9801b25 | 2014-06-20 00:24:56 +0000 | [diff] [blame] | 3901 | case HadErrors: { |
| 3902 | llvm::SmallPtrSet<ModuleFile *, 4> LoadedSet; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 3903 | for (const ImportedModule &IM : Loaded) |
| Ben Langmuir | 9801b25 | 2014-06-20 00:24:56 +0000 | [diff] [blame] | 3904 | LoadedSet.insert(IM.Mod); |
| 3905 | |
| Duncan P. N. Exon Smith | 8e6bc197 | 2017-01-28 23:02:12 +0000 | [diff] [blame] | 3906 | ModuleMgr.removeModules(ModuleMgr.begin() + NumModules, LoadedSet, |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3907 | PP.getLangOpts().Modules |
| Duncan P. N. Exon Smith | 8e6bc197 | 2017-01-28 23:02:12 +0000 | [diff] [blame] | 3908 | ? &PP.getHeaderSearchInfo().getModuleMap() |
| 3909 | : nullptr); |
| Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 3910 | |
| 3911 | // If we find that any modules are unusable, the global index is going |
| 3912 | // to be out-of-date. Just remove it. |
| 3913 | GlobalIndex.reset(); |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3914 | ModuleMgr.setGlobalIndex(nullptr); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3915 | return ReadResult; |
| Ben Langmuir | 9801b25 | 2014-06-20 00:24:56 +0000 | [diff] [blame] | 3916 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3917 | case Success: |
| 3918 | break; |
| 3919 | } |
| 3920 | |
| 3921 | // Here comes stuff that we only do once the entire chain is loaded. |
| 3922 | |
| 3923 | // Load the AST blocks of all of the modules that we loaded. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 3924 | for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(), |
| 3925 | MEnd = Loaded.end(); |
| 3926 | M != MEnd; ++M) { |
| 3927 | ModuleFile &F = *M->Mod; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3928 | |
| 3929 | // Read the AST block. |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 3930 | if (ASTReadResult Result = ReadASTBlock(F, ClientLoadCapabilities)) |
| 3931 | return Result; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3932 | |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 3933 | // Read the extension blocks. |
| 3934 | while (!SkipCursorToBlock(F.Stream, EXTENSION_BLOCK_ID)) { |
| 3935 | if (ASTReadResult Result = ReadExtensionBlock(F)) |
| 3936 | return Result; |
| 3937 | } |
| 3938 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3939 | // 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] | 3940 | // bits of all files we've seen. |
| 3941 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 3942 | TotalModulesSizeInBits += F.SizeInBits; |
| 3943 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 3944 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3945 | // Preload SLocEntries. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 3946 | for (unsigned I = 0, N = F.PreloadSLocEntries.size(); I != N; ++I) { |
| 3947 | int Index = int(F.PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3948 | // Load it through the SourceManager and don't call ReadSLocEntry() |
| 3949 | // directly because the entry may have already been loaded in which case |
| 3950 | // calling ReadSLocEntry() directly would trigger an assertion in |
| 3951 | // SourceManager. |
| 3952 | SourceMgr.getLoadedSLocEntryByID(Index); |
| 3953 | } |
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3954 | |
| Richard Smith | ea74148 | 2017-05-01 22:10:47 +0000 | [diff] [blame] | 3955 | // Map the original source file ID into the ID space of the current |
| 3956 | // compilation. |
| 3957 | if (F.OriginalSourceFileID.isValid()) { |
| 3958 | F.OriginalSourceFileID = FileID::get( |
| 3959 | F.SLocEntryBaseID + F.OriginalSourceFileID.getOpaqueValue() - 1); |
| 3960 | } |
| 3961 | |
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3962 | // Preload all the pending interesting identifiers by marking them out of |
| 3963 | // date. |
| 3964 | for (auto Offset : F.PreloadIdentifierOffsets) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 3965 | const unsigned char *Data = reinterpret_cast<const unsigned char *>( |
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3966 | F.IdentifierTableData + Offset); |
| 3967 | |
| 3968 | ASTIdentifierLookupTrait Trait(*this, F); |
| 3969 | auto KeyDataLen = Trait.ReadKeyDataLength(Data); |
| 3970 | auto Key = Trait.ReadKey(Data, KeyDataLen.first); |
| Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 3971 | auto &II = PP.getIdentifierTable().getOwn(Key); |
| 3972 | II.setOutOfDate(true); |
| 3973 | |
| 3974 | // Mark this identifier as being from an AST file so that we can track |
| 3975 | // whether we need to serialize it. |
| Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 3976 | markIdentifierFromAST(*this, II); |
| Richard Smith | 79bf920 | 2015-08-24 03:33:22 +0000 | [diff] [blame] | 3977 | |
| 3978 | // Associate the ID with the identifier so that the writer can reuse it. |
| 3979 | auto ID = Trait.ReadIdentifierID(Data + KeyDataLen.first); |
| 3980 | SetIdentifierInfo(ID, &II); |
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 3981 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3982 | } |
| 3983 | |
| Douglas Gregor | 603cd86 | 2013-03-22 18:50:14 +0000 | [diff] [blame] | 3984 | // Setup the import locations and notify the module manager that we've |
| 3985 | // committed to these module files. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 3986 | for (SmallVectorImpl<ImportedModule>::iterator M = Loaded.begin(), |
| 3987 | MEnd = Loaded.end(); |
| 3988 | M != MEnd; ++M) { |
| 3989 | ModuleFile &F = *M->Mod; |
| Douglas Gregor | 603cd86 | 2013-03-22 18:50:14 +0000 | [diff] [blame] | 3990 | |
| 3991 | ModuleMgr.moduleFileAccepted(&F); |
| 3992 | |
| 3993 | // Set the import location. |
| Argyrios Kyrtzidis | 71c1af8 | 2013-02-01 16:36:14 +0000 | [diff] [blame] | 3994 | F.DirectImportLoc = ImportLoc; |
| Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 3995 | // FIXME: We assume that locations from PCH / preamble do not need |
| 3996 | // any translation. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 3997 | if (!M->ImportedBy) |
| 3998 | F.ImportLoc = M->ImportLoc; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 3999 | else |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4000 | F.ImportLoc = TranslateSourceLocation(*M->ImportedBy, M->ImportLoc); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4001 | } |
| 4002 | |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4003 | if (!PP.getLangOpts().CPlusPlus || |
| Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 4004 | (Type != MK_ImplicitModule && Type != MK_ExplicitModule && |
| 4005 | Type != MK_PrebuiltModule)) { |
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 4006 | // Mark all of the identifiers in the identifier table as being out of date, |
| 4007 | // so that various accessors know to check the loaded modules when the |
| 4008 | // identifier is used. |
| 4009 | // |
| 4010 | // For C++ modules, we don't need information on many identifiers (just |
| 4011 | // those that provide macros or are poisoned), so we mark all of |
| 4012 | // the interesting ones via PreloadIdentifierOffsets. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4013 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 4014 | IdEnd = PP.getIdentifierTable().end(); |
| 4015 | Id != IdEnd; ++Id) |
| 4016 | Id->second->setOutOfDate(true); |
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 4017 | } |
| Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 4018 | // Mark selectors as out of date. |
| 4019 | for (auto Sel : SelectorGeneration) |
| 4020 | SelectorOutOfDate[Sel.first] = true; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4021 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4022 | // Resolve any unresolved module exports. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4023 | for (unsigned I = 0, N = UnresolvedModuleRefs.size(); I != N; ++I) { |
| 4024 | UnresolvedModuleRef &Unresolved = UnresolvedModuleRefs[I]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4025 | SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID); |
| 4026 | Module *ResolvedMod = getSubmodule(GlobalID); |
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4027 | |
| 4028 | switch (Unresolved.Kind) { |
| 4029 | case UnresolvedModuleRef::Conflict: |
| 4030 | if (ResolvedMod) { |
| 4031 | Module::Conflict Conflict; |
| 4032 | Conflict.Other = ResolvedMod; |
| 4033 | Conflict.Message = Unresolved.String.str(); |
| 4034 | Unresolved.Mod->Conflicts.push_back(Conflict); |
| 4035 | } |
| 4036 | continue; |
| 4037 | |
| 4038 | case UnresolvedModuleRef::Import: |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4039 | if (ResolvedMod) |
| Richard Smith | 38477db | 2015-05-02 00:45:56 +0000 | [diff] [blame] | 4040 | Unresolved.Mod->Imports.insert(ResolvedMod); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4041 | continue; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4042 | |
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4043 | case UnresolvedModuleRef::Export: |
| 4044 | if (ResolvedMod || Unresolved.IsWildcard) |
| 4045 | Unresolved.Mod->Exports.push_back( |
| 4046 | Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard)); |
| 4047 | continue; |
| 4048 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4049 | } |
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 4050 | UnresolvedModuleRefs.clear(); |
| Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 4051 | |
| Graydon Hoare | e7196af | 2016-12-09 21:45:49 +0000 | [diff] [blame] | 4052 | if (Imported) |
| 4053 | Imported->append(ImportedModules.begin(), |
| 4054 | ImportedModules.end()); |
| 4055 | |
| Daniel Jasper | ba7f2f7 | 2013-09-24 09:14:14 +0000 | [diff] [blame] | 4056 | // FIXME: How do we load the 'use'd modules? They may not be submodules. |
| 4057 | // Might be unnecessary as use declarations are only used to build the |
| 4058 | // module itself. |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4059 | |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4060 | if (ContextObj) |
| 4061 | InitializeContext(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4062 | |
| Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 4063 | if (SemaObj) |
| 4064 | UpdateSema(); |
| 4065 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4066 | if (DeserializationListener) |
| 4067 | DeserializationListener->ReaderInitialized(this); |
| 4068 | |
| 4069 | ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule(); |
| Yaron Keren | 8b56366 | 2015-10-03 10:46:20 +0000 | [diff] [blame] | 4070 | if (PrimaryModule.OriginalSourceFileID.isValid()) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4071 | // If this AST file is a precompiled preamble, then set the |
| 4072 | // preamble file ID of the source manager to the file source file |
| 4073 | // from which the preamble was built. |
| 4074 | if (Type == MK_Preamble) { |
| 4075 | SourceMgr.setPreambleFileID(PrimaryModule.OriginalSourceFileID); |
| 4076 | } else if (Type == MK_MainFile) { |
| 4077 | SourceMgr.setMainFileID(PrimaryModule.OriginalSourceFileID); |
| 4078 | } |
| 4079 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4080 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4081 | // For any Objective-C class definitions we have already loaded, make sure |
| 4082 | // that we load any additional categories. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4083 | if (ContextObj) { |
| 4084 | for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) { |
| 4085 | loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(), |
| 4086 | ObjCClassesLoaded[I], |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4087 | PreviousGeneration); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4088 | } |
| 4089 | } |
| Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 4090 | |
| Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 4091 | if (PP.getHeaderSearchInfo() |
| 4092 | .getHeaderSearchOpts() |
| 4093 | .ModulesValidateOncePerBuildSession) { |
| 4094 | // Now we are certain that the module and all modules it depends on are |
| 4095 | // up to date. Create or update timestamp files for modules that are |
| 4096 | // located in the module cache (not for PCH files that could be anywhere |
| 4097 | // in the filesystem). |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4098 | for (unsigned I = 0, N = Loaded.size(); I != N; ++I) { |
| 4099 | ImportedModule &M = Loaded[I]; |
| 4100 | if (M.Mod->Kind == MK_ImplicitModule) { |
| Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 4101 | updateModuleTimestamp(*M.Mod); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4102 | } |
| 4103 | } |
| Dmitri Gribenko | f430da4 | 2014-02-12 10:33:14 +0000 | [diff] [blame] | 4104 | } |
| 4105 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4106 | return Success; |
| 4107 | } |
| 4108 | |
| Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4109 | static ASTFileSignature readASTFileSignature(StringRef PCH); |
| Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4110 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4111 | /// Whether \p Stream starts with the AST/PCH file magic number 'CPCH'. |
| Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4112 | static bool startsWithASTFileMagic(BitstreamCursor &Stream) { |
| Peter Collingbourne | 028eb5a | 2016-11-02 00:08:19 +0000 | [diff] [blame] | 4113 | return Stream.canSkipToPos(4) && |
| 4114 | Stream.Read(8) == 'C' && |
| Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4115 | Stream.Read(8) == 'P' && |
| 4116 | Stream.Read(8) == 'C' && |
| 4117 | Stream.Read(8) == 'H'; |
| 4118 | } |
| 4119 | |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4120 | static unsigned moduleKindForDiagnostic(ModuleKind Kind) { |
| 4121 | switch (Kind) { |
| 4122 | case MK_PCH: |
| 4123 | return 0; // PCH |
| 4124 | case MK_ImplicitModule: |
| 4125 | case MK_ExplicitModule: |
| Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 4126 | case MK_PrebuiltModule: |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4127 | return 1; // module |
| 4128 | case MK_MainFile: |
| 4129 | case MK_Preamble: |
| 4130 | return 2; // main source file |
| 4131 | } |
| 4132 | llvm_unreachable("unknown module kind"); |
| 4133 | } |
| 4134 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4135 | ASTReader::ASTReadResult |
| 4136 | ASTReader::ReadASTCore(StringRef FileName, |
| 4137 | ModuleKind Type, |
| 4138 | SourceLocation ImportLoc, |
| 4139 | ModuleFile *ImportedBy, |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 4140 | SmallVectorImpl<ImportedModule> &Loaded, |
| Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4141 | off_t ExpectedSize, time_t ExpectedModTime, |
| Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4142 | ASTFileSignature ExpectedSignature, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4143 | unsigned ClientLoadCapabilities) { |
| 4144 | ModuleFile *M; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4145 | std::string ErrorStr; |
| Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4146 | ModuleManager::AddModuleResult AddResult |
| 4147 | = ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy, |
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 4148 | getGeneration(), ExpectedSize, ExpectedModTime, |
| Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4149 | ExpectedSignature, readASTFileSignature, |
| Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4150 | M, ErrorStr); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4151 | |
| Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4152 | switch (AddResult) { |
| 4153 | case ModuleManager::AlreadyLoaded: |
| Duncan P. N. Exon Smith | 9dda8f5 | 2019-03-06 02:50:46 +0000 | [diff] [blame] | 4154 | Diag(diag::remark_module_import) |
| 4155 | << M->ModuleName << M->FileName << (ImportedBy ? true : false) |
| 4156 | << (ImportedBy ? StringRef(ImportedBy->ModuleName) : StringRef()); |
| Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4157 | return Success; |
| 4158 | |
| 4159 | case ModuleManager::NewlyLoaded: |
| 4160 | // Load module file below. |
| 4161 | break; |
| 4162 | |
| 4163 | case ModuleManager::Missing: |
| Richard Smith | e842a47 | 2014-10-22 02:05:46 +0000 | [diff] [blame] | 4164 | // The module file was missing; if the client can handle that, return |
| Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4165 | // it. |
| 4166 | if (ClientLoadCapabilities & ARR_Missing) |
| 4167 | return Missing; |
| 4168 | |
| 4169 | // Otherwise, return an error. |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4170 | Diag(diag::err_module_file_not_found) << moduleKindForDiagnostic(Type) |
| Adrian Prantl | b3b5a73 | 2016-08-29 20:46:59 +0000 | [diff] [blame] | 4171 | << FileName << !ErrorStr.empty() |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4172 | << ErrorStr; |
| Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4173 | return Failure; |
| 4174 | |
| 4175 | case ModuleManager::OutOfDate: |
| 4176 | // We couldn't load the module file because it is out-of-date. If the |
| 4177 | // client can handle out-of-date, return it. |
| 4178 | if (ClientLoadCapabilities & ARR_OutOfDate) |
| 4179 | return OutOfDate; |
| 4180 | |
| 4181 | // Otherwise, return an error. |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4182 | Diag(diag::err_module_file_out_of_date) << moduleKindForDiagnostic(Type) |
| Adrian Prantl | 9a06a88 | 2016-08-29 20:46:56 +0000 | [diff] [blame] | 4183 | << FileName << !ErrorStr.empty() |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4184 | << ErrorStr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4185 | return Failure; |
| 4186 | } |
| 4187 | |
| Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4188 | assert(M && "Missing module file"); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4189 | |
| Duncan P. N. Exon Smith | 0a2be46 | 2019-03-09 17:44:01 +0000 | [diff] [blame] | 4190 | bool ShouldFinalizePCM = false; |
| 4191 | auto FinalizeOrDropPCM = llvm::make_scope_exit([&]() { |
| 4192 | auto &MC = getModuleManager().getModuleCache(); |
| 4193 | if (ShouldFinalizePCM) |
| 4194 | MC.finalizePCM(FileName); |
| 4195 | else |
| 4196 | MC.tryToDropPCM(FileName); |
| 4197 | }); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4198 | ModuleFile &F = *M; |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4199 | BitstreamCursor &Stream = F.Stream; |
| Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4200 | Stream = BitstreamCursor(PCHContainerRdr.ExtractPCH(*F.Buffer)); |
| Adrian Prantl | cbc368c | 2015-02-25 02:44:04 +0000 | [diff] [blame] | 4201 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4202 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4203 | // Sniff for the signature. |
| Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4204 | if (!startsWithASTFileMagic(Stream)) { |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4205 | Diag(diag::err_module_file_invalid) << moduleKindForDiagnostic(Type) |
| 4206 | << FileName; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4207 | return Failure; |
| 4208 | } |
| 4209 | |
| 4210 | // This is used for compatibility with older PCH formats. |
| 4211 | bool HaveReadControlBlock = false; |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4212 | while (true) { |
| Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4213 | llvm::BitstreamEntry Entry = Stream.advance(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4214 | |
| Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4215 | switch (Entry.Kind) { |
| 4216 | case llvm::BitstreamEntry::Error: |
| Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4217 | case llvm::BitstreamEntry::Record: |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4218 | case llvm::BitstreamEntry::EndBlock: |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4219 | Error("invalid record at top-level of AST file"); |
| 4220 | return Failure; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4221 | |
| Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4222 | case llvm::BitstreamEntry::SubBlock: |
| 4223 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4224 | } |
| 4225 | |
| Chris Lattner | efa7717 | 2013-01-20 00:00:22 +0000 | [diff] [blame] | 4226 | switch (Entry.ID) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4227 | case CONTROL_BLOCK_ID: |
| 4228 | HaveReadControlBlock = true; |
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 4229 | switch (ReadControlBlock(F, Loaded, ImportedBy, ClientLoadCapabilities)) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4230 | case Success: |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4231 | // Check that we didn't try to load a non-module AST file as a module. |
| 4232 | // |
| 4233 | // FIXME: Should we also perform the converse check? Loading a module as |
| 4234 | // a PCH file sort of works, but it's a bit wonky. |
| Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 4235 | if ((Type == MK_ImplicitModule || Type == MK_ExplicitModule || |
| 4236 | Type == MK_PrebuiltModule) && |
| Richard Smith | 0f99d6a | 2015-08-09 08:48:41 +0000 | [diff] [blame] | 4237 | F.ModuleName.empty()) { |
| 4238 | auto Result = (Type == MK_ImplicitModule) ? OutOfDate : Failure; |
| 4239 | if (Result != OutOfDate || |
| 4240 | (ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 4241 | Diag(diag::err_module_file_not_module) << FileName; |
| 4242 | return Result; |
| 4243 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4244 | break; |
| 4245 | |
| 4246 | case Failure: return Failure; |
| Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 4247 | case Missing: return Missing; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4248 | case OutOfDate: return OutOfDate; |
| 4249 | case VersionMismatch: return VersionMismatch; |
| 4250 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 4251 | case HadErrors: return HadErrors; |
| 4252 | } |
| 4253 | break; |
| Richard Smith | f8c3255 | 2015-09-02 17:45:54 +0000 | [diff] [blame] | 4254 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4255 | case AST_BLOCK_ID: |
| 4256 | if (!HaveReadControlBlock) { |
| 4257 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
| Dmitri Gribenko | 2228cd3 | 2014-02-11 15:40:09 +0000 | [diff] [blame] | 4258 | Diag(diag::err_pch_version_too_old); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4259 | return VersionMismatch; |
| 4260 | } |
| 4261 | |
| 4262 | // Record that we've loaded this module. |
| 4263 | Loaded.push_back(ImportedModule(M, ImportedBy, ImportLoc)); |
| Duncan P. N. Exon Smith | 0a2be46 | 2019-03-09 17:44:01 +0000 | [diff] [blame] | 4264 | ShouldFinalizePCM = true; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4265 | return Success; |
| 4266 | |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4267 | case UNHASHED_CONTROL_BLOCK_ID: |
| 4268 | // This block is handled using look-ahead during ReadControlBlock. We |
| 4269 | // shouldn't get here! |
| 4270 | Error("malformed block record in AST file"); |
| 4271 | return Failure; |
| 4272 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4273 | default: |
| 4274 | if (Stream.SkipBlock()) { |
| 4275 | Error("malformed block record in AST file"); |
| 4276 | return Failure; |
| 4277 | } |
| 4278 | break; |
| 4279 | } |
| 4280 | } |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4281 | |
| Duncan P. N. Exon Smith | fae03d8 | 2019-03-03 20:17:53 +0000 | [diff] [blame] | 4282 | llvm_unreachable("unexpected break; expected return"); |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4283 | } |
| 4284 | |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4285 | ASTReader::ASTReadResult |
| 4286 | ASTReader::readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy, |
| 4287 | unsigned ClientLoadCapabilities) { |
| 4288 | const HeaderSearchOptions &HSOpts = |
| 4289 | PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 4290 | bool AllowCompatibleConfigurationMismatch = |
| 4291 | F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule; |
| 4292 | |
| 4293 | ASTReadResult Result = readUnhashedControlBlockImpl( |
| 4294 | &F, F.Data, ClientLoadCapabilities, AllowCompatibleConfigurationMismatch, |
| 4295 | Listener.get(), |
| 4296 | WasImportedBy ? false : HSOpts.ModulesValidateDiagnosticOptions); |
| 4297 | |
| Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4298 | // If F was directly imported by another module, it's implicitly validated by |
| 4299 | // the importing module. |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4300 | if (DisableValidation || WasImportedBy || |
| 4301 | (AllowConfigurationMismatch && Result == ConfigurationMismatch)) |
| 4302 | return Success; |
| 4303 | |
| Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4304 | if (Result == Failure) { |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4305 | Error("malformed block record in AST file"); |
| Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4306 | return Failure; |
| 4307 | } |
| 4308 | |
| 4309 | if (Result == OutOfDate && F.Kind == MK_ImplicitModule) { |
| Duncan P. N. Exon Smith | 8bef5cd | 2019-03-09 17:33:56 +0000 | [diff] [blame] | 4310 | // If this module has already been finalized in the ModuleCache, we're stuck |
| Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4311 | // with it; we can only load a single version of each module. |
| 4312 | // |
| 4313 | // This can happen when a module is imported in two contexts: in one, as a |
| 4314 | // user module; in another, as a system module (due to an import from |
| 4315 | // another module marked with the [system] flag). It usually indicates a |
| 4316 | // bug in the module map: this module should also be marked with [system]. |
| 4317 | // |
| 4318 | // If -Wno-system-headers (the default), and the first import is as a |
| 4319 | // system module, then validation will fail during the as-user import, |
| 4320 | // since -Werror flags won't have been validated. However, it's reasonable |
| 4321 | // to treat this consistently as a system module. |
| 4322 | // |
| 4323 | // If -Wsystem-headers, the PCM on disk was built with |
| 4324 | // -Wno-system-headers, and the first import is as a user module, then |
| 4325 | // validation will fail during the as-system import since the PCM on disk |
| 4326 | // doesn't guarantee that -Werror was respected. However, the -Werror |
| 4327 | // flags were checked during the initial as-user import. |
| Duncan P. N. Exon Smith | 0a2be46 | 2019-03-09 17:44:01 +0000 | [diff] [blame] | 4328 | if (getModuleManager().getModuleCache().isPCMFinal(F.FileName)) { |
| Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4329 | Diag(diag::warn_module_system_bit_conflict) << F.FileName; |
| 4330 | return Success; |
| 4331 | } |
| 4332 | } |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4333 | |
| 4334 | return Result; |
| 4335 | } |
| 4336 | |
| 4337 | ASTReader::ASTReadResult ASTReader::readUnhashedControlBlockImpl( |
| 4338 | ModuleFile *F, llvm::StringRef StreamData, unsigned ClientLoadCapabilities, |
| 4339 | bool AllowCompatibleConfigurationMismatch, ASTReaderListener *Listener, |
| 4340 | bool ValidateDiagnosticOptions) { |
| 4341 | // Initialize a stream. |
| 4342 | BitstreamCursor Stream(StreamData); |
| 4343 | |
| 4344 | // Sniff for the signature. |
| 4345 | if (!startsWithASTFileMagic(Stream)) |
| 4346 | return Failure; |
| 4347 | |
| 4348 | // Scan for the UNHASHED_CONTROL_BLOCK_ID block. |
| 4349 | if (SkipCursorToBlock(Stream, UNHASHED_CONTROL_BLOCK_ID)) |
| 4350 | return Failure; |
| 4351 | |
| 4352 | // Read all of the records in the options block. |
| 4353 | RecordData Record; |
| 4354 | ASTReadResult Result = Success; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 4355 | while (true) { |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4356 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4357 | |
| 4358 | switch (Entry.Kind) { |
| 4359 | case llvm::BitstreamEntry::Error: |
| 4360 | case llvm::BitstreamEntry::SubBlock: |
| 4361 | return Failure; |
| 4362 | |
| 4363 | case llvm::BitstreamEntry::EndBlock: |
| 4364 | return Result; |
| 4365 | |
| 4366 | case llvm::BitstreamEntry::Record: |
| 4367 | // The interesting case. |
| 4368 | break; |
| 4369 | } |
| 4370 | |
| 4371 | // Read and process a record. |
| 4372 | Record.clear(); |
| 4373 | switch ( |
| 4374 | (UnhashedControlBlockRecordTypes)Stream.readRecord(Entry.ID, Record)) { |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 4375 | case SIGNATURE: |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4376 | if (F) |
| 4377 | std::copy(Record.begin(), Record.end(), F->Signature.data()); |
| 4378 | break; |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4379 | case DIAGNOSTIC_OPTIONS: { |
| 4380 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
| 4381 | if (Listener && ValidateDiagnosticOptions && |
| 4382 | !AllowCompatibleConfigurationMismatch && |
| 4383 | ParseDiagnosticOptions(Record, Complain, *Listener)) |
| Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 4384 | Result = OutOfDate; // Don't return early. Read the signature. |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4385 | break; |
| 4386 | } |
| 4387 | case DIAG_PRAGMA_MAPPINGS: |
| 4388 | if (!F) |
| 4389 | break; |
| 4390 | if (F->PragmaDiagMappings.empty()) |
| 4391 | F->PragmaDiagMappings.swap(Record); |
| 4392 | else |
| 4393 | F->PragmaDiagMappings.insert(F->PragmaDiagMappings.end(), |
| 4394 | Record.begin(), Record.end()); |
| 4395 | break; |
| 4396 | } |
| 4397 | } |
| 4398 | } |
| 4399 | |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4400 | /// Parse a record and blob containing module file extension metadata. |
| 4401 | static bool parseModuleFileExtensionMetadata( |
| 4402 | const SmallVectorImpl<uint64_t> &Record, |
| 4403 | StringRef Blob, |
| 4404 | ModuleFileExtensionMetadata &Metadata) { |
| 4405 | if (Record.size() < 4) return true; |
| 4406 | |
| 4407 | Metadata.MajorVersion = Record[0]; |
| 4408 | Metadata.MinorVersion = Record[1]; |
| 4409 | |
| 4410 | unsigned BlockNameLen = Record[2]; |
| 4411 | unsigned UserInfoLen = Record[3]; |
| 4412 | |
| 4413 | if (BlockNameLen + UserInfoLen > Blob.size()) return true; |
| 4414 | |
| 4415 | Metadata.BlockName = std::string(Blob.data(), Blob.data() + BlockNameLen); |
| 4416 | Metadata.UserInfo = std::string(Blob.data() + BlockNameLen, |
| 4417 | Blob.data() + BlockNameLen + UserInfoLen); |
| 4418 | return false; |
| 4419 | } |
| 4420 | |
| 4421 | ASTReader::ASTReadResult ASTReader::ReadExtensionBlock(ModuleFile &F) { |
| 4422 | BitstreamCursor &Stream = F.Stream; |
| 4423 | |
| 4424 | RecordData Record; |
| 4425 | while (true) { |
| 4426 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4427 | switch (Entry.Kind) { |
| 4428 | case llvm::BitstreamEntry::SubBlock: |
| 4429 | if (Stream.SkipBlock()) |
| 4430 | return Failure; |
| 4431 | |
| 4432 | continue; |
| 4433 | |
| 4434 | case llvm::BitstreamEntry::EndBlock: |
| 4435 | return Success; |
| 4436 | |
| 4437 | case llvm::BitstreamEntry::Error: |
| 4438 | return HadErrors; |
| 4439 | |
| 4440 | case llvm::BitstreamEntry::Record: |
| 4441 | break; |
| 4442 | } |
| 4443 | |
| 4444 | Record.clear(); |
| 4445 | StringRef Blob; |
| 4446 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
| 4447 | switch (RecCode) { |
| 4448 | case EXTENSION_METADATA: { |
| 4449 | ModuleFileExtensionMetadata Metadata; |
| 4450 | if (parseModuleFileExtensionMetadata(Record, Blob, Metadata)) |
| 4451 | return Failure; |
| 4452 | |
| 4453 | // Find a module file extension with this block name. |
| 4454 | auto Known = ModuleFileExtensions.find(Metadata.BlockName); |
| 4455 | if (Known == ModuleFileExtensions.end()) break; |
| 4456 | |
| 4457 | // Form a reader. |
| 4458 | if (auto Reader = Known->second->createExtensionReader(Metadata, *this, |
| 4459 | F, Stream)) { |
| 4460 | F.ExtensionReaders.push_back(std::move(Reader)); |
| 4461 | } |
| 4462 | |
| 4463 | break; |
| 4464 | } |
| 4465 | } |
| 4466 | } |
| 4467 | |
| 4468 | return Success; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4469 | } |
| 4470 | |
| Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4471 | void ASTReader::InitializeContext() { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4472 | assert(ContextObj && "no context to initialize"); |
| 4473 | ASTContext &Context = *ContextObj; |
| 4474 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4475 | // If there's a listener, notify them that we "read" the translation unit. |
| 4476 | if (DeserializationListener) |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4477 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4478 | Context.getTranslationUnitDecl()); |
| 4479 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4480 | // FIXME: Find a better way to deal with collisions between these |
| 4481 | // built-in types. Right now, we just ignore the problem. |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4482 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4483 | // Load the special types. |
| 4484 | if (SpecialTypes.size() >= NumSpecialTypeIDs) { |
| 4485 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| 4486 | if (!Context.CFConstantStringTypeDecl) |
| 4487 | Context.setCFConstantStringType(GetType(String)); |
| 4488 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4489 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4490 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| 4491 | QualType FileType = GetType(File); |
| 4492 | if (FileType.isNull()) { |
| 4493 | Error("FILE type is NULL"); |
| 4494 | return; |
| 4495 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4496 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4497 | if (!Context.FILEDecl) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4498 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4499 | Context.setFILEDecl(Typedef->getDecl()); |
| 4500 | else { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4501 | const TagType *Tag = FileType->getAs<TagType>(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4502 | if (!Tag) { |
| 4503 | Error("Invalid FILE type in AST file"); |
| 4504 | return; |
| 4505 | } |
| 4506 | Context.setFILEDecl(Tag->getDecl()); |
| 4507 | } |
| 4508 | } |
| 4509 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4510 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4511 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) { |
| 4512 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 4513 | if (Jmp_bufType.isNull()) { |
| 4514 | Error("jmp_buf type is NULL"); |
| 4515 | return; |
| 4516 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4517 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4518 | if (!Context.jmp_bufDecl) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4519 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4520 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 4521 | else { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4522 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4523 | if (!Tag) { |
| 4524 | Error("Invalid jmp_buf type in AST file"); |
| 4525 | return; |
| 4526 | } |
| 4527 | Context.setjmp_bufDecl(Tag->getDecl()); |
| 4528 | } |
| 4529 | } |
| 4530 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4531 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4532 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) { |
| 4533 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 4534 | if (Sigjmp_bufType.isNull()) { |
| 4535 | Error("sigjmp_buf type is NULL"); |
| 4536 | return; |
| 4537 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4538 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4539 | if (!Context.sigjmp_bufDecl) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4540 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4541 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 4542 | else { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4543 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4544 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 4545 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 4546 | } |
| 4547 | } |
| 4548 | } |
| 4549 | |
| 4550 | if (unsigned ObjCIdRedef |
| 4551 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 4552 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 4553 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 4554 | } |
| 4555 | |
| 4556 | if (unsigned ObjCClassRedef |
| 4557 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 4558 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 4559 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 4560 | } |
| 4561 | |
| 4562 | if (unsigned ObjCSelRedef |
| 4563 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 4564 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 4565 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 4566 | } |
| 4567 | |
| 4568 | if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) { |
| 4569 | QualType Ucontext_tType = GetType(Ucontext_t); |
| 4570 | if (Ucontext_tType.isNull()) { |
| 4571 | Error("ucontext_t type is NULL"); |
| 4572 | return; |
| 4573 | } |
| 4574 | |
| 4575 | if (!Context.ucontext_tDecl) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4576 | if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>()) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4577 | Context.setucontext_tDecl(Typedef->getDecl()); |
| 4578 | else { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4579 | const TagType *Tag = Ucontext_tType->getAs<TagType>(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4580 | assert(Tag && "Invalid ucontext_t type in AST file"); |
| 4581 | Context.setucontext_tDecl(Tag->getDecl()); |
| 4582 | } |
| 4583 | } |
| 4584 | } |
| 4585 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4586 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4587 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
| 4588 | |
| 4589 | // If there were any CUDA special declarations, deserialize them. |
| 4590 | if (!CUDASpecialDeclRefs.empty()) { |
| 4591 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 4592 | Context.setcudaConfigureCallDecl( |
| 4593 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 4594 | } |
| Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4595 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4596 | // 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] | 4597 | // FIXME: This does not make macro-only imports visible again. |
| Richard Smith | 56be754 | 2014-03-21 00:33:59 +0000 | [diff] [blame] | 4598 | for (auto &Import : ImportedModules) { |
| Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4599 | if (Module *Imported = getSubmodule(Import.ID)) { |
| Argyrios Kyrtzidis | 125df05 | 2013-02-01 16:36:12 +0000 | [diff] [blame] | 4600 | makeModuleVisible(Imported, Module::AllVisible, |
| Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4601 | /*ImportLoc=*/Import.ImportLoc); |
| Ben Langmuir | 6d25fdc | 2016-02-11 17:04:42 +0000 | [diff] [blame] | 4602 | if (Import.ImportLoc.isValid()) |
| 4603 | PP.makeModuleVisible(Imported, Import.ImportLoc); |
| 4604 | // FIXME: should we tell Sema to make the module visible too? |
| Richard Smith | a7e2cc6 | 2015-05-01 01:53:09 +0000 | [diff] [blame] | 4605 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4606 | } |
| 4607 | ImportedModules.clear(); |
| 4608 | } |
| 4609 | |
| 4610 | void ASTReader::finalizeForWriting() { |
| Richard Smith | de71142 | 2015-04-23 21:20:19 +0000 | [diff] [blame] | 4611 | // Nothing to do for now. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4612 | } |
| 4613 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4614 | /// Reads and return the signature record from \p PCH's control block, or |
| Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4615 | /// else returns 0. |
| 4616 | static ASTFileSignature readASTFileSignature(StringRef PCH) { |
| 4617 | BitstreamCursor Stream(PCH); |
| Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4618 | if (!startsWithASTFileMagic(Stream)) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4619 | return ASTFileSignature(); |
| Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4620 | |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4621 | // Scan for the UNHASHED_CONTROL_BLOCK_ID block. |
| 4622 | if (SkipCursorToBlock(Stream, UNHASHED_CONTROL_BLOCK_ID)) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4623 | return ASTFileSignature(); |
| Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4624 | |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4625 | // Scan for SIGNATURE inside the diagnostic options block. |
| Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4626 | ASTReader::RecordData Record; |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4627 | while (true) { |
| Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4628 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
| Simon Pilgrim | 0b33f11 | 2016-11-16 16:11:08 +0000 | [diff] [blame] | 4629 | if (Entry.Kind != llvm::BitstreamEntry::Record) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4630 | return ASTFileSignature(); |
| Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4631 | |
| 4632 | Record.clear(); |
| 4633 | StringRef Blob; |
| 4634 | if (SIGNATURE == Stream.readRecord(Entry.ID, Record, &Blob)) |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4635 | return {{{(uint32_t)Record[0], (uint32_t)Record[1], (uint32_t)Record[2], |
| 4636 | (uint32_t)Record[3], (uint32_t)Record[4]}}}; |
| Ben Langmuir | 487ea14 | 2014-10-23 18:05:36 +0000 | [diff] [blame] | 4637 | } |
| 4638 | } |
| 4639 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4640 | /// Retrieve the name of the original source file name |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4641 | /// directly from the AST file, without actually loading the AST |
| 4642 | /// file. |
| Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame] | 4643 | std::string ASTReader::getOriginalSourceFile( |
| 4644 | const std::string &ASTFileName, FileManager &FileMgr, |
| Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 4645 | const PCHContainerReader &PCHContainerRdr, DiagnosticsEngine &Diags) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4646 | // Open the AST file. |
| Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 4647 | auto Buffer = FileMgr.getBufferForFile(ASTFileName); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4648 | if (!Buffer) { |
| Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 4649 | Diags.Report(diag::err_fe_unable_to_read_pch_file) |
| 4650 | << ASTFileName << Buffer.getError().message(); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4651 | return std::string(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4652 | } |
| 4653 | |
| 4654 | // Initialize the stream |
| Peter Collingbourne | 77c89b6 | 2016-11-08 04:17:11 +0000 | [diff] [blame] | 4655 | BitstreamCursor Stream(PCHContainerRdr.ExtractPCH(**Buffer)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4656 | |
| 4657 | // Sniff for the signature. |
| Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4658 | if (!startsWithASTFileMagic(Stream)) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4659 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4660 | return std::string(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4661 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4662 | |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4663 | // Scan for the CONTROL_BLOCK_ID block. |
| Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4664 | if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) { |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4665 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4666 | return std::string(); |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4667 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4668 | |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4669 | // Scan for ORIGINAL_FILE inside the control block. |
| 4670 | RecordData Record; |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4671 | while (true) { |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4672 | llvm::BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4673 | if (Entry.Kind == llvm::BitstreamEntry::EndBlock) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4674 | return std::string(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4675 | |
| Chris Lattner | e7b154b | 2013-01-19 21:39:22 +0000 | [diff] [blame] | 4676 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| 4677 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4678 | return std::string(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4679 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4680 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4681 | Record.clear(); |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4682 | StringRef Blob; |
| 4683 | if (Stream.readRecord(Entry.ID, Record, &Blob) == ORIGINAL_FILE) |
| 4684 | return Blob.str(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4685 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4686 | } |
| 4687 | |
| 4688 | namespace { |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4689 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4690 | class SimplePCHValidator : public ASTReaderListener { |
| 4691 | const LangOptions &ExistingLangOpts; |
| 4692 | const TargetOptions &ExistingTargetOpts; |
| 4693 | const PreprocessorOptions &ExistingPPOpts; |
| Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4694 | std::string ExistingModuleCachePath; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4695 | FileManager &FileMgr; |
| Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4696 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4697 | public: |
| 4698 | SimplePCHValidator(const LangOptions &ExistingLangOpts, |
| 4699 | const TargetOptions &ExistingTargetOpts, |
| 4700 | const PreprocessorOptions &ExistingPPOpts, |
| Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4701 | StringRef ExistingModuleCachePath, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4702 | FileManager &FileMgr) |
| 4703 | : ExistingLangOpts(ExistingLangOpts), |
| 4704 | ExistingTargetOpts(ExistingTargetOpts), |
| 4705 | ExistingPPOpts(ExistingPPOpts), |
| Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4706 | ExistingModuleCachePath(ExistingModuleCachePath), |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 4707 | FileMgr(FileMgr) {} |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4708 | |
| Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 4709 | bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, |
| 4710 | bool AllowCompatibleDifferences) override { |
| 4711 | return checkLanguageOptions(ExistingLangOpts, LangOpts, nullptr, |
| 4712 | AllowCompatibleDifferences); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4713 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4714 | |
| Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 4715 | bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, |
| 4716 | bool AllowCompatibleDifferences) override { |
| 4717 | return checkTargetOptions(ExistingTargetOpts, TargetOpts, nullptr, |
| 4718 | AllowCompatibleDifferences); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4719 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4720 | |
| Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4721 | bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 4722 | StringRef SpecificModuleCachePath, |
| 4723 | bool Complain) override { |
| 4724 | return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 4725 | ExistingModuleCachePath, |
| 4726 | nullptr, ExistingLangOpts); |
| 4727 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4728 | |
| Craig Topper | 3e89dfe | 2014-03-13 02:13:41 +0000 | [diff] [blame] | 4729 | bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 4730 | bool Complain, |
| 4731 | std::string &SuggestedPredefines) override { |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4732 | return checkPreprocessorOptions(ExistingPPOpts, PPOpts, nullptr, FileMgr, |
| Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 4733 | SuggestedPredefines, ExistingLangOpts); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4734 | } |
| 4735 | }; |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 4736 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 4737 | } // namespace |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4738 | |
| Adrian Prantl | bb165fb | 2015-06-20 18:53:08 +0000 | [diff] [blame] | 4739 | bool ASTReader::readASTFileControlBlock( |
| 4740 | StringRef Filename, FileManager &FileMgr, |
| Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 4741 | const PCHContainerReader &PCHContainerRdr, |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4742 | bool FindModuleFileExtensions, |
| Manman Ren | 47a4445 | 2016-07-26 17:12:17 +0000 | [diff] [blame] | 4743 | ASTReaderListener &Listener, bool ValidateDiagnosticOptions) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4744 | // Open the AST file. |
| Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 4745 | // FIXME: This allows use of the VFS; we do not allow use of the |
| 4746 | // VFS when actually loading a module. |
| Benjamin Kramer | a885796 | 2014-10-26 22:44:13 +0000 | [diff] [blame] | 4747 | auto Buffer = FileMgr.getBufferForFile(Filename); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4748 | if (!Buffer) { |
| 4749 | return true; |
| 4750 | } |
| 4751 | |
| 4752 | // Initialize the stream |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4753 | StringRef Bytes = PCHContainerRdr.ExtractPCH(**Buffer); |
| 4754 | BitstreamCursor Stream(Bytes); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4755 | |
| 4756 | // Sniff for the signature. |
| Ben Langmuir | 70a1b81 | 2015-03-24 04:43:52 +0000 | [diff] [blame] | 4757 | if (!startsWithASTFileMagic(Stream)) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4758 | return true; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4759 | |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4760 | // Scan for the CONTROL_BLOCK_ID block. |
| Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4761 | if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4762 | return true; |
| Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4763 | |
| 4764 | bool NeedsInputFiles = Listener.needsInputFileVisitation(); |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 4765 | bool NeedsSystemInputFiles = Listener.needsSystemInputFileVisitation(); |
| Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4766 | bool NeedsImports = Listener.needsImportVisitation(); |
| Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4767 | BitstreamCursor InputFilesCursor; |
| Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4768 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4769 | RecordData Record; |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4770 | std::string ModuleDir; |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4771 | bool DoneWithControlBlock = false; |
| 4772 | while (!DoneWithControlBlock) { |
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4773 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4774 | |
| 4775 | switch (Entry.Kind) { |
| 4776 | case llvm::BitstreamEntry::SubBlock: { |
| 4777 | switch (Entry.ID) { |
| 4778 | case OPTIONS_BLOCK_ID: { |
| 4779 | std::string IgnoredSuggestedPredefines; |
| 4780 | if (ReadOptionsBlock(Stream, ARR_ConfigurationMismatch | ARR_OutOfDate, |
| 4781 | /*AllowCompatibleConfigurationMismatch*/ false, |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4782 | Listener, IgnoredSuggestedPredefines) != Success) |
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4783 | return true; |
| 4784 | break; |
| 4785 | } |
| 4786 | |
| 4787 | case INPUT_FILES_BLOCK_ID: |
| 4788 | InputFilesCursor = Stream; |
| 4789 | if (Stream.SkipBlock() || |
| 4790 | (NeedsInputFiles && |
| 4791 | ReadBlockAbbrevs(InputFilesCursor, INPUT_FILES_BLOCK_ID))) |
| 4792 | return true; |
| 4793 | break; |
| 4794 | |
| 4795 | default: |
| 4796 | if (Stream.SkipBlock()) |
| 4797 | return true; |
| 4798 | break; |
| 4799 | } |
| 4800 | |
| 4801 | continue; |
| 4802 | } |
| 4803 | |
| 4804 | case llvm::BitstreamEntry::EndBlock: |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4805 | DoneWithControlBlock = true; |
| 4806 | break; |
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4807 | |
| 4808 | case llvm::BitstreamEntry::Error: |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4809 | return true; |
| Richard Smith | 0516b18 | 2015-09-08 19:40:14 +0000 | [diff] [blame] | 4810 | |
| 4811 | case llvm::BitstreamEntry::Record: |
| 4812 | break; |
| 4813 | } |
| 4814 | |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4815 | if (DoneWithControlBlock) break; |
| 4816 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4817 | Record.clear(); |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4818 | StringRef Blob; |
| 4819 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4820 | switch ((ControlRecordTypes)RecCode) { |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 4821 | case METADATA: |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4822 | if (Record[0] != VERSION_MAJOR) |
| 4823 | return true; |
| Douglas Gregor | bf7fc9c | 2013-03-27 16:47:18 +0000 | [diff] [blame] | 4824 | if (Listener.ReadFullVersionInformation(Blob)) |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4825 | return true; |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4826 | break; |
| Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 4827 | case MODULE_NAME: |
| 4828 | Listener.ReadModuleName(Blob); |
| 4829 | break; |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4830 | case MODULE_DIRECTORY: |
| 4831 | ModuleDir = Blob; |
| 4832 | break; |
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 4833 | case MODULE_MAP_FILE: { |
| 4834 | unsigned Idx = 0; |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4835 | auto Path = ReadString(Record, Idx); |
| 4836 | ResolveImportedPath(Path, ModuleDir); |
| 4837 | Listener.ReadModuleMapFile(Path); |
| Ben Langmuir | 4f5212a | 2014-04-14 22:12:44 +0000 | [diff] [blame] | 4838 | break; |
| Ben Langmuir | 4b8a9e9 | 2014-08-12 16:42:33 +0000 | [diff] [blame] | 4839 | } |
| Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4840 | case INPUT_FILE_OFFSETS: { |
| 4841 | if (!NeedsInputFiles) |
| 4842 | break; |
| 4843 | |
| 4844 | unsigned NumInputFiles = Record[0]; |
| 4845 | unsigned NumUserFiles = Record[1]; |
| Raphael Isemann | eb13d3d | 2018-05-23 09:02:40 +0000 | [diff] [blame] | 4846 | const llvm::support::unaligned_uint64_t *InputFileOffs = |
| 4847 | (const llvm::support::unaligned_uint64_t *)Blob.data(); |
| Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4848 | for (unsigned I = 0; I != NumInputFiles; ++I) { |
| 4849 | // Go find this input file. |
| 4850 | bool isSystemFile = I >= NumUserFiles; |
| Ben Langmuir | cb69b57 | 2014-03-07 06:40:32 +0000 | [diff] [blame] | 4851 | |
| 4852 | if (isSystemFile && !NeedsSystemInputFiles) |
| 4853 | break; // the rest are system input files |
| 4854 | |
| Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4855 | BitstreamCursor &Cursor = InputFilesCursor; |
| 4856 | SavedStreamPosition SavedPosition(Cursor); |
| 4857 | Cursor.JumpToBit(InputFileOffs[I]); |
| 4858 | |
| 4859 | unsigned Code = Cursor.ReadCode(); |
| 4860 | RecordData Record; |
| 4861 | StringRef Blob; |
| 4862 | bool shouldContinue = false; |
| 4863 | switch ((InputFileRecordTypes)Cursor.readRecord(Code, Record, &Blob)) { |
| 4864 | case INPUT_FILE: |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 4865 | bool Overridden = static_cast<bool>(Record[3]); |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4866 | std::string Filename = Blob; |
| 4867 | ResolveImportedPath(Filename, ModuleDir); |
| Richard Smith | 216a3bd | 2015-08-13 17:57:10 +0000 | [diff] [blame] | 4868 | shouldContinue = Listener.visitInputFile( |
| 4869 | Filename, isSystemFile, Overridden, /*IsExplicitModule*/false); |
| Argyrios Kyrtzidis | c4cd2c4 | 2013-05-06 19:23:40 +0000 | [diff] [blame] | 4870 | break; |
| 4871 | } |
| 4872 | if (!shouldContinue) |
| 4873 | break; |
| 4874 | } |
| 4875 | break; |
| 4876 | } |
| 4877 | |
| Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4878 | case IMPORTS: { |
| 4879 | if (!NeedsImports) |
| 4880 | break; |
| 4881 | |
| 4882 | unsigned Idx = 0, N = Record.size(); |
| 4883 | while (Idx < N) { |
| 4884 | // Read information about the AST file. |
| Bruno Cardoso Lopes | 6fc8a56 | 2018-09-11 05:17:13 +0000 | [diff] [blame] | 4885 | Idx += 1+1+1+1+5; // Kind, ImportLoc, Size, ModTime, Signature |
| 4886 | std::string ModuleName = ReadString(Record, Idx); |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 4887 | std::string Filename = ReadString(Record, Idx); |
| 4888 | ResolveImportedPath(Filename, ModuleDir); |
| Bruno Cardoso Lopes | 6fc8a56 | 2018-09-11 05:17:13 +0000 | [diff] [blame] | 4889 | Listener.visitImport(ModuleName, Filename); |
| Richard Smith | d4b230b | 2014-10-27 23:01:16 +0000 | [diff] [blame] | 4890 | } |
| 4891 | break; |
| 4892 | } |
| 4893 | |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4894 | default: |
| 4895 | // No other validation to perform. |
| 4896 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4897 | } |
| 4898 | } |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4899 | |
| 4900 | // Look for module file extension blocks, if requested. |
| 4901 | if (FindModuleFileExtensions) { |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4902 | BitstreamCursor SavedStream = Stream; |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4903 | while (!SkipCursorToBlock(Stream, EXTENSION_BLOCK_ID)) { |
| 4904 | bool DoneWithExtensionBlock = false; |
| 4905 | while (!DoneWithExtensionBlock) { |
| 4906 | llvm::BitstreamEntry Entry = Stream.advance(); |
| 4907 | |
| 4908 | switch (Entry.Kind) { |
| 4909 | case llvm::BitstreamEntry::SubBlock: |
| 4910 | if (Stream.SkipBlock()) |
| 4911 | return true; |
| 4912 | |
| 4913 | continue; |
| 4914 | |
| 4915 | case llvm::BitstreamEntry::EndBlock: |
| 4916 | DoneWithExtensionBlock = true; |
| 4917 | continue; |
| 4918 | |
| 4919 | case llvm::BitstreamEntry::Error: |
| 4920 | return true; |
| 4921 | |
| 4922 | case llvm::BitstreamEntry::Record: |
| 4923 | break; |
| 4924 | } |
| 4925 | |
| 4926 | Record.clear(); |
| 4927 | StringRef Blob; |
| 4928 | unsigned RecCode = Stream.readRecord(Entry.ID, Record, &Blob); |
| 4929 | switch (RecCode) { |
| 4930 | case EXTENSION_METADATA: { |
| 4931 | ModuleFileExtensionMetadata Metadata; |
| 4932 | if (parseModuleFileExtensionMetadata(Record, Blob, Metadata)) |
| 4933 | return true; |
| 4934 | |
| 4935 | Listener.readModuleFileExtension(Metadata); |
| 4936 | break; |
| 4937 | } |
| 4938 | } |
| 4939 | } |
| 4940 | } |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4941 | Stream = SavedStream; |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4942 | } |
| 4943 | |
| Duncan P. N. Exon Smith | 60fa288 | 2017-03-13 18:45:08 +0000 | [diff] [blame] | 4944 | // Scan for the UNHASHED_CONTROL_BLOCK_ID block. |
| 4945 | if (readUnhashedControlBlockImpl( |
| 4946 | nullptr, Bytes, ARR_ConfigurationMismatch | ARR_OutOfDate, |
| 4947 | /*AllowCompatibleConfigurationMismatch*/ false, &Listener, |
| 4948 | ValidateDiagnosticOptions) != Success) |
| 4949 | return true; |
| 4950 | |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4951 | return false; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4952 | } |
| 4953 | |
| Benjamin Kramer | f6021ec | 2017-03-21 21:35:04 +0000 | [diff] [blame] | 4954 | bool ASTReader::isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, |
| 4955 | const PCHContainerReader &PCHContainerRdr, |
| 4956 | const LangOptions &LangOpts, |
| 4957 | const TargetOptions &TargetOpts, |
| 4958 | const PreprocessorOptions &PPOpts, |
| 4959 | StringRef ExistingModuleCachePath) { |
| Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 4960 | SimplePCHValidator validator(LangOpts, TargetOpts, PPOpts, |
| 4961 | ExistingModuleCachePath, FileMgr); |
| Adrian Prantl | fb2398d | 2015-07-17 01:19:54 +0000 | [diff] [blame] | 4962 | return !readASTFileControlBlock(Filename, FileMgr, PCHContainerRdr, |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 4963 | /*FindModuleFileExtensions=*/false, |
| Manman Ren | 47a4445 | 2016-07-26 17:12:17 +0000 | [diff] [blame] | 4964 | validator, |
| 4965 | /*ValidateDiagnosticOptions=*/true); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4966 | } |
| 4967 | |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4968 | ASTReader::ASTReadResult |
| 4969 | ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4970 | // Enter the submodule block. |
| 4971 | if (F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) { |
| 4972 | Error("malformed submodule block record in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4973 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4974 | } |
| 4975 | |
| 4976 | ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap(); |
| 4977 | bool First = true; |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 4978 | Module *CurrentModule = nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4979 | RecordData Record; |
| 4980 | while (true) { |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4981 | llvm::BitstreamEntry Entry = F.Stream.advanceSkippingSubblocks(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4982 | |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4983 | switch (Entry.Kind) { |
| 4984 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 4985 | case llvm::BitstreamEntry::Error: |
| 4986 | Error("malformed block record in AST file"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4987 | return Failure; |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4988 | case llvm::BitstreamEntry::EndBlock: |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 4989 | return Success; |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4990 | case llvm::BitstreamEntry::Record: |
| 4991 | // The interesting case. |
| 4992 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4993 | } |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 4994 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4995 | // Read a record. |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 4996 | StringRef Blob; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 4997 | Record.clear(); |
| Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 4998 | auto Kind = F.Stream.readRecord(Entry.ID, Record, &Blob); |
| 4999 | |
| 5000 | if ((Kind == SUBMODULE_METADATA) != First) { |
| 5001 | Error("submodule metadata record should be at beginning of block"); |
| 5002 | return Failure; |
| 5003 | } |
| 5004 | First = false; |
| 5005 | |
| 5006 | // Submodule information is only valid if we have a current module. |
| 5007 | // FIXME: Should we error on these cases? |
| 5008 | if (!CurrentModule && Kind != SUBMODULE_METADATA && |
| 5009 | Kind != SUBMODULE_DEFINITION) |
| 5010 | continue; |
| 5011 | |
| 5012 | switch (Kind) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5013 | default: // Default behavior: ignore. |
| 5014 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5015 | |
| Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 5016 | case SUBMODULE_DEFINITION: { |
| Jordan Rose | 90b0a1f | 2018-04-20 17:16:04 +0000 | [diff] [blame] | 5017 | if (Record.size() < 12) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5018 | Error("malformed module definition"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 5019 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5020 | } |
| Richard Smith | 03478d9 | 2014-10-23 22:12:14 +0000 | [diff] [blame] | 5021 | |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5022 | StringRef Name = Blob; |
| Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 5023 | unsigned Idx = 0; |
| 5024 | SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[Idx++]); |
| 5025 | SubmoduleID Parent = getGlobalSubmoduleID(F, Record[Idx++]); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5026 | Module::ModuleKind Kind = (Module::ModuleKind)Record[Idx++]; |
| Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 5027 | bool IsFramework = Record[Idx++]; |
| 5028 | bool IsExplicit = Record[Idx++]; |
| 5029 | bool IsSystem = Record[Idx++]; |
| 5030 | bool IsExternC = Record[Idx++]; |
| 5031 | bool InferSubmodules = Record[Idx++]; |
| 5032 | bool InferExplicitSubmodules = Record[Idx++]; |
| 5033 | bool InferExportWildcard = Record[Idx++]; |
| 5034 | bool ConfigMacrosExhaustive = Record[Idx++]; |
| Jordan Rose | 90b0a1f | 2018-04-20 17:16:04 +0000 | [diff] [blame] | 5035 | bool ModuleMapIsPrivate = Record[Idx++]; |
| Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 5036 | |
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 5037 | Module *ParentModule = nullptr; |
| Ben Langmuir | 9d6448b | 2014-08-09 00:57:23 +0000 | [diff] [blame] | 5038 | if (Parent) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5039 | ParentModule = getSubmodule(Parent); |
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 5040 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5041 | // Retrieve this (sub)module from the module map, creating it if |
| 5042 | // necessary. |
| David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 5043 | CurrentModule = |
| 5044 | ModMap.findOrCreateModule(Name, ParentModule, IsFramework, IsExplicit) |
| 5045 | .first; |
| Ben Langmuir | 9d6448b | 2014-08-09 00:57:23 +0000 | [diff] [blame] | 5046 | |
| 5047 | // FIXME: set the definition loc for CurrentModule, or call |
| 5048 | // ModMap.setInferredModuleAllowedBy() |
| 5049 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5050 | SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS; |
| 5051 | if (GlobalIndex >= SubmodulesLoaded.size() || |
| 5052 | SubmodulesLoaded[GlobalIndex]) { |
| 5053 | Error("too many submodules"); |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 5054 | return Failure; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5055 | } |
| Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 5056 | |
| Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 5057 | if (!ParentModule) { |
| 5058 | if (const FileEntry *CurFile = CurrentModule->getASTFile()) { |
| Yuka Takahashi | d8baec2 | 2018-08-01 09:50:02 +0000 | [diff] [blame] | 5059 | // Don't emit module relocation error if we have -fno-validate-pch |
| 5060 | if (!PP.getPreprocessorOpts().DisablePCHValidation && |
| 5061 | CurFile != F.File) { |
| Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 5062 | if (!Diags.isDiagnosticInFlight()) { |
| 5063 | Diag(diag::err_module_file_conflict) |
| 5064 | << CurrentModule->getTopLevelModuleName() |
| 5065 | << CurFile->getName() |
| 5066 | << F.File->getName(); |
| 5067 | } |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 5068 | return Failure; |
| Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 5069 | } |
| Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 5070 | } |
| Douglas Gregor | 7029ce1 | 2013-03-19 00:28:20 +0000 | [diff] [blame] | 5071 | |
| 5072 | CurrentModule->setASTFile(F.File); |
| Richard Smith | ab75597 | 2017-06-05 18:10:11 +0000 | [diff] [blame] | 5073 | CurrentModule->PresumedModuleMapFile = F.ModuleMapPath; |
| Douglas Gregor | 8a114ab | 2013-02-06 22:40:31 +0000 | [diff] [blame] | 5074 | } |
| Ben Langmuir | beee15e | 2014-04-14 18:00:01 +0000 | [diff] [blame] | 5075 | |
| Richard Smith | dd8b533 | 2017-09-04 05:37:53 +0000 | [diff] [blame] | 5076 | CurrentModule->Kind = Kind; |
| Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 5077 | CurrentModule->Signature = F.Signature; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5078 | CurrentModule->IsFromModuleFile = true; |
| 5079 | CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem; |
| Richard Smith | 9bca298 | 2014-03-08 00:03:56 +0000 | [diff] [blame] | 5080 | CurrentModule->IsExternC = IsExternC; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5081 | CurrentModule->InferSubmodules = InferSubmodules; |
| 5082 | CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules; |
| 5083 | CurrentModule->InferExportWildcard = InferExportWildcard; |
| Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 5084 | CurrentModule->ConfigMacrosExhaustive = ConfigMacrosExhaustive; |
| Jordan Rose | 90b0a1f | 2018-04-20 17:16:04 +0000 | [diff] [blame] | 5085 | CurrentModule->ModuleMapIsPrivate = ModuleMapIsPrivate; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5086 | if (DeserializationListener) |
| 5087 | DeserializationListener->ModuleRead(GlobalID, CurrentModule); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5088 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5089 | SubmodulesLoaded[GlobalIndex] = CurrentModule; |
| Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5090 | |
| Richard Smith | 8a3e39a | 2016-03-28 21:31:09 +0000 | [diff] [blame] | 5091 | // 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] | 5092 | CurrentModule->LinkLibraries.clear(); |
| Douglas Gregor | 8d93242 | 2013-03-20 03:59:18 +0000 | [diff] [blame] | 5093 | CurrentModule->ConfigMacros.clear(); |
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5094 | CurrentModule->UnresolvedConflicts.clear(); |
| 5095 | CurrentModule->Conflicts.clear(); |
| Richard Smith | 8a3e39a | 2016-03-28 21:31:09 +0000 | [diff] [blame] | 5096 | |
| 5097 | // The module is available unless it's missing a requirement; relevant |
| 5098 | // requirements will be (re-)added by SUBMODULE_REQUIRES records. |
| 5099 | // Missing headers that were present when the module was built do not |
| 5100 | // make it unavailable -- if we got this far, this must be an explicitly |
| 5101 | // imported module file. |
| 5102 | CurrentModule->Requirements.clear(); |
| 5103 | CurrentModule->MissingHeaders.clear(); |
| 5104 | CurrentModule->IsMissingRequirement = |
| 5105 | ParentModule && ParentModule->IsMissingRequirement; |
| 5106 | CurrentModule->IsAvailable = !CurrentModule->IsMissingRequirement; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5107 | break; |
| 5108 | } |
| Richard Smith | 8a3e39a | 2016-03-28 21:31:09 +0000 | [diff] [blame] | 5109 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5110 | case SUBMODULE_UMBRELLA_HEADER: { |
| Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 5111 | std::string Filename = Blob; |
| 5112 | ResolveImportedPath(F, Filename); |
| 5113 | if (auto *Umbrella = PP.getFileManager().getFile(Filename)) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5114 | if (!CurrentModule->getUmbrellaHeader()) |
| Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 5115 | ModMap.setUmbrellaHeader(CurrentModule, Umbrella, Blob); |
| 5116 | else if (CurrentModule->getUmbrellaHeader().Entry != Umbrella) { |
| Bruno Cardoso Lopes | 573b13f | 2017-03-22 00:11:21 +0000 | [diff] [blame] | 5117 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 5118 | Error("mismatched umbrella headers in submodule"); |
| 5119 | return OutOfDate; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5120 | } |
| 5121 | } |
| 5122 | break; |
| 5123 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5124 | |
| Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 5125 | case SUBMODULE_HEADER: |
| 5126 | case SUBMODULE_EXCLUDED_HEADER: |
| 5127 | case SUBMODULE_PRIVATE_HEADER: |
| 5128 | // We lazily associate headers with their modules via the HeaderInfo table. |
| Argyrios Kyrtzidis | b146baa | 2013-03-13 21:13:51 +0000 | [diff] [blame] | 5129 | // FIXME: Re-evaluate this section; maybe only store InputFile IDs instead |
| 5130 | // of complete filenames or remove it entirely. |
| Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 5131 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5132 | |
| Richard Smith | 202210b | 2014-10-24 20:23:01 +0000 | [diff] [blame] | 5133 | case SUBMODULE_TEXTUAL_HEADER: |
| 5134 | case SUBMODULE_PRIVATE_TEXTUAL_HEADER: |
| 5135 | // FIXME: Textual headers are not marked in the HeaderInfo table. Load |
| 5136 | // them here. |
| 5137 | break; |
| Lawrence Crowl | b53e548 | 2013-06-20 21:14:14 +0000 | [diff] [blame] | 5138 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5139 | case SUBMODULE_TOPHEADER: |
| Argyrios Kyrtzidis | 3c5305c | 2013-03-13 21:13:43 +0000 | [diff] [blame] | 5140 | CurrentModule->addTopHeaderFilename(Blob); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5141 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5142 | |
| 5143 | case SUBMODULE_UMBRELLA_DIR: { |
| Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 5144 | std::string Dirname = Blob; |
| 5145 | ResolveImportedPath(F, Dirname); |
| 5146 | if (auto *Umbrella = PP.getFileManager().getDirectory(Dirname)) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5147 | if (!CurrentModule->getUmbrellaDir()) |
| Richard Smith | 2b63d15 | 2015-05-16 02:28:53 +0000 | [diff] [blame] | 5148 | ModMap.setUmbrellaDir(CurrentModule, Umbrella, Blob); |
| 5149 | else if (CurrentModule->getUmbrellaDir().Entry != Umbrella) { |
| Ben Langmuir | 2c9af44 | 2014-04-10 17:57:43 +0000 | [diff] [blame] | 5150 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 5151 | Error("mismatched umbrella directories in submodule"); |
| 5152 | return OutOfDate; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5153 | } |
| 5154 | } |
| 5155 | break; |
| 5156 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5157 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5158 | case SUBMODULE_METADATA: { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5159 | F.BaseSubmoduleID = getTotalNumSubmodules(); |
| 5160 | F.LocalNumSubmodules = Record[0]; |
| 5161 | unsigned LocalBaseSubmoduleID = Record[1]; |
| 5162 | if (F.LocalNumSubmodules > 0) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5163 | // Introduce the global -> local mapping for submodules within this |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5164 | // module. |
| 5165 | GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F)); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5166 | |
| 5167 | // Introduce the local -> global mapping for submodules within this |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5168 | // module. |
| 5169 | F.SubmoduleRemap.insertOrReplace( |
| 5170 | std::make_pair(LocalBaseSubmoduleID, |
| 5171 | F.BaseSubmoduleID - LocalBaseSubmoduleID)); |
| Ben Langmuir | fe971d9 | 2014-08-16 04:54:18 +0000 | [diff] [blame] | 5172 | |
| Ben Langmuir | 52ca678 | 2014-10-20 16:27:32 +0000 | [diff] [blame] | 5173 | SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules); |
| 5174 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5175 | break; |
| 5176 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5177 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5178 | case SUBMODULE_IMPORTS: |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5179 | for (unsigned Idx = 0; Idx != Record.size(); ++Idx) { |
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5180 | UnresolvedModuleRef Unresolved; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5181 | Unresolved.File = &F; |
| 5182 | Unresolved.Mod = CurrentModule; |
| 5183 | Unresolved.ID = Record[Idx]; |
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5184 | Unresolved.Kind = UnresolvedModuleRef::Import; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5185 | Unresolved.IsWildcard = false; |
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5186 | UnresolvedModuleRefs.push_back(Unresolved); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5187 | } |
| 5188 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5189 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5190 | case SUBMODULE_EXPORTS: |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5191 | for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) { |
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5192 | UnresolvedModuleRef Unresolved; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5193 | Unresolved.File = &F; |
| 5194 | Unresolved.Mod = CurrentModule; |
| 5195 | Unresolved.ID = Record[Idx]; |
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5196 | Unresolved.Kind = UnresolvedModuleRef::Export; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5197 | Unresolved.IsWildcard = Record[Idx + 1]; |
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5198 | UnresolvedModuleRefs.push_back(Unresolved); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5199 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5200 | |
| 5201 | // 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] | 5202 | // the parsed, unresolved exports around. |
| 5203 | CurrentModule->UnresolvedExports.clear(); |
| 5204 | break; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5205 | |
| 5206 | case SUBMODULE_REQUIRES: |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5207 | CurrentModule->addRequirement(Blob, Record[0], PP.getLangOpts(), |
| 5208 | PP.getTargetInfo()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5209 | break; |
| Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5210 | |
| 5211 | case SUBMODULE_LINK_LIBRARY: |
| Bruno Cardoso Lopes | a3b5f71 | 2018-04-16 19:42:32 +0000 | [diff] [blame] | 5212 | ModMap.resolveLinkAsDependencies(CurrentModule); |
| Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5213 | CurrentModule->LinkLibraries.push_back( |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5214 | Module::LinkLibrary(Blob, Record[0])); |
| Douglas Gregor | 6ddfca9 | 2013-01-14 17:21:00 +0000 | [diff] [blame] | 5215 | break; |
| Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 5216 | |
| 5217 | case SUBMODULE_CONFIG_MACRO: |
| Douglas Gregor | 35b13ec | 2013-03-20 00:22:05 +0000 | [diff] [blame] | 5218 | CurrentModule->ConfigMacros.push_back(Blob.str()); |
| 5219 | break; |
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5220 | |
| 5221 | case SUBMODULE_CONFLICT: { |
| Douglas Gregor | fb91265 | 2013-03-20 21:10:35 +0000 | [diff] [blame] | 5222 | UnresolvedModuleRef Unresolved; |
| 5223 | Unresolved.File = &F; |
| 5224 | Unresolved.Mod = CurrentModule; |
| 5225 | Unresolved.ID = Record[0]; |
| 5226 | Unresolved.Kind = UnresolvedModuleRef::Conflict; |
| 5227 | Unresolved.IsWildcard = false; |
| 5228 | Unresolved.String = Blob; |
| 5229 | UnresolvedModuleRefs.push_back(Unresolved); |
| 5230 | break; |
| 5231 | } |
| Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 5232 | |
| Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame] | 5233 | case SUBMODULE_INITIALIZERS: { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5234 | if (!ContextObj) |
| 5235 | break; |
| Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 5236 | SmallVector<uint32_t, 16> Inits; |
| 5237 | for (auto &ID : Record) |
| 5238 | Inits.push_back(getGlobalDeclID(F, ID)); |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5239 | ContextObj->addLazyModuleInitializers(CurrentModule, Inits); |
| Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 5240 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5241 | } |
| Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame] | 5242 | |
| 5243 | case SUBMODULE_EXPORT_AS: |
| 5244 | CurrentModule->ExportAsModule = Blob.str(); |
| Bruno Cardoso Lopes | a3b5f71 | 2018-04-16 19:42:32 +0000 | [diff] [blame] | 5245 | ModMap.addLinkAsDependency(CurrentModule); |
| Douglas Gregor | f0b11de | 2017-09-14 23:38:44 +0000 | [diff] [blame] | 5246 | break; |
| 5247 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5248 | } |
| 5249 | } |
| 5250 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5251 | /// Parse the record that corresponds to a LangOptions data |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5252 | /// structure. |
| 5253 | /// |
| 5254 | /// This routine parses the language options from the AST file and then gives |
| 5255 | /// them to the AST listener if one is set. |
| 5256 | /// |
| 5257 | /// \returns true if the listener deems the file unacceptable, false otherwise. |
| 5258 | bool ASTReader::ParseLanguageOptions(const RecordData &Record, |
| 5259 | bool Complain, |
| Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 5260 | ASTReaderListener &Listener, |
| 5261 | bool AllowCompatibleDifferences) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5262 | LangOptions LangOpts; |
| 5263 | unsigned Idx = 0; |
| 5264 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 5265 | LangOpts.Name = Record[Idx++]; |
| 5266 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 5267 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 5268 | #include "clang/Basic/LangOptions.def" |
| Alexey Samsonov | edf99a9 | 2014-11-07 22:29:38 +0000 | [diff] [blame] | 5269 | #define SANITIZER(NAME, ID) \ |
| 5270 | LangOpts.Sanitize.set(SanitizerKind::ID, Record[Idx++]); |
| Will Dietz | f54319c | 2013-01-18 11:30:38 +0000 | [diff] [blame] | 5271 | #include "clang/Basic/Sanitizers.def" |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5272 | |
| Ben Langmuir | cd98cb7 | 2015-06-23 18:20:18 +0000 | [diff] [blame] | 5273 | for (unsigned N = Record[Idx++]; N; --N) |
| 5274 | LangOpts.ModuleFeatures.push_back(ReadString(Record, Idx)); |
| 5275 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5276 | ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5277 | VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx); |
| 5278 | LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion); |
| Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 5279 | |
| Ben Langmuir | d4a667a | 2015-06-23 18:20:23 +0000 | [diff] [blame] | 5280 | LangOpts.CurrentModule = ReadString(Record, Idx); |
| Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 5281 | |
| 5282 | // Comment options. |
| 5283 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5284 | LangOpts.CommentOpts.BlockCommandNames.push_back( |
| 5285 | ReadString(Record, Idx)); |
| 5286 | } |
| Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 5287 | LangOpts.CommentOpts.ParseAllComments = Record[Idx++]; |
| Dmitri Gribenko | acf2e78 | 2013-02-22 14:21:27 +0000 | [diff] [blame] | 5288 | |
| Samuel Antao | ee8fb30 | 2016-01-06 13:42:12 +0000 | [diff] [blame] | 5289 | // OpenMP offloading options. |
| 5290 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5291 | LangOpts.OMPTargetTriples.push_back(llvm::Triple(ReadString(Record, Idx))); |
| 5292 | } |
| 5293 | |
| 5294 | LangOpts.OMPHostIRFile = ReadString(Record, Idx); |
| 5295 | |
| Richard Smith | 1e2cf0d | 2014-10-31 02:28:58 +0000 | [diff] [blame] | 5296 | return Listener.ReadLanguageOptions(LangOpts, Complain, |
| 5297 | AllowCompatibleDifferences); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5298 | } |
| 5299 | |
| Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 5300 | bool ASTReader::ParseTargetOptions(const RecordData &Record, bool Complain, |
| 5301 | ASTReaderListener &Listener, |
| 5302 | bool AllowCompatibleDifferences) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5303 | unsigned Idx = 0; |
| 5304 | TargetOptions TargetOpts; |
| 5305 | TargetOpts.Triple = ReadString(Record, Idx); |
| 5306 | TargetOpts.CPU = ReadString(Record, Idx); |
| 5307 | TargetOpts.ABI = ReadString(Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5308 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5309 | TargetOpts.FeaturesAsWritten.push_back(ReadString(Record, Idx)); |
| 5310 | } |
| 5311 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5312 | TargetOpts.Features.push_back(ReadString(Record, Idx)); |
| 5313 | } |
| 5314 | |
| Chandler Carruth | 0d745bc | 2015-03-14 04:47:43 +0000 | [diff] [blame] | 5315 | return Listener.ReadTargetOptions(TargetOpts, Complain, |
| 5316 | AllowCompatibleDifferences); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5317 | } |
| 5318 | |
| 5319 | bool ASTReader::ParseDiagnosticOptions(const RecordData &Record, bool Complain, |
| 5320 | ASTReaderListener &Listener) { |
| Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5321 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5322 | unsigned Idx = 0; |
| Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5323 | #define DIAGOPT(Name, Bits, Default) DiagOpts->Name = Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5324 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5325 | DiagOpts->set##Name(static_cast<Type>(Record[Idx++])); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5326 | #include "clang/Basic/DiagnosticOptions.def" |
| 5327 | |
| Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 5328 | for (unsigned N = Record[Idx++]; N; --N) |
| Ben Langmuir | b92de02 | 2014-04-29 16:25:26 +0000 | [diff] [blame] | 5329 | DiagOpts->Warnings.push_back(ReadString(Record, Idx)); |
| Richard Smith | 3be1cb2 | 2014-08-07 00:24:21 +0000 | [diff] [blame] | 5330 | for (unsigned N = Record[Idx++]; N; --N) |
| 5331 | DiagOpts->Remarks.push_back(ReadString(Record, Idx)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5332 | |
| 5333 | return Listener.ReadDiagnosticOptions(DiagOpts, Complain); |
| 5334 | } |
| 5335 | |
| 5336 | bool ASTReader::ParseFileSystemOptions(const RecordData &Record, bool Complain, |
| 5337 | ASTReaderListener &Listener) { |
| 5338 | FileSystemOptions FSOpts; |
| 5339 | unsigned Idx = 0; |
| 5340 | FSOpts.WorkingDir = ReadString(Record, Idx); |
| 5341 | return Listener.ReadFileSystemOptions(FSOpts, Complain); |
| 5342 | } |
| 5343 | |
| 5344 | bool ASTReader::ParseHeaderSearchOptions(const RecordData &Record, |
| 5345 | bool Complain, |
| 5346 | ASTReaderListener &Listener) { |
| 5347 | HeaderSearchOptions HSOpts; |
| 5348 | unsigned Idx = 0; |
| 5349 | HSOpts.Sysroot = ReadString(Record, Idx); |
| 5350 | |
| 5351 | // Include entries. |
| 5352 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5353 | std::string Path = ReadString(Record, Idx); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5354 | frontend::IncludeDirGroup Group |
| 5355 | = static_cast<frontend::IncludeDirGroup>(Record[Idx++]); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5356 | bool IsFramework = Record[Idx++]; |
| 5357 | bool IgnoreSysRoot = Record[Idx++]; |
| Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 5358 | HSOpts.UserEntries.emplace_back(std::move(Path), Group, IsFramework, |
| 5359 | IgnoreSysRoot); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5360 | } |
| 5361 | |
| 5362 | // System header prefixes. |
| 5363 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5364 | std::string Prefix = ReadString(Record, Idx); |
| 5365 | bool IsSystemHeader = Record[Idx++]; |
| Benjamin Kramer | 3204b15 | 2015-05-29 19:42:19 +0000 | [diff] [blame] | 5366 | HSOpts.SystemHeaderPrefixes.emplace_back(std::move(Prefix), IsSystemHeader); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5367 | } |
| 5368 | |
| 5369 | HSOpts.ResourceDir = ReadString(Record, Idx); |
| 5370 | HSOpts.ModuleCachePath = ReadString(Record, Idx); |
| Argyrios Kyrtzidis | 1594c15 | 2014-03-03 08:12:05 +0000 | [diff] [blame] | 5371 | HSOpts.ModuleUserBuildPath = ReadString(Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5372 | HSOpts.DisableModuleHash = Record[Idx++]; |
| Richard Smith | 1893475 | 2017-06-06 00:32:01 +0000 | [diff] [blame] | 5373 | HSOpts.ImplicitModuleMaps = Record[Idx++]; |
| 5374 | HSOpts.ModuleMapFileHomeIsCwd = Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5375 | HSOpts.UseBuiltinIncludes = Record[Idx++]; |
| 5376 | HSOpts.UseStandardSystemIncludes = Record[Idx++]; |
| 5377 | HSOpts.UseStandardCXXIncludes = Record[Idx++]; |
| 5378 | HSOpts.UseLibcxx = Record[Idx++]; |
| Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 5379 | std::string SpecificModuleCachePath = ReadString(Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5380 | |
| Argyrios Kyrtzidis | bd0b651 | 2015-02-19 20:12:20 +0000 | [diff] [blame] | 5381 | return Listener.ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 5382 | Complain); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5383 | } |
| 5384 | |
| 5385 | bool ASTReader::ParsePreprocessorOptions(const RecordData &Record, |
| 5386 | bool Complain, |
| 5387 | ASTReaderListener &Listener, |
| 5388 | std::string &SuggestedPredefines) { |
| 5389 | PreprocessorOptions PPOpts; |
| 5390 | unsigned Idx = 0; |
| 5391 | |
| 5392 | // Macro definitions/undefs |
| 5393 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5394 | std::string Macro = ReadString(Record, Idx); |
| 5395 | bool IsUndef = Record[Idx++]; |
| 5396 | PPOpts.Macros.push_back(std::make_pair(Macro, IsUndef)); |
| 5397 | } |
| 5398 | |
| 5399 | // Includes |
| 5400 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5401 | PPOpts.Includes.push_back(ReadString(Record, Idx)); |
| 5402 | } |
| 5403 | |
| 5404 | // Macro Includes |
| 5405 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5406 | PPOpts.MacroIncludes.push_back(ReadString(Record, Idx)); |
| 5407 | } |
| 5408 | |
| 5409 | PPOpts.UsePredefines = Record[Idx++]; |
| Argyrios Kyrtzidis | d3afa0c | 2013-04-26 21:33:40 +0000 | [diff] [blame] | 5410 | PPOpts.DetailedRecord = Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5411 | PPOpts.ImplicitPCHInclude = ReadString(Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5412 | PPOpts.ObjCXXARCStandardLibrary = |
| 5413 | static_cast<ObjCXXARCStandardLibraryKind>(Record[Idx++]); |
| 5414 | SuggestedPredefines.clear(); |
| 5415 | return Listener.ReadPreprocessorOptions(PPOpts, Complain, |
| 5416 | SuggestedPredefines); |
| 5417 | } |
| 5418 | |
| 5419 | std::pair<ModuleFile *, unsigned> |
| 5420 | ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { |
| 5421 | GlobalPreprocessedEntityMapType::iterator |
| 5422 | I = GlobalPreprocessedEntityMap.find(GlobalIndex); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5423 | assert(I != GlobalPreprocessedEntityMap.end() && |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5424 | "Corrupted global preprocessed entity map"); |
| 5425 | ModuleFile *M = I->second; |
| 5426 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; |
| 5427 | return std::make_pair(M, LocalIndex); |
| 5428 | } |
| 5429 | |
| Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5430 | llvm::iterator_range<PreprocessingRecord::iterator> |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5431 | ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const { |
| 5432 | if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord()) |
| 5433 | return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID, |
| 5434 | Mod.NumPreprocessedEntities); |
| 5435 | |
| Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5436 | return llvm::make_range(PreprocessingRecord::iterator(), |
| 5437 | PreprocessingRecord::iterator()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5438 | } |
| 5439 | |
| Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5440 | llvm::iterator_range<ASTReader::ModuleDeclIterator> |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5441 | ASTReader::getModuleFileLevelDecls(ModuleFile &Mod) { |
| Benjamin Kramer | b4ef668 | 2015-02-06 17:25:10 +0000 | [diff] [blame] | 5442 | return llvm::make_range( |
| 5443 | ModuleDeclIterator(this, &Mod, Mod.FileSortedDecls), |
| 5444 | ModuleDeclIterator(this, &Mod, |
| 5445 | Mod.FileSortedDecls + Mod.NumFileSortedDecls)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5446 | } |
| 5447 | |
| Cameron Desrochers | b60f1b6 | 2018-01-15 19:14:16 +0000 | [diff] [blame] | 5448 | SourceRange ASTReader::ReadSkippedRange(unsigned GlobalIndex) { |
| 5449 | auto I = GlobalSkippedRangeMap.find(GlobalIndex); |
| 5450 | assert(I != GlobalSkippedRangeMap.end() && |
| 5451 | "Corrupted global skipped range map"); |
| 5452 | ModuleFile *M = I->second; |
| 5453 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedSkippedRangeID; |
| 5454 | assert(LocalIndex < M->NumPreprocessedSkippedRanges); |
| 5455 | PPSkippedRange RawRange = M->PreprocessedSkippedRangeOffsets[LocalIndex]; |
| 5456 | SourceRange Range(TranslateSourceLocation(*M, RawRange.getBegin()), |
| 5457 | TranslateSourceLocation(*M, RawRange.getEnd())); |
| 5458 | assert(Range.isValid()); |
| 5459 | return Range; |
| 5460 | } |
| 5461 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5462 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { |
| 5463 | PreprocessedEntityID PPID = Index+1; |
| 5464 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 5465 | ModuleFile &M = *PPInfo.first; |
| 5466 | unsigned LocalIndex = PPInfo.second; |
| 5467 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 5468 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5469 | if (!PP.getPreprocessingRecord()) { |
| 5470 | Error("no preprocessing record"); |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5471 | return nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5472 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5473 | |
| 5474 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5475 | M.PreprocessorDetailCursor.JumpToBit(PPOffs.BitOffset); |
| 5476 | |
| 5477 | llvm::BitstreamEntry Entry = |
| 5478 | M.PreprocessorDetailCursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd); |
| 5479 | if (Entry.Kind != llvm::BitstreamEntry::Record) |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5480 | return nullptr; |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5481 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5482 | // Read the record. |
| Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 5483 | SourceRange Range(TranslateSourceLocation(M, PPOffs.getBegin()), |
| 5484 | TranslateSourceLocation(M, PPOffs.getEnd())); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5485 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5486 | StringRef Blob; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5487 | RecordData Record; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5488 | PreprocessorDetailRecordTypes RecType = |
| 5489 | (PreprocessorDetailRecordTypes)M.PreprocessorDetailCursor.readRecord( |
| 5490 | Entry.ID, Record, &Blob); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5491 | switch (RecType) { |
| 5492 | case PPD_MACRO_EXPANSION: { |
| 5493 | bool isBuiltin = Record[0]; |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5494 | IdentifierInfo *Name = nullptr; |
| Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5495 | MacroDefinitionRecord *Def = nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5496 | if (isBuiltin) |
| 5497 | Name = getLocalIdentifier(M, Record[1]); |
| 5498 | else { |
| Richard Smith | 66a8186 | 2015-05-04 02:25:31 +0000 | [diff] [blame] | 5499 | PreprocessedEntityID GlobalID = |
| 5500 | getGlobalPreprocessedEntityID(M, Record[1]); |
| 5501 | Def = cast<MacroDefinitionRecord>( |
| 5502 | PPRec.getLoadedPreprocessedEntity(GlobalID - 1)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5503 | } |
| 5504 | |
| 5505 | MacroExpansion *ME; |
| 5506 | if (isBuiltin) |
| 5507 | ME = new (PPRec) MacroExpansion(Name, Range); |
| 5508 | else |
| 5509 | ME = new (PPRec) MacroExpansion(Def, Range); |
| 5510 | |
| 5511 | return ME; |
| 5512 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5513 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5514 | case PPD_MACRO_DEFINITION: { |
| 5515 | // Decode the identifier info and then check again; if the macro is |
| 5516 | // still defined and associated with the identifier, |
| 5517 | IdentifierInfo *II = getLocalIdentifier(M, Record[0]); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5518 | MacroDefinitionRecord *MD = new (PPRec) MacroDefinitionRecord(II, Range); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5519 | |
| 5520 | if (DeserializationListener) |
| 5521 | DeserializationListener->MacroDefinitionRead(PPID, MD); |
| 5522 | |
| 5523 | return MD; |
| 5524 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5525 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5526 | case PPD_INCLUSION_DIRECTIVE: { |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5527 | const char *FullFileNameStart = Blob.data() + Record[0]; |
| 5528 | StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]); |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 5529 | const FileEntry *File = nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5530 | if (!FullFileName.empty()) |
| 5531 | File = PP.getFileManager().getFile(FullFileName); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5532 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5533 | // FIXME: Stable encoding |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5534 | InclusionDirective::InclusionKind Kind |
| 5535 | = static_cast<InclusionDirective::InclusionKind>(Record[2]); |
| 5536 | InclusionDirective *ID |
| 5537 | = new (PPRec) InclusionDirective(PPRec, Kind, |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5538 | StringRef(Blob.data(), Record[0]), |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5539 | Record[1], Record[3], |
| 5540 | File, |
| 5541 | Range); |
| 5542 | return ID; |
| 5543 | } |
| 5544 | } |
| 5545 | |
| 5546 | llvm_unreachable("Invalid PreprocessorDetailRecordTypes"); |
| 5547 | } |
| 5548 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5549 | /// Find the next module that contains entities and return the ID |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5550 | /// of the first entry. |
| NAKAMURA Takumi | 12ab07e | 2017-10-12 09:42:14 +0000 | [diff] [blame] | 5551 | /// |
| 5552 | /// \param SLocMapI points at a chunk of a module that contains no |
| 5553 | /// preprocessed entities or the entities it contains are not the ones we are |
| 5554 | /// looking for. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5555 | PreprocessedEntityID ASTReader::findNextPreprocessedEntity( |
| 5556 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const { |
| 5557 | ++SLocMapI; |
| 5558 | for (GlobalSLocOffsetMapType::const_iterator |
| 5559 | EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) { |
| 5560 | ModuleFile &M = *SLocMapI->second; |
| 5561 | if (M.NumPreprocessedEntities) |
| 5562 | return M.BasePreprocessedEntityID; |
| 5563 | } |
| 5564 | |
| 5565 | return getTotalNumPreprocessedEntities(); |
| 5566 | } |
| 5567 | |
| 5568 | namespace { |
| 5569 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5570 | struct PPEntityComp { |
| 5571 | const ASTReader &Reader; |
| 5572 | ModuleFile &M; |
| 5573 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5574 | PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) {} |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5575 | |
| 5576 | bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const { |
| 5577 | SourceLocation LHS = getLoc(L); |
| 5578 | SourceLocation RHS = getLoc(R); |
| 5579 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5580 | } |
| 5581 | |
| 5582 | bool operator()(const PPEntityOffset &L, SourceLocation RHS) const { |
| 5583 | SourceLocation LHS = getLoc(L); |
| 5584 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5585 | } |
| 5586 | |
| 5587 | bool operator()(SourceLocation LHS, const PPEntityOffset &R) const { |
| 5588 | SourceLocation RHS = getLoc(R); |
| 5589 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 5590 | } |
| 5591 | |
| 5592 | SourceLocation getLoc(const PPEntityOffset &PPE) const { |
| Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5593 | return Reader.TranslateSourceLocation(M, PPE.getBegin()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5594 | } |
| 5595 | }; |
| 5596 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5597 | } // namespace |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5598 | |
| Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5599 | PreprocessedEntityID ASTReader::findPreprocessedEntity(SourceLocation Loc, |
| 5600 | bool EndsAfter) const { |
| 5601 | if (SourceMgr.isLocalSourceLocation(Loc)) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5602 | return getTotalNumPreprocessedEntities(); |
| 5603 | |
| Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5604 | GlobalSLocOffsetMapType::const_iterator SLocMapI = GlobalSLocOffsetMap.find( |
| 5605 | SourceManager::MaxLoadedOffset - Loc.getOffset() - 1); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5606 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 5607 | "Corrupted global sloc offset map"); |
| 5608 | |
| 5609 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 5610 | return findNextPreprocessedEntity(SLocMapI); |
| 5611 | |
| 5612 | ModuleFile &M = *SLocMapI->second; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5613 | |
| 5614 | using pp_iterator = const PPEntityOffset *; |
| 5615 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5616 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 5617 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
| 5618 | |
| 5619 | size_t Count = M.NumPreprocessedEntities; |
| 5620 | size_t Half; |
| 5621 | pp_iterator First = pp_begin; |
| 5622 | pp_iterator PPI; |
| 5623 | |
| Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5624 | if (EndsAfter) { |
| 5625 | PPI = std::upper_bound(pp_begin, pp_end, Loc, |
| Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5626 | PPEntityComp(*this, M)); |
| Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5627 | } else { |
| 5628 | // Do a binary search manually instead of using std::lower_bound because |
| 5629 | // The end locations of entities may be unordered (when a macro expansion |
| 5630 | // is inside another macro argument), but for this case it is not important |
| 5631 | // whether we get the first macro expansion or its containing macro. |
| 5632 | while (Count > 0) { |
| 5633 | Half = Count / 2; |
| 5634 | PPI = First; |
| 5635 | std::advance(PPI, Half); |
| Richard Smith | b22a1d1 | 2016-03-27 20:13:24 +0000 | [diff] [blame] | 5636 | if (SourceMgr.isBeforeInTranslationUnit( |
| 5637 | TranslateSourceLocation(M, PPI->getEnd()), Loc)) { |
| Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5638 | First = PPI; |
| 5639 | ++First; |
| 5640 | Count = Count - Half - 1; |
| 5641 | } else |
| 5642 | Count = Half; |
| 5643 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5644 | } |
| 5645 | |
| 5646 | if (PPI == pp_end) |
| 5647 | return findNextPreprocessedEntity(SLocMapI); |
| 5648 | |
| 5649 | return M.BasePreprocessedEntityID + (PPI - pp_begin); |
| 5650 | } |
| 5651 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5652 | /// Returns a pair of [Begin, End) indices of preallocated |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5653 | /// preprocessed entities that \arg Range encompasses. |
| 5654 | std::pair<unsigned, unsigned> |
| 5655 | ASTReader::findPreprocessedEntitiesInRange(SourceRange Range) { |
| 5656 | if (Range.isInvalid()) |
| 5657 | return std::make_pair(0,0); |
| 5658 | assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); |
| 5659 | |
| Alp Toker | 2e9ce4c | 2014-05-16 18:59:21 +0000 | [diff] [blame] | 5660 | PreprocessedEntityID BeginID = |
| 5661 | findPreprocessedEntity(Range.getBegin(), false); |
| 5662 | PreprocessedEntityID EndID = findPreprocessedEntity(Range.getEnd(), true); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5663 | return std::make_pair(BeginID, EndID); |
| 5664 | } |
| 5665 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5666 | /// Optionally returns true or false if the preallocated preprocessed |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5667 | /// entity with index \arg Index came from file \arg FID. |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5668 | Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5669 | FileID FID) { |
| 5670 | if (FID.isInvalid()) |
| 5671 | return false; |
| 5672 | |
| 5673 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 5674 | ModuleFile &M = *PPInfo.first; |
| 5675 | unsigned LocalIndex = PPInfo.second; |
| 5676 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5677 | |
| Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 5678 | SourceLocation Loc = TranslateSourceLocation(M, PPOffs.getBegin()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5679 | if (Loc.isInvalid()) |
| 5680 | return false; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5681 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5682 | if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) |
| 5683 | return true; |
| 5684 | else |
| 5685 | return false; |
| 5686 | } |
| 5687 | |
| 5688 | namespace { |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5689 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5690 | /// Visitor used to search for information about a header file. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5691 | class HeaderFileInfoVisitor { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5692 | const FileEntry *FE; |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5693 | Optional<HeaderFileInfo> HFI; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5694 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5695 | public: |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5696 | explicit HeaderFileInfoVisitor(const FileEntry *FE) : FE(FE) {} |
| Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 5697 | |
| 5698 | bool operator()(ModuleFile &M) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5699 | HeaderFileInfoLookupTable *Table |
| 5700 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5701 | if (!Table) |
| 5702 | return false; |
| 5703 | |
| 5704 | // 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] | 5705 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5706 | if (Pos == Table->end()) |
| 5707 | return false; |
| 5708 | |
| Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 5709 | HFI = *Pos; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5710 | return true; |
| 5711 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5712 | |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 5713 | Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5714 | }; |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 5715 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 5716 | } // namespace |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5717 | |
| 5718 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
| Argyrios Kyrtzidis | 61a3896 | 2013-03-06 18:12:44 +0000 | [diff] [blame] | 5719 | HeaderFileInfoVisitor Visitor(FE); |
| Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 5720 | ModuleMgr.visit(Visitor); |
| Argyrios Kyrtzidis | 1054bbf | 2013-05-08 23:46:55 +0000 | [diff] [blame] | 5721 | if (Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5722 | return *HFI; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5723 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5724 | return HeaderFileInfo(); |
| 5725 | } |
| 5726 | |
| 5727 | void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { |
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5728 | using DiagState = DiagnosticsEngine::DiagState; |
| 5729 | SmallVector<DiagState *, 32> DiagStates; |
| 5730 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5731 | for (ModuleFile &F : ModuleMgr) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5732 | unsigned Idx = 0; |
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5733 | auto &Record = F.PragmaDiagMappings; |
| 5734 | if (Record.empty()) |
| 5735 | continue; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5736 | |
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5737 | DiagStates.clear(); |
| 5738 | |
| 5739 | auto ReadDiagState = |
| 5740 | [&](const DiagState &BasedOn, SourceLocation Loc, |
| 5741 | bool IncludeNonPragmaStates) -> DiagnosticsEngine::DiagState * { |
| 5742 | unsigned BackrefID = Record[Idx++]; |
| 5743 | if (BackrefID != 0) |
| 5744 | return DiagStates[BackrefID - 1]; |
| 5745 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5746 | // A new DiagState was created here. |
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5747 | Diag.DiagStates.push_back(BasedOn); |
| 5748 | DiagState *NewState = &Diag.DiagStates.back(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5749 | DiagStates.push_back(NewState); |
| Duncan P. N. Exon Smith | 3cb183b | 2017-03-14 19:31:27 +0000 | [diff] [blame] | 5750 | unsigned Size = Record[Idx++]; |
| 5751 | assert(Idx + Size * 2 <= Record.size() && |
| 5752 | "Invalid data, not enough diag/map pairs"); |
| 5753 | while (Size--) { |
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5754 | unsigned DiagID = Record[Idx++]; |
| Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5755 | DiagnosticMapping NewMapping = |
| Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5756 | DiagnosticMapping::deserialize(Record[Idx++]); |
| Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5757 | if (!NewMapping.isPragma() && !IncludeNonPragmaStates) |
| 5758 | continue; |
| 5759 | |
| 5760 | DiagnosticMapping &Mapping = NewState->getOrAddMapping(DiagID); |
| 5761 | |
| 5762 | // If this mapping was specified as a warning but the severity was |
| 5763 | // upgraded due to diagnostic settings, simulate the current diagnostic |
| 5764 | // settings (and use a warning). |
| Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5765 | if (NewMapping.wasUpgradedFromWarning() && !Mapping.isErrorOrFatal()) { |
| 5766 | NewMapping.setSeverity(diag::Severity::Warning); |
| 5767 | NewMapping.setUpgradedFromWarning(false); |
| Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5768 | } |
| 5769 | |
| Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5770 | Mapping = NewMapping; |
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5771 | } |
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5772 | return NewState; |
| 5773 | }; |
| 5774 | |
| Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5775 | // Read the first state. |
| Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5776 | DiagState *FirstState; |
| 5777 | if (F.Kind == MK_ImplicitModule) { |
| 5778 | // Implicitly-built modules are reused with different diagnostic |
| 5779 | // settings. Use the initial diagnostic state from Diag to simulate this |
| 5780 | // compilation's diagnostic settings. |
| 5781 | FirstState = Diag.DiagStatesByLoc.FirstDiagState; |
| 5782 | DiagStates.push_back(FirstState); |
| 5783 | |
| 5784 | // Skip the initial diagnostic state from the serialized module. |
| Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5785 | assert(Record[1] == 0 && |
| Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5786 | "Invalid data, unexpected backref in initial state"); |
| Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5787 | Idx = 3 + Record[2] * 2; |
| Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5788 | assert(Idx < Record.size() && |
| 5789 | "Invalid data, not enough state change pairs in initial state"); |
| Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5790 | } else if (F.isModule()) { |
| 5791 | // For an explicit module, preserve the flags from the module build |
| 5792 | // command line (-w, -Weverything, -Werror, ...) along with any explicit |
| 5793 | // -Wblah flags. |
| 5794 | unsigned Flags = Record[Idx++]; |
| 5795 | DiagState Initial; |
| 5796 | Initial.SuppressSystemWarnings = Flags & 1; Flags >>= 1; |
| 5797 | Initial.ErrorsAsFatal = Flags & 1; Flags >>= 1; |
| 5798 | Initial.WarningsAsErrors = Flags & 1; Flags >>= 1; |
| 5799 | Initial.EnableAllWarnings = Flags & 1; Flags >>= 1; |
| 5800 | Initial.IgnoreAllWarnings = Flags & 1; Flags >>= 1; |
| 5801 | Initial.ExtBehavior = (diag::Severity)Flags; |
| 5802 | FirstState = ReadDiagState(Initial, SourceLocation(), true); |
| Richard Smith | ea74148 | 2017-05-01 22:10:47 +0000 | [diff] [blame] | 5803 | |
| Richard Smith | 6c2b5a8 | 2018-02-09 01:15:13 +0000 | [diff] [blame] | 5804 | assert(F.OriginalSourceFileID.isValid()); |
| 5805 | |
| Richard Smith | e37391c | 2017-05-03 00:28:49 +0000 | [diff] [blame] | 5806 | // Set up the root buffer of the module to start with the initial |
| 5807 | // diagnostic state of the module itself, to cover files that contain no |
| 5808 | // explicit transitions (for which we did not serialize anything). |
| 5809 | Diag.DiagStatesByLoc.Files[F.OriginalSourceFileID] |
| 5810 | .StateTransitions.push_back({FirstState, 0}); |
| 5811 | } else { |
| 5812 | // For prefix ASTs, start with whatever the user configured on the |
| 5813 | // command line. |
| 5814 | Idx++; // Skip flags. |
| 5815 | FirstState = ReadDiagState(*Diag.DiagStatesByLoc.CurDiagState, |
| 5816 | SourceLocation(), false); |
| Duncan P. N. Exon Smith | 900f817 | 2017-04-12 03:58:58 +0000 | [diff] [blame] | 5817 | } |
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5818 | |
| Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5819 | // Read the state transitions. |
| 5820 | unsigned NumLocations = Record[Idx++]; |
| 5821 | while (NumLocations--) { |
| 5822 | assert(Idx < Record.size() && |
| 5823 | "Invalid data, missing pragma diagnostic states"); |
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5824 | SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]); |
| 5825 | auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc); |
| Richard Smith | 6c2b5a8 | 2018-02-09 01:15:13 +0000 | [diff] [blame] | 5826 | assert(IDAndOffset.first.isValid() && "invalid FileID for transition"); |
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5827 | assert(IDAndOffset.second == 0 && "not a start location for a FileID"); |
| 5828 | unsigned Transitions = Record[Idx++]; |
| 5829 | |
| 5830 | // Note that we don't need to set up Parent/ParentOffset here, because |
| 5831 | // we won't be changing the diagnostic state within imported FileIDs |
| 5832 | // (other than perhaps appending to the main source file, which has no |
| 5833 | // parent). |
| 5834 | auto &F = Diag.DiagStatesByLoc.Files[IDAndOffset.first]; |
| 5835 | F.StateTransitions.reserve(F.StateTransitions.size() + Transitions); |
| 5836 | for (unsigned I = 0; I != Transitions; ++I) { |
| 5837 | unsigned Offset = Record[Idx++]; |
| 5838 | auto *State = |
| 5839 | ReadDiagState(*FirstState, Loc.getLocWithOffset(Offset), false); |
| 5840 | F.StateTransitions.push_back({State, Offset}); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5841 | } |
| 5842 | } |
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5843 | |
| Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5844 | // Read the final state. |
| 5845 | assert(Idx < Record.size() && |
| 5846 | "Invalid data, missing final pragma diagnostic state"); |
| 5847 | SourceLocation CurStateLoc = |
| 5848 | ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
| 5849 | auto *CurState = ReadDiagState(*FirstState, CurStateLoc, false); |
| 5850 | |
| 5851 | if (!F.isModule()) { |
| 5852 | Diag.DiagStatesByLoc.CurDiagState = CurState; |
| 5853 | Diag.DiagStatesByLoc.CurDiagStateLoc = CurStateLoc; |
| 5854 | |
| 5855 | // Preserve the property that the imaginary root file describes the |
| 5856 | // current state. |
| Simon Pilgrim | 2251863 | 2017-10-10 13:56:17 +0000 | [diff] [blame] | 5857 | FileID NullFile; |
| 5858 | auto &T = Diag.DiagStatesByLoc.Files[NullFile].StateTransitions; |
| Duncan P. N. Exon Smith | a351c10 | 2017-04-12 03:45:32 +0000 | [diff] [blame] | 5859 | if (T.empty()) |
| 5860 | T.push_back({CurState, 0}); |
| 5861 | else |
| 5862 | T[0].State = CurState; |
| 5863 | } |
| 5864 | |
| Richard Smith | d230de2 | 2017-01-26 01:01:01 +0000 | [diff] [blame] | 5865 | // Don't try to read these mappings again. |
| 5866 | Record.clear(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5867 | } |
| 5868 | } |
| 5869 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5870 | /// Get the correct cursor and offset for loading a type. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5871 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
| 5872 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
| 5873 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
| 5874 | ModuleFile *M = I->second; |
| 5875 | return RecordLocation(M, M->TypeOffsets[Index - M->BaseTypeIndex]); |
| 5876 | } |
| 5877 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 5878 | /// Read and return the type with the given index.. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5879 | /// |
| 5880 | /// The index is the type ID, shifted and minus the number of predefs. This |
| 5881 | /// routine actually reads the record corresponding to the type at the given |
| 5882 | /// location. It is a helper routine for GetType, which deals with reading type |
| 5883 | /// IDs. |
| 5884 | QualType ASTReader::readTypeRecord(unsigned Index) { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 5885 | assert(ContextObj && "reading type with no AST context"); |
| 5886 | ASTContext &Context = *ContextObj; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5887 | RecordLocation Loc = TypeCursorForIndex(Index); |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 5888 | BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5889 | |
| 5890 | // Keep track of where we are in the stream, then jump back there |
| 5891 | // after reading this type. |
| 5892 | SavedStreamPosition SavedPosition(DeclsCursor); |
| 5893 | |
| 5894 | ReadingKindTracker ReadingKind(Read_Type, *this); |
| 5895 | |
| 5896 | // Note that we are loading a type record. |
| 5897 | Deserializing AType(this); |
| 5898 | |
| 5899 | unsigned Idx = 0; |
| 5900 | DeclsCursor.JumpToBit(Loc.Offset); |
| 5901 | RecordData Record; |
| 5902 | unsigned Code = DeclsCursor.ReadCode(); |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 5903 | switch ((TypeCode)DeclsCursor.readRecord(Code, Record)) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5904 | case TYPE_EXT_QUAL: { |
| 5905 | if (Record.size() != 2) { |
| 5906 | Error("Incorrect encoding of extended qualifier type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5907 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5908 | } |
| 5909 | QualType Base = readType(*Loc.F, Record, Idx); |
| 5910 | Qualifiers Quals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
| 5911 | return Context.getQualifiedType(Base, Quals); |
| 5912 | } |
| 5913 | |
| 5914 | case TYPE_COMPLEX: { |
| 5915 | if (Record.size() != 1) { |
| 5916 | Error("Incorrect encoding of complex type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5917 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5918 | } |
| 5919 | QualType ElemType = readType(*Loc.F, Record, Idx); |
| 5920 | return Context.getComplexType(ElemType); |
| 5921 | } |
| 5922 | |
| 5923 | case TYPE_POINTER: { |
| 5924 | if (Record.size() != 1) { |
| 5925 | Error("Incorrect encoding of pointer type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5926 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5927 | } |
| 5928 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5929 | return Context.getPointerType(PointeeType); |
| 5930 | } |
| 5931 | |
| Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 5932 | case TYPE_DECAYED: { |
| 5933 | if (Record.size() != 1) { |
| 5934 | Error("Incorrect encoding of decayed type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5935 | return QualType(); |
| Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 5936 | } |
| 5937 | QualType OriginalType = readType(*Loc.F, Record, Idx); |
| 5938 | QualType DT = Context.getAdjustedParameterType(OriginalType); |
| 5939 | if (!isa<DecayedType>(DT)) |
| 5940 | Error("Decayed type does not decay"); |
| 5941 | return DT; |
| 5942 | } |
| 5943 | |
| Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 5944 | case TYPE_ADJUSTED: { |
| 5945 | if (Record.size() != 2) { |
| 5946 | Error("Incorrect encoding of adjusted type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5947 | return QualType(); |
| Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 5948 | } |
| 5949 | QualType OriginalTy = readType(*Loc.F, Record, Idx); |
| 5950 | QualType AdjustedTy = readType(*Loc.F, Record, Idx); |
| 5951 | return Context.getAdjustedType(OriginalTy, AdjustedTy); |
| 5952 | } |
| 5953 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5954 | case TYPE_BLOCK_POINTER: { |
| 5955 | if (Record.size() != 1) { |
| 5956 | Error("Incorrect encoding of block pointer type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5957 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5958 | } |
| 5959 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5960 | return Context.getBlockPointerType(PointeeType); |
| 5961 | } |
| 5962 | |
| 5963 | case TYPE_LVALUE_REFERENCE: { |
| 5964 | if (Record.size() != 2) { |
| 5965 | Error("Incorrect encoding of lvalue reference type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5966 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5967 | } |
| 5968 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5969 | return Context.getLValueReferenceType(PointeeType, Record[1]); |
| 5970 | } |
| 5971 | |
| 5972 | case TYPE_RVALUE_REFERENCE: { |
| 5973 | if (Record.size() != 1) { |
| 5974 | Error("Incorrect encoding of rvalue reference type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5975 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5976 | } |
| 5977 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5978 | return Context.getRValueReferenceType(PointeeType); |
| 5979 | } |
| 5980 | |
| 5981 | case TYPE_MEMBER_POINTER: { |
| 5982 | if (Record.size() != 2) { |
| 5983 | Error("Incorrect encoding of member pointer type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5984 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5985 | } |
| 5986 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 5987 | QualType ClassType = readType(*Loc.F, Record, Idx); |
| 5988 | if (PointeeType.isNull() || ClassType.isNull()) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5989 | return QualType(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 5990 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5991 | return Context.getMemberPointerType(PointeeType, ClassType.getTypePtr()); |
| 5992 | } |
| 5993 | |
| 5994 | case TYPE_CONSTANT_ARRAY: { |
| 5995 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 5996 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 5997 | unsigned IndexTypeQuals = Record[2]; |
| 5998 | unsigned Idx = 3; |
| 5999 | llvm::APInt Size = ReadAPInt(Record, Idx); |
| 6000 | return Context.getConstantArrayType(ElementType, Size, |
| 6001 | ASM, IndexTypeQuals); |
| 6002 | } |
| 6003 | |
| 6004 | case TYPE_INCOMPLETE_ARRAY: { |
| 6005 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6006 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6007 | unsigned IndexTypeQuals = Record[2]; |
| 6008 | return Context.getIncompleteArrayType(ElementType, ASM, IndexTypeQuals); |
| 6009 | } |
| 6010 | |
| 6011 | case TYPE_VARIABLE_ARRAY: { |
| 6012 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6013 | ArrayType::ArraySizeModifier ASM = (ArrayType::ArraySizeModifier)Record[1]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6014 | unsigned IndexTypeQuals = Record[2]; |
| 6015 | SourceLocation LBLoc = ReadSourceLocation(*Loc.F, Record[3]); |
| 6016 | SourceLocation RBLoc = ReadSourceLocation(*Loc.F, Record[4]); |
| 6017 | return Context.getVariableArrayType(ElementType, ReadExpr(*Loc.F), |
| 6018 | ASM, IndexTypeQuals, |
| 6019 | SourceRange(LBLoc, RBLoc)); |
| 6020 | } |
| 6021 | |
| 6022 | case TYPE_VECTOR: { |
| 6023 | if (Record.size() != 3) { |
| 6024 | Error("incorrect encoding of vector type in AST file"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6025 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6026 | } |
| 6027 | |
| 6028 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 6029 | unsigned NumElements = Record[1]; |
| 6030 | unsigned VecKind = Record[2]; |
| 6031 | return Context.getVectorType(ElementType, NumElements, |
| 6032 | (VectorType::VectorKind)VecKind); |
| 6033 | } |
| 6034 | |
| 6035 | case TYPE_EXT_VECTOR: { |
| 6036 | if (Record.size() != 3) { |
| 6037 | Error("incorrect encoding of extended vector type in AST file"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6038 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6039 | } |
| 6040 | |
| 6041 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 6042 | unsigned NumElements = Record[1]; |
| 6043 | return Context.getExtVectorType(ElementType, NumElements); |
| 6044 | } |
| 6045 | |
| 6046 | case TYPE_FUNCTION_NO_PROTO: { |
| Oren Ben Simhon | 220671a | 2018-03-17 13:31:35 +0000 | [diff] [blame] | 6047 | if (Record.size() != 8) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6048 | Error("incorrect encoding of no-proto function type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6049 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6050 | } |
| 6051 | QualType ResultType = readType(*Loc.F, Record, Idx); |
| 6052 | FunctionType::ExtInfo Info(Record[1], Record[2], Record[3], |
| Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 6053 | (CallingConv)Record[4], Record[5], Record[6], |
| Oren Ben Simhon | 220671a | 2018-03-17 13:31:35 +0000 | [diff] [blame] | 6054 | Record[7]); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6055 | return Context.getFunctionNoProtoType(ResultType, Info); |
| 6056 | } |
| 6057 | |
| 6058 | case TYPE_FUNCTION_PROTO: { |
| 6059 | QualType ResultType = readType(*Loc.F, Record, Idx); |
| 6060 | |
| 6061 | FunctionProtoType::ExtProtoInfo EPI; |
| 6062 | EPI.ExtInfo = FunctionType::ExtInfo(/*noreturn*/ Record[1], |
| 6063 | /*hasregparm*/ Record[2], |
| 6064 | /*regparm*/ Record[3], |
| 6065 | static_cast<CallingConv>(Record[4]), |
| Oren Ben Simhon | 318a6ea | 2017-04-27 12:01:00 +0000 | [diff] [blame] | 6066 | /*produces*/ Record[5], |
| Oren Ben Simhon | 220671a | 2018-03-17 13:31:35 +0000 | [diff] [blame] | 6067 | /*nocallersavedregs*/ Record[6], |
| 6068 | /*nocfcheck*/ Record[7]); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6069 | |
| Oren Ben Simhon | 220671a | 2018-03-17 13:31:35 +0000 | [diff] [blame] | 6070 | unsigned Idx = 8; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6071 | |
| 6072 | EPI.Variadic = Record[Idx++]; |
| 6073 | EPI.HasTrailingReturn = Record[Idx++]; |
| Mikael Nilsson | 9d2872d | 2018-12-13 10:15:27 +0000 | [diff] [blame] | 6074 | EPI.TypeQuals = Qualifiers::fromOpaqueValue(Record[Idx++]); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6075 | EPI.RefQualifier = static_cast<RefQualifierKind>(Record[Idx++]); |
| Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6076 | SmallVector<QualType, 8> ExceptionStorage; |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6077 | readExceptionSpec(*Loc.F, ExceptionStorage, EPI.ExceptionSpec, Record, Idx); |
| Richard Smith | 01b2cb4 | 2014-07-26 06:37:51 +0000 | [diff] [blame] | 6078 | |
| 6079 | unsigned NumParams = Record[Idx++]; |
| 6080 | SmallVector<QualType, 16> ParamTypes; |
| 6081 | for (unsigned I = 0; I != NumParams; ++I) |
| 6082 | ParamTypes.push_back(readType(*Loc.F, Record, Idx)); |
| 6083 | |
| John McCall | 18afab7 | 2016-03-01 00:49:02 +0000 | [diff] [blame] | 6084 | SmallVector<FunctionProtoType::ExtParameterInfo, 4> ExtParameterInfos; |
| 6085 | if (Idx != Record.size()) { |
| 6086 | for (unsigned I = 0; I != NumParams; ++I) |
| 6087 | ExtParameterInfos.push_back( |
| 6088 | FunctionProtoType::ExtParameterInfo |
| 6089 | ::getFromOpaqueValue(Record[Idx++])); |
| 6090 | EPI.ExtParameterInfos = ExtParameterInfos.data(); |
| 6091 | } |
| 6092 | |
| 6093 | assert(Idx == Record.size()); |
| 6094 | |
| Jordan Rose | 5c38272 | 2013-03-08 21:51:21 +0000 | [diff] [blame] | 6095 | return Context.getFunctionType(ResultType, ParamTypes, EPI); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6096 | } |
| 6097 | |
| 6098 | case TYPE_UNRESOLVED_USING: { |
| 6099 | unsigned Idx = 0; |
| 6100 | return Context.getTypeDeclType( |
| 6101 | ReadDeclAs<UnresolvedUsingTypenameDecl>(*Loc.F, Record, Idx)); |
| 6102 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6103 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6104 | case TYPE_TYPEDEF: { |
| 6105 | if (Record.size() != 2) { |
| 6106 | Error("incorrect encoding of typedef type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6107 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6108 | } |
| 6109 | unsigned Idx = 0; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6110 | TypedefNameDecl *Decl = ReadDeclAs<TypedefNameDecl>(*Loc.F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6111 | QualType Canonical = readType(*Loc.F, Record, Idx); |
| 6112 | if (!Canonical.isNull()) |
| 6113 | Canonical = Context.getCanonicalType(Canonical); |
| 6114 | return Context.getTypedefType(Decl, Canonical); |
| 6115 | } |
| 6116 | |
| 6117 | case TYPE_TYPEOF_EXPR: |
| 6118 | return Context.getTypeOfExprType(ReadExpr(*Loc.F)); |
| 6119 | |
| 6120 | case TYPE_TYPEOF: { |
| 6121 | if (Record.size() != 1) { |
| 6122 | Error("incorrect encoding of typeof(type) in AST file"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6123 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6124 | } |
| 6125 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 6126 | return Context.getTypeOfType(UnderlyingType); |
| 6127 | } |
| 6128 | |
| 6129 | case TYPE_DECLTYPE: { |
| 6130 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| 6131 | return Context.getDecltypeType(ReadExpr(*Loc.F), UnderlyingType); |
| 6132 | } |
| 6133 | |
| 6134 | case TYPE_UNARY_TRANSFORM: { |
| 6135 | QualType BaseType = readType(*Loc.F, Record, Idx); |
| 6136 | QualType UnderlyingType = readType(*Loc.F, Record, Idx); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6137 | UnaryTransformType::UTTKind UKind = (UnaryTransformType::UTTKind)Record[2]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6138 | return Context.getUnaryTransformType(BaseType, UnderlyingType, UKind); |
| 6139 | } |
| 6140 | |
| Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 6141 | case TYPE_AUTO: { |
| 6142 | QualType Deduced = readType(*Loc.F, Record, Idx); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6143 | AutoTypeKeyword Keyword = (AutoTypeKeyword)Record[Idx++]; |
| Richard Smith | 27d807c | 2013-04-30 13:56:41 +0000 | [diff] [blame] | 6144 | bool IsDependent = Deduced.isNull() ? Record[Idx++] : false; |
| Richard Smith | e301ba2 | 2015-11-11 02:02:15 +0000 | [diff] [blame] | 6145 | return Context.getAutoType(Deduced, Keyword, IsDependent); |
| Richard Smith | 74aeef5 | 2013-04-26 16:15:35 +0000 | [diff] [blame] | 6146 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6147 | |
| Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 6148 | case TYPE_DEDUCED_TEMPLATE_SPECIALIZATION: { |
| 6149 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
| 6150 | QualType Deduced = readType(*Loc.F, Record, Idx); |
| 6151 | bool IsDependent = Deduced.isNull() ? Record[Idx++] : false; |
| 6152 | return Context.getDeducedTemplateSpecializationType(Name, Deduced, |
| 6153 | IsDependent); |
| 6154 | } |
| 6155 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6156 | case TYPE_RECORD: { |
| 6157 | if (Record.size() != 2) { |
| 6158 | Error("incorrect encoding of record type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6159 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6160 | } |
| 6161 | unsigned Idx = 0; |
| 6162 | bool IsDependent = Record[Idx++]; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6163 | RecordDecl *RD = ReadDeclAs<RecordDecl>(*Loc.F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6164 | RD = cast_or_null<RecordDecl>(RD->getCanonicalDecl()); |
| 6165 | QualType T = Context.getRecordType(RD); |
| 6166 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 6167 | return T; |
| 6168 | } |
| 6169 | |
| 6170 | case TYPE_ENUM: { |
| 6171 | if (Record.size() != 2) { |
| 6172 | Error("incorrect encoding of enum type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6173 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6174 | } |
| 6175 | unsigned Idx = 0; |
| 6176 | bool IsDependent = Record[Idx++]; |
| 6177 | QualType T |
| 6178 | = Context.getEnumType(ReadDeclAs<EnumDecl>(*Loc.F, Record, Idx)); |
| 6179 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 6180 | return T; |
| 6181 | } |
| 6182 | |
| 6183 | case TYPE_ATTRIBUTED: { |
| 6184 | if (Record.size() != 3) { |
| 6185 | Error("incorrect encoding of attributed type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6186 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6187 | } |
| 6188 | QualType modifiedType = readType(*Loc.F, Record, Idx); |
| 6189 | QualType equivalentType = readType(*Loc.F, Record, Idx); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6190 | AttributedType::Kind kind = static_cast<AttributedType::Kind>(Record[2]); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6191 | return Context.getAttributedType(kind, modifiedType, equivalentType); |
| 6192 | } |
| 6193 | |
| 6194 | case TYPE_PAREN: { |
| 6195 | if (Record.size() != 1) { |
| 6196 | Error("incorrect encoding of paren type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6197 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6198 | } |
| 6199 | QualType InnerType = readType(*Loc.F, Record, Idx); |
| 6200 | return Context.getParenType(InnerType); |
| 6201 | } |
| 6202 | |
| 6203 | case TYPE_PACK_EXPANSION: { |
| 6204 | if (Record.size() != 2) { |
| 6205 | Error("incorrect encoding of pack expansion type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6206 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6207 | } |
| 6208 | QualType Pattern = readType(*Loc.F, Record, Idx); |
| 6209 | if (Pattern.isNull()) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6210 | return QualType(); |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 6211 | Optional<unsigned> NumExpansions; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6212 | if (Record[1]) |
| 6213 | NumExpansions = Record[1] - 1; |
| 6214 | return Context.getPackExpansionType(Pattern, NumExpansions); |
| 6215 | } |
| 6216 | |
| 6217 | case TYPE_ELABORATED: { |
| 6218 | unsigned Idx = 0; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6219 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6220 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
| 6221 | QualType NamedType = readType(*Loc.F, Record, Idx); |
| Joel E. Denny | 7509a2f | 2018-05-14 19:36:45 +0000 | [diff] [blame] | 6222 | TagDecl *OwnedTagDecl = ReadDeclAs<TagDecl>(*Loc.F, Record, Idx); |
| 6223 | return Context.getElaboratedType(Keyword, NNS, NamedType, OwnedTagDecl); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6224 | } |
| 6225 | |
| 6226 | case TYPE_OBJC_INTERFACE: { |
| 6227 | unsigned Idx = 0; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6228 | ObjCInterfaceDecl *ItfD |
| 6229 | = ReadDeclAs<ObjCInterfaceDecl>(*Loc.F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6230 | return Context.getObjCInterfaceType(ItfD->getCanonicalDecl()); |
| 6231 | } |
| 6232 | |
| Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6233 | case TYPE_OBJC_TYPE_PARAM: { |
| 6234 | unsigned Idx = 0; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6235 | ObjCTypeParamDecl *Decl |
| 6236 | = ReadDeclAs<ObjCTypeParamDecl>(*Loc.F, Record, Idx); |
| Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6237 | unsigned NumProtos = Record[Idx++]; |
| 6238 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 6239 | for (unsigned I = 0; I != NumProtos; ++I) |
| 6240 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
| 6241 | return Context.getObjCTypeParamType(Decl, Protos); |
| 6242 | } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6243 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6244 | case TYPE_OBJC_OBJECT: { |
| 6245 | unsigned Idx = 0; |
| 6246 | QualType Base = readType(*Loc.F, Record, Idx); |
| Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6247 | unsigned NumTypeArgs = Record[Idx++]; |
| 6248 | SmallVector<QualType, 4> TypeArgs; |
| 6249 | for (unsigned I = 0; I != NumTypeArgs; ++I) |
| 6250 | TypeArgs.push_back(readType(*Loc.F, Record, Idx)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6251 | unsigned NumProtos = Record[Idx++]; |
| 6252 | SmallVector<ObjCProtocolDecl*, 4> Protos; |
| 6253 | for (unsigned I = 0; I != NumProtos; ++I) |
| 6254 | Protos.push_back(ReadDeclAs<ObjCProtocolDecl>(*Loc.F, Record, Idx)); |
| Douglas Gregor | ab209d8 | 2015-07-07 03:58:42 +0000 | [diff] [blame] | 6255 | bool IsKindOf = Record[Idx++]; |
| 6256 | return Context.getObjCObjectType(Base, TypeArgs, Protos, IsKindOf); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6257 | } |
| 6258 | |
| 6259 | case TYPE_OBJC_OBJECT_POINTER: { |
| 6260 | unsigned Idx = 0; |
| 6261 | QualType Pointee = readType(*Loc.F, Record, Idx); |
| 6262 | return Context.getObjCObjectPointerType(Pointee); |
| 6263 | } |
| 6264 | |
| 6265 | case TYPE_SUBST_TEMPLATE_TYPE_PARM: { |
| 6266 | unsigned Idx = 0; |
| 6267 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 6268 | QualType Replacement = readType(*Loc.F, Record, Idx); |
| Stephan Tolksdorf | e96f8b3 | 2014-03-15 10:23:27 +0000 | [diff] [blame] | 6269 | return Context.getSubstTemplateTypeParmType( |
| 6270 | cast<TemplateTypeParmType>(Parm), |
| 6271 | Context.getCanonicalType(Replacement)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6272 | } |
| 6273 | |
| 6274 | case TYPE_SUBST_TEMPLATE_TYPE_PARM_PACK: { |
| 6275 | unsigned Idx = 0; |
| 6276 | QualType Parm = readType(*Loc.F, Record, Idx); |
| 6277 | TemplateArgument ArgPack = ReadTemplateArgument(*Loc.F, Record, Idx); |
| 6278 | return Context.getSubstTemplateTypeParmPackType( |
| 6279 | cast<TemplateTypeParmType>(Parm), |
| 6280 | ArgPack); |
| 6281 | } |
| 6282 | |
| 6283 | case TYPE_INJECTED_CLASS_NAME: { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6284 | CXXRecordDecl *D = ReadDeclAs<CXXRecordDecl>(*Loc.F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6285 | QualType TST = readType(*Loc.F, Record, Idx); // probably derivable |
| 6286 | // FIXME: ASTContext::getInjectedClassNameType is not currently suitable |
| 6287 | // for AST reading, too much interdependencies. |
| Richard Smith | 6377f8f | 2014-10-21 21:15:18 +0000 | [diff] [blame] | 6288 | const Type *T = nullptr; |
| 6289 | for (auto *DI = D; DI; DI = DI->getPreviousDecl()) { |
| 6290 | if (const Type *Existing = DI->getTypeForDecl()) { |
| 6291 | T = Existing; |
| 6292 | break; |
| 6293 | } |
| 6294 | } |
| 6295 | if (!T) { |
| Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 6296 | T = new (Context, TypeAlignment) InjectedClassNameType(D, TST); |
| Richard Smith | 6377f8f | 2014-10-21 21:15:18 +0000 | [diff] [blame] | 6297 | for (auto *DI = D; DI; DI = DI->getPreviousDecl()) |
| 6298 | DI->setTypeForDecl(T); |
| 6299 | } |
| Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 6300 | return QualType(T, 0); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6301 | } |
| 6302 | |
| 6303 | case TYPE_TEMPLATE_TYPE_PARM: { |
| 6304 | unsigned Idx = 0; |
| 6305 | unsigned Depth = Record[Idx++]; |
| 6306 | unsigned Index = Record[Idx++]; |
| 6307 | bool Pack = Record[Idx++]; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6308 | TemplateTypeParmDecl *D |
| 6309 | = ReadDeclAs<TemplateTypeParmDecl>(*Loc.F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6310 | return Context.getTemplateTypeParmType(Depth, Index, Pack, D); |
| 6311 | } |
| 6312 | |
| 6313 | case TYPE_DEPENDENT_NAME: { |
| 6314 | unsigned Idx = 0; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6315 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6316 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
| Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 6317 | const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6318 | QualType Canon = readType(*Loc.F, Record, Idx); |
| 6319 | if (!Canon.isNull()) |
| 6320 | Canon = Context.getCanonicalType(Canon); |
| 6321 | return Context.getDependentNameType(Keyword, NNS, Name, Canon); |
| 6322 | } |
| 6323 | |
| 6324 | case TYPE_DEPENDENT_TEMPLATE_SPECIALIZATION: { |
| 6325 | unsigned Idx = 0; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6326 | ElaboratedTypeKeyword Keyword = (ElaboratedTypeKeyword)Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6327 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(*Loc.F, Record, Idx); |
| Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 6328 | const IdentifierInfo *Name = GetIdentifierInfo(*Loc.F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6329 | unsigned NumArgs = Record[Idx++]; |
| 6330 | SmallVector<TemplateArgument, 8> Args; |
| 6331 | Args.reserve(NumArgs); |
| 6332 | while (NumArgs--) |
| 6333 | Args.push_back(ReadTemplateArgument(*Loc.F, Record, Idx)); |
| 6334 | return Context.getDependentTemplateSpecializationType(Keyword, NNS, Name, |
| David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 6335 | Args); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6336 | } |
| 6337 | |
| 6338 | case TYPE_DEPENDENT_SIZED_ARRAY: { |
| 6339 | unsigned Idx = 0; |
| 6340 | |
| 6341 | // ArrayType |
| 6342 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6343 | ArrayType::ArraySizeModifier ASM |
| 6344 | = (ArrayType::ArraySizeModifier)Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6345 | unsigned IndexTypeQuals = Record[Idx++]; |
| 6346 | |
| 6347 | // DependentSizedArrayType |
| 6348 | Expr *NumElts = ReadExpr(*Loc.F); |
| 6349 | SourceRange Brackets = ReadSourceRange(*Loc.F, Record, Idx); |
| 6350 | |
| 6351 | return Context.getDependentSizedArrayType(ElementType, NumElts, ASM, |
| 6352 | IndexTypeQuals, Brackets); |
| 6353 | } |
| 6354 | |
| 6355 | case TYPE_TEMPLATE_SPECIALIZATION: { |
| 6356 | unsigned Idx = 0; |
| 6357 | bool IsDependent = Record[Idx++]; |
| 6358 | TemplateName Name = ReadTemplateName(*Loc.F, Record, Idx); |
| 6359 | SmallVector<TemplateArgument, 8> Args; |
| 6360 | ReadTemplateArgumentList(Args, *Loc.F, Record, Idx); |
| 6361 | QualType Underlying = readType(*Loc.F, Record, Idx); |
| 6362 | QualType T; |
| 6363 | if (Underlying.isNull()) |
| David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 6364 | T = Context.getCanonicalTemplateSpecializationType(Name, Args); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6365 | else |
| David Majnemer | 6fbeee3 | 2016-07-07 04:43:07 +0000 | [diff] [blame] | 6366 | T = Context.getTemplateSpecializationType(Name, Args, Underlying); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6367 | const_cast<Type*>(T.getTypePtr())->setDependent(IsDependent); |
| 6368 | return T; |
| 6369 | } |
| 6370 | |
| 6371 | case TYPE_ATOMIC: { |
| 6372 | if (Record.size() != 1) { |
| 6373 | Error("Incorrect encoding of atomic type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6374 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6375 | } |
| 6376 | QualType ValueType = readType(*Loc.F, Record, Idx); |
| 6377 | return Context.getAtomicType(ValueType); |
| 6378 | } |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6379 | |
| Joey Gouly | e3c85de | 2016-12-01 11:30:49 +0000 | [diff] [blame] | 6380 | case TYPE_PIPE: { |
| 6381 | if (Record.size() != 2) { |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6382 | Error("Incorrect encoding of pipe type"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6383 | return QualType(); |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6384 | } |
| 6385 | |
| 6386 | // Reading the pipe element type. |
| 6387 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| Joey Gouly | e3c85de | 2016-12-01 11:30:49 +0000 | [diff] [blame] | 6388 | unsigned ReadOnly = Record[1]; |
| 6389 | return Context.getPipeType(ElementType, ReadOnly); |
| Joey Gouly | 5788b78 | 2016-11-18 14:10:54 +0000 | [diff] [blame] | 6390 | } |
| 6391 | |
| Erich Keane | f702b02 | 2018-07-13 19:46:04 +0000 | [diff] [blame] | 6392 | case TYPE_DEPENDENT_SIZED_VECTOR: { |
| 6393 | unsigned Idx = 0; |
| 6394 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 6395 | Expr *SizeExpr = ReadExpr(*Loc.F); |
| 6396 | SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx); |
| 6397 | unsigned VecKind = Record[Idx]; |
| 6398 | |
| 6399 | return Context.getDependentVectorType(ElementType, SizeExpr, AttrLoc, |
| 6400 | (VectorType::VectorKind)VecKind); |
| 6401 | } |
| 6402 | |
| Alex Lorenz | 00aee43 | 2017-03-22 10:04:48 +0000 | [diff] [blame] | 6403 | case TYPE_DEPENDENT_SIZED_EXT_VECTOR: { |
| 6404 | unsigned Idx = 0; |
| 6405 | |
| 6406 | // DependentSizedExtVectorType |
| 6407 | QualType ElementType = readType(*Loc.F, Record, Idx); |
| 6408 | Expr *SizeExpr = ReadExpr(*Loc.F); |
| 6409 | SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx); |
| 6410 | |
| 6411 | return Context.getDependentSizedExtVectorType(ElementType, SizeExpr, |
| 6412 | AttrLoc); |
| 6413 | } |
| Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 6414 | |
| 6415 | case TYPE_DEPENDENT_ADDRESS_SPACE: { |
| 6416 | unsigned Idx = 0; |
| 6417 | |
| 6418 | // DependentAddressSpaceType |
| 6419 | QualType PointeeType = readType(*Loc.F, Record, Idx); |
| 6420 | Expr *AddrSpaceExpr = ReadExpr(*Loc.F); |
| 6421 | SourceLocation AttrLoc = ReadSourceLocation(*Loc.F, Record, Idx); |
| 6422 | |
| 6423 | return Context.getDependentAddressSpaceType(PointeeType, AddrSpaceExpr, |
| 6424 | AttrLoc); |
| 6425 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6426 | } |
| 6427 | llvm_unreachable("Invalid TypeCode!"); |
| 6428 | } |
| 6429 | |
| Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6430 | void ASTReader::readExceptionSpec(ModuleFile &ModuleFile, |
| 6431 | SmallVectorImpl<QualType> &Exceptions, |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6432 | FunctionProtoType::ExceptionSpecInfo &ESI, |
| Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6433 | const RecordData &Record, unsigned &Idx) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6434 | ExceptionSpecificationType EST = |
| 6435 | static_cast<ExceptionSpecificationType>(Record[Idx++]); |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6436 | ESI.Type = EST; |
| Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6437 | if (EST == EST_Dynamic) { |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6438 | for (unsigned I = 0, N = Record[Idx++]; I != N; ++I) |
| Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6439 | Exceptions.push_back(readType(ModuleFile, Record, Idx)); |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6440 | ESI.Exceptions = Exceptions; |
| Richard Smith | eaf11ad | 2018-05-03 03:58:32 +0000 | [diff] [blame] | 6441 | } else if (isComputedNoexcept(EST)) { |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6442 | ESI.NoexceptExpr = ReadExpr(ModuleFile); |
| Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6443 | } else if (EST == EST_Uninstantiated) { |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6444 | ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
| 6445 | ESI.SourceTemplate = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
| Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6446 | } else if (EST == EST_Unevaluated) { |
| Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 6447 | ESI.SourceDecl = ReadDeclAs<FunctionDecl>(ModuleFile, Record, Idx); |
| Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 6448 | } |
| 6449 | } |
| 6450 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6451 | namespace clang { |
| 6452 | |
| 6453 | class TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6454 | ModuleFile *F; |
| 6455 | ASTReader *Reader; |
| 6456 | const ASTReader::RecordData &Record; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6457 | unsigned &Idx; |
| 6458 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6459 | SourceLocation ReadSourceLocation() { |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6460 | return Reader->ReadSourceLocation(*F, Record, Idx); |
| 6461 | } |
| 6462 | |
| 6463 | TypeSourceInfo *GetTypeSourceInfo() { |
| 6464 | return Reader->GetTypeSourceInfo(*F, Record, Idx); |
| 6465 | } |
| 6466 | |
| 6467 | NestedNameSpecifierLoc ReadNestedNameSpecifierLoc() { |
| 6468 | return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6469 | } |
| 6470 | |
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 6471 | Attr *ReadAttr() { |
| 6472 | return Reader->ReadAttr(*F, Record, Idx); |
| 6473 | } |
| 6474 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6475 | public: |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6476 | TypeLocReader(ModuleFile &F, ASTReader &Reader, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6477 | const ASTReader::RecordData &Record, unsigned &Idx) |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6478 | : F(&F), Reader(&Reader), Record(Record), Idx(Idx) {} |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6479 | |
| 6480 | // We want compile-time assurance that we've enumerated all of |
| 6481 | // these, so unfortunately we have to declare them first, then |
| 6482 | // define them out-of-line. |
| 6483 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 6484 | #define TYPELOC(CLASS, PARENT) \ |
| 6485 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
| 6486 | #include "clang/AST/TypeLocNodes.def" |
| 6487 | |
| 6488 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 6489 | void VisitArrayTypeLoc(ArrayTypeLoc); |
| 6490 | }; |
| 6491 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6492 | } // namespace clang |
| 6493 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6494 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 6495 | // nothing to do |
| 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::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6499 | TL.setBuiltinLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6500 | if (TL.needsExtraLocalData()) { |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6501 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Record[Idx++])); |
| 6502 | TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Record[Idx++])); |
| 6503 | TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Record[Idx++])); |
| 6504 | TL.setModeAttr(Record[Idx++]); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6505 | } |
| 6506 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6507 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6508 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6509 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6510 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6511 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6512 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6513 | TL.setStarLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6514 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6515 | |
| Reid Kleckner | 8a36502 | 2013-06-24 17:51:48 +0000 | [diff] [blame] | 6516 | void TypeLocReader::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 6517 | // nothing to do |
| 6518 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6519 | |
| Reid Kleckner | 0503a87 | 2013-12-05 01:23:43 +0000 | [diff] [blame] | 6520 | void TypeLocReader::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 6521 | // nothing to do |
| 6522 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6523 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6524 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6525 | TL.setCaretLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6526 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6527 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6528 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6529 | TL.setAmpLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6530 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6531 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6532 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6533 | TL.setAmpAmpLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6534 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6535 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6536 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6537 | TL.setStarLoc(ReadSourceLocation()); |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6538 | TL.setClassTInfo(GetTypeSourceInfo()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6539 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6540 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6541 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6542 | TL.setLBracketLoc(ReadSourceLocation()); |
| 6543 | TL.setRBracketLoc(ReadSourceLocation()); |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6544 | if (Record[Idx++]) |
| 6545 | TL.setSizeExpr(Reader->ReadExpr(*F)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6546 | else |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6547 | TL.setSizeExpr(nullptr); |
| 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::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 6551 | VisitArrayTypeLoc(TL); |
| 6552 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6553 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6554 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 6555 | VisitArrayTypeLoc(TL); |
| 6556 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6557 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6558 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 6559 | VisitArrayTypeLoc(TL); |
| 6560 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6561 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6562 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 6563 | DependentSizedArrayTypeLoc TL) { |
| 6564 | VisitArrayTypeLoc(TL); |
| 6565 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6566 | |
| Andrew Gozillon | 572bbb0 | 2017-10-02 06:25:51 +0000 | [diff] [blame] | 6567 | void TypeLocReader::VisitDependentAddressSpaceTypeLoc( |
| 6568 | DependentAddressSpaceTypeLoc TL) { |
| 6569 | |
| 6570 | TL.setAttrNameLoc(ReadSourceLocation()); |
| 6571 | SourceRange range; |
| 6572 | range.setBegin(ReadSourceLocation()); |
| 6573 | range.setEnd(ReadSourceLocation()); |
| 6574 | TL.setAttrOperandParensRange(range); |
| 6575 | TL.setAttrExprOperand(Reader->ReadExpr(*F)); |
| 6576 | } |
| 6577 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6578 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 6579 | DependentSizedExtVectorTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6580 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6581 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6582 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6583 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6584 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6585 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6586 | |
| Erich Keane | f702b02 | 2018-07-13 19:46:04 +0000 | [diff] [blame] | 6587 | void TypeLocReader::VisitDependentVectorTypeLoc( |
| 6588 | DependentVectorTypeLoc TL) { |
| 6589 | TL.setNameLoc(ReadSourceLocation()); |
| 6590 | } |
| 6591 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6592 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6593 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6594 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6595 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6596 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6597 | TL.setLocalRangeBegin(ReadSourceLocation()); |
| 6598 | TL.setLParenLoc(ReadSourceLocation()); |
| 6599 | TL.setRParenLoc(ReadSourceLocation()); |
| Malcolm Parsons | a3220ce | 2017-01-12 16:11:28 +0000 | [diff] [blame] | 6600 | TL.setExceptionSpecRange(SourceRange(Reader->ReadSourceLocation(*F, Record, Idx), |
| 6601 | Reader->ReadSourceLocation(*F, Record, Idx))); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6602 | TL.setLocalRangeEnd(ReadSourceLocation()); |
| Alp Toker | b3fd5cf | 2014-01-21 00:32:38 +0000 | [diff] [blame] | 6603 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) { |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6604 | TL.setParam(i, Reader->ReadDeclAs<ParmVarDecl>(*F, Record, Idx)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6605 | } |
| 6606 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6607 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6608 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 6609 | VisitFunctionTypeLoc(TL); |
| 6610 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6611 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6612 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 6613 | VisitFunctionTypeLoc(TL); |
| 6614 | } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6615 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6616 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6617 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6618 | } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6619 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6620 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6621 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6622 | } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6623 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6624 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6625 | TL.setTypeofLoc(ReadSourceLocation()); |
| 6626 | TL.setLParenLoc(ReadSourceLocation()); |
| 6627 | TL.setRParenLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6628 | } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6629 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6630 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6631 | TL.setTypeofLoc(ReadSourceLocation()); |
| 6632 | TL.setLParenLoc(ReadSourceLocation()); |
| 6633 | TL.setRParenLoc(ReadSourceLocation()); |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6634 | TL.setUnderlyingTInfo(GetTypeSourceInfo()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6635 | } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6636 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6637 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6638 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6639 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6640 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6641 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6642 | TL.setKWLoc(ReadSourceLocation()); |
| 6643 | TL.setLParenLoc(ReadSourceLocation()); |
| 6644 | TL.setRParenLoc(ReadSourceLocation()); |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6645 | TL.setUnderlyingTInfo(GetTypeSourceInfo()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6646 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6647 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6648 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6649 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6650 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6651 | |
| Richard Smith | 600b526 | 2017-01-26 20:40:47 +0000 | [diff] [blame] | 6652 | void TypeLocReader::VisitDeducedTemplateSpecializationTypeLoc( |
| 6653 | DeducedTemplateSpecializationTypeLoc TL) { |
| 6654 | TL.setTemplateNameLoc(ReadSourceLocation()); |
| 6655 | } |
| 6656 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6657 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6658 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6659 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6660 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6661 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6662 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6663 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6664 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6665 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 6666 | TL.setAttr(ReadAttr()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6667 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6668 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6669 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6670 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6671 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6672 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6673 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 6674 | SubstTemplateTypeParmTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6675 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6676 | } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6677 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6678 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 6679 | SubstTemplateTypeParmPackTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6680 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6681 | } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6682 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6683 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 6684 | TemplateSpecializationTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6685 | TL.setTemplateKeywordLoc(ReadSourceLocation()); |
| 6686 | TL.setTemplateNameLoc(ReadSourceLocation()); |
| 6687 | TL.setLAngleLoc(ReadSourceLocation()); |
| 6688 | TL.setRAngleLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6689 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6690 | TL.setArgLocInfo( |
| 6691 | i, |
| 6692 | Reader->GetTemplateArgumentLocInfo( |
| 6693 | *F, TL.getTypePtr()->getArg(i).getKind(), Record, Idx)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6694 | } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 6695 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6696 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6697 | TL.setLParenLoc(ReadSourceLocation()); |
| 6698 | TL.setRParenLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6699 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6700 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6701 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6702 | TL.setElaboratedKeywordLoc(ReadSourceLocation()); |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6703 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6704 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6705 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6706 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6707 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6708 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6709 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6710 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6711 | TL.setElaboratedKeywordLoc(ReadSourceLocation()); |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6712 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6713 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6714 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6715 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6716 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 6717 | DependentTemplateSpecializationTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6718 | TL.setElaboratedKeywordLoc(ReadSourceLocation()); |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6719 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6720 | TL.setTemplateKeywordLoc(ReadSourceLocation()); |
| 6721 | TL.setTemplateNameLoc(ReadSourceLocation()); |
| 6722 | TL.setLAngleLoc(ReadSourceLocation()); |
| 6723 | TL.setRAngleLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6724 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6725 | TL.setArgLocInfo( |
| 6726 | I, |
| 6727 | Reader->GetTemplateArgumentLocInfo( |
| 6728 | *F, TL.getTypePtr()->getArg(I).getKind(), Record, Idx)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6729 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6730 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6731 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6732 | TL.setEllipsisLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6733 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6734 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6735 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6736 | TL.setNameLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6737 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6738 | |
| Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6739 | void TypeLocReader::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { |
| 6740 | if (TL.getNumProtocols()) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6741 | TL.setProtocolLAngleLoc(ReadSourceLocation()); |
| 6742 | TL.setProtocolRAngleLoc(ReadSourceLocation()); |
| Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6743 | } |
| 6744 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6745 | TL.setProtocolLoc(i, ReadSourceLocation()); |
| Manman Ren | e6be26c | 2016-09-13 17:25:08 +0000 | [diff] [blame] | 6746 | } |
| 6747 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6748 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6749 | TL.setHasBaseTypeAsWritten(Record[Idx++]); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6750 | TL.setTypeArgsLAngleLoc(ReadSourceLocation()); |
| 6751 | TL.setTypeArgsRAngleLoc(ReadSourceLocation()); |
| Douglas Gregor | e9d95f1 | 2015-07-07 03:57:35 +0000 | [diff] [blame] | 6752 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6753 | TL.setTypeArgTInfo(i, GetTypeSourceInfo()); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6754 | TL.setProtocolLAngleLoc(ReadSourceLocation()); |
| 6755 | TL.setProtocolRAngleLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6756 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6757 | TL.setProtocolLoc(i, ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6758 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6759 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6760 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6761 | TL.setStarLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6762 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6763 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6764 | void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6765 | TL.setKWLoc(ReadSourceLocation()); |
| 6766 | TL.setLParenLoc(ReadSourceLocation()); |
| 6767 | TL.setRParenLoc(ReadSourceLocation()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6768 | } |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 6769 | |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6770 | void TypeLocReader::VisitPipeTypeLoc(PipeTypeLoc TL) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 6771 | TL.setKWLoc(ReadSourceLocation()); |
| Xiuli Pan | 9c14e28 | 2016-01-09 12:53:17 +0000 | [diff] [blame] | 6772 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6773 | |
| Richard Smith | c23d734 | 2018-06-29 20:46:25 +0000 | [diff] [blame] | 6774 | void ASTReader::ReadTypeLoc(ModuleFile &F, const ASTReader::RecordData &Record, |
| 6775 | unsigned &Idx, TypeLoc TL) { |
| 6776 | TypeLocReader TLR(F, *this, Record, Idx); |
| 6777 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
| 6778 | TLR.Visit(TL); |
| 6779 | } |
| 6780 | |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 6781 | TypeSourceInfo * |
| 6782 | ASTReader::GetTypeSourceInfo(ModuleFile &F, const ASTReader::RecordData &Record, |
| 6783 | unsigned &Idx) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6784 | QualType InfoTy = readType(F, Record, Idx); |
| 6785 | if (InfoTy.isNull()) |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 6786 | return nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6787 | |
| 6788 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
| Richard Smith | c23d734 | 2018-06-29 20:46:25 +0000 | [diff] [blame] | 6789 | ReadTypeLoc(F, Record, Idx, TInfo->getTypeLoc()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6790 | return TInfo; |
| 6791 | } |
| 6792 | |
| 6793 | QualType ASTReader::GetType(TypeID ID) { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 6794 | assert(ContextObj && "reading type with no AST context"); |
| 6795 | ASTContext &Context = *ContextObj; |
| 6796 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6797 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 6798 | unsigned Index = ID >> Qualifiers::FastWidth; |
| 6799 | |
| 6800 | if (Index < NUM_PREDEF_TYPE_IDS) { |
| 6801 | QualType T; |
| 6802 | switch ((PredefinedTypeIDs)Index) { |
| Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6803 | case PREDEF_TYPE_NULL_ID: |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 6804 | return QualType(); |
| Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6805 | case PREDEF_TYPE_VOID_ID: |
| 6806 | T = Context.VoidTy; |
| 6807 | break; |
| 6808 | case PREDEF_TYPE_BOOL_ID: |
| 6809 | T = Context.BoolTy; |
| 6810 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 6811 | case PREDEF_TYPE_CHAR_U_ID: |
| 6812 | case PREDEF_TYPE_CHAR_S_ID: |
| 6813 | // FIXME: Check that the signedness of CharTy is correct! |
| 6814 | T = Context.CharTy; |
| 6815 | break; |
| Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6816 | case PREDEF_TYPE_UCHAR_ID: |
| 6817 | T = Context.UnsignedCharTy; |
| 6818 | break; |
| 6819 | case PREDEF_TYPE_USHORT_ID: |
| 6820 | T = Context.UnsignedShortTy; |
| 6821 | break; |
| 6822 | case PREDEF_TYPE_UINT_ID: |
| 6823 | T = Context.UnsignedIntTy; |
| 6824 | break; |
| 6825 | case PREDEF_TYPE_ULONG_ID: |
| 6826 | T = Context.UnsignedLongTy; |
| 6827 | break; |
| 6828 | case PREDEF_TYPE_ULONGLONG_ID: |
| 6829 | T = Context.UnsignedLongLongTy; |
| 6830 | break; |
| 6831 | case PREDEF_TYPE_UINT128_ID: |
| 6832 | T = Context.UnsignedInt128Ty; |
| 6833 | break; |
| 6834 | case PREDEF_TYPE_SCHAR_ID: |
| 6835 | T = Context.SignedCharTy; |
| 6836 | break; |
| 6837 | case PREDEF_TYPE_WCHAR_ID: |
| 6838 | T = Context.WCharTy; |
| 6839 | break; |
| 6840 | case PREDEF_TYPE_SHORT_ID: |
| 6841 | T = Context.ShortTy; |
| 6842 | break; |
| 6843 | case PREDEF_TYPE_INT_ID: |
| 6844 | T = Context.IntTy; |
| 6845 | break; |
| 6846 | case PREDEF_TYPE_LONG_ID: |
| 6847 | T = Context.LongTy; |
| 6848 | break; |
| 6849 | case PREDEF_TYPE_LONGLONG_ID: |
| 6850 | T = Context.LongLongTy; |
| 6851 | break; |
| 6852 | case PREDEF_TYPE_INT128_ID: |
| 6853 | T = Context.Int128Ty; |
| 6854 | break; |
| 6855 | case PREDEF_TYPE_HALF_ID: |
| 6856 | T = Context.HalfTy; |
| 6857 | break; |
| 6858 | case PREDEF_TYPE_FLOAT_ID: |
| 6859 | T = Context.FloatTy; |
| 6860 | break; |
| 6861 | case PREDEF_TYPE_DOUBLE_ID: |
| 6862 | T = Context.DoubleTy; |
| 6863 | break; |
| 6864 | case PREDEF_TYPE_LONGDOUBLE_ID: |
| 6865 | T = Context.LongDoubleTy; |
| 6866 | break; |
| Leonard Chan | f921d85 | 2018-06-04 16:07:52 +0000 | [diff] [blame] | 6867 | case PREDEF_TYPE_SHORT_ACCUM_ID: |
| 6868 | T = Context.ShortAccumTy; |
| 6869 | break; |
| 6870 | case PREDEF_TYPE_ACCUM_ID: |
| 6871 | T = Context.AccumTy; |
| 6872 | break; |
| 6873 | case PREDEF_TYPE_LONG_ACCUM_ID: |
| 6874 | T = Context.LongAccumTy; |
| 6875 | break; |
| 6876 | case PREDEF_TYPE_USHORT_ACCUM_ID: |
| 6877 | T = Context.UnsignedShortAccumTy; |
| 6878 | break; |
| 6879 | case PREDEF_TYPE_UACCUM_ID: |
| 6880 | T = Context.UnsignedAccumTy; |
| 6881 | break; |
| 6882 | case PREDEF_TYPE_ULONG_ACCUM_ID: |
| 6883 | T = Context.UnsignedLongAccumTy; |
| 6884 | break; |
| Leonard Chan | ab80f3c | 2018-06-14 14:53:51 +0000 | [diff] [blame] | 6885 | case PREDEF_TYPE_SHORT_FRACT_ID: |
| 6886 | T = Context.ShortFractTy; |
| 6887 | break; |
| 6888 | case PREDEF_TYPE_FRACT_ID: |
| 6889 | T = Context.FractTy; |
| 6890 | break; |
| 6891 | case PREDEF_TYPE_LONG_FRACT_ID: |
| 6892 | T = Context.LongFractTy; |
| 6893 | break; |
| 6894 | case PREDEF_TYPE_USHORT_FRACT_ID: |
| 6895 | T = Context.UnsignedShortFractTy; |
| 6896 | break; |
| 6897 | case PREDEF_TYPE_UFRACT_ID: |
| 6898 | T = Context.UnsignedFractTy; |
| 6899 | break; |
| 6900 | case PREDEF_TYPE_ULONG_FRACT_ID: |
| 6901 | T = Context.UnsignedLongFractTy; |
| 6902 | break; |
| 6903 | case PREDEF_TYPE_SAT_SHORT_ACCUM_ID: |
| 6904 | T = Context.SatShortAccumTy; |
| 6905 | break; |
| 6906 | case PREDEF_TYPE_SAT_ACCUM_ID: |
| 6907 | T = Context.SatAccumTy; |
| 6908 | break; |
| 6909 | case PREDEF_TYPE_SAT_LONG_ACCUM_ID: |
| 6910 | T = Context.SatLongAccumTy; |
| 6911 | break; |
| 6912 | case PREDEF_TYPE_SAT_USHORT_ACCUM_ID: |
| 6913 | T = Context.SatUnsignedShortAccumTy; |
| 6914 | break; |
| 6915 | case PREDEF_TYPE_SAT_UACCUM_ID: |
| 6916 | T = Context.SatUnsignedAccumTy; |
| 6917 | break; |
| 6918 | case PREDEF_TYPE_SAT_ULONG_ACCUM_ID: |
| 6919 | T = Context.SatUnsignedLongAccumTy; |
| 6920 | break; |
| 6921 | case PREDEF_TYPE_SAT_SHORT_FRACT_ID: |
| 6922 | T = Context.SatShortFractTy; |
| 6923 | break; |
| 6924 | case PREDEF_TYPE_SAT_FRACT_ID: |
| 6925 | T = Context.SatFractTy; |
| 6926 | break; |
| 6927 | case PREDEF_TYPE_SAT_LONG_FRACT_ID: |
| 6928 | T = Context.SatLongFractTy; |
| 6929 | break; |
| 6930 | case PREDEF_TYPE_SAT_USHORT_FRACT_ID: |
| 6931 | T = Context.SatUnsignedShortFractTy; |
| 6932 | break; |
| 6933 | case PREDEF_TYPE_SAT_UFRACT_ID: |
| 6934 | T = Context.SatUnsignedFractTy; |
| 6935 | break; |
| 6936 | case PREDEF_TYPE_SAT_ULONG_FRACT_ID: |
| 6937 | T = Context.SatUnsignedLongFractTy; |
| 6938 | break; |
| Sjoerd Meijer | cc623ad | 2017-09-08 15:15:00 +0000 | [diff] [blame] | 6939 | case PREDEF_TYPE_FLOAT16_ID: |
| 6940 | T = Context.Float16Ty; |
| 6941 | break; |
| Nemanja Ivanovic | bb1ea2d | 2016-05-09 08:52:33 +0000 | [diff] [blame] | 6942 | case PREDEF_TYPE_FLOAT128_ID: |
| 6943 | T = Context.Float128Ty; |
| 6944 | break; |
| Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6945 | case PREDEF_TYPE_OVERLOAD_ID: |
| 6946 | T = Context.OverloadTy; |
| 6947 | break; |
| 6948 | case PREDEF_TYPE_BOUND_MEMBER: |
| 6949 | T = Context.BoundMemberTy; |
| 6950 | break; |
| 6951 | case PREDEF_TYPE_PSEUDO_OBJECT: |
| 6952 | T = Context.PseudoObjectTy; |
| 6953 | break; |
| 6954 | case PREDEF_TYPE_DEPENDENT_ID: |
| 6955 | T = Context.DependentTy; |
| 6956 | break; |
| 6957 | case PREDEF_TYPE_UNKNOWN_ANY: |
| 6958 | T = Context.UnknownAnyTy; |
| 6959 | break; |
| 6960 | case PREDEF_TYPE_NULLPTR_ID: |
| 6961 | T = Context.NullPtrTy; |
| 6962 | break; |
| Richard Smith | 3a8244d | 2018-05-01 05:02:45 +0000 | [diff] [blame] | 6963 | case PREDEF_TYPE_CHAR8_ID: |
| 6964 | T = Context.Char8Ty; |
| 6965 | break; |
| Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6966 | case PREDEF_TYPE_CHAR16_ID: |
| 6967 | T = Context.Char16Ty; |
| 6968 | break; |
| 6969 | case PREDEF_TYPE_CHAR32_ID: |
| 6970 | T = Context.Char32Ty; |
| 6971 | break; |
| 6972 | case PREDEF_TYPE_OBJC_ID: |
| 6973 | T = Context.ObjCBuiltinIdTy; |
| 6974 | break; |
| 6975 | case PREDEF_TYPE_OBJC_CLASS: |
| 6976 | T = Context.ObjCBuiltinClassTy; |
| 6977 | break; |
| 6978 | case PREDEF_TYPE_OBJC_SEL: |
| 6979 | T = Context.ObjCBuiltinSelTy; |
| 6980 | break; |
| Alexey Bader | 954ba21 | 2016-04-08 13:40:33 +0000 | [diff] [blame] | 6981 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 6982 | case PREDEF_TYPE_##Id##_ID: \ |
| 6983 | T = Context.SingletonId; \ |
| Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6984 | break; |
| Alexey Bader | b62f144 | 2016-04-13 08:33:41 +0000 | [diff] [blame] | 6985 | #include "clang/Basic/OpenCLImageTypes.def" |
| Andrew Savonichev | 3fee351 | 2018-11-08 11:25:41 +0000 | [diff] [blame] | 6986 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 6987 | case PREDEF_TYPE_##Id##_ID: \ |
| 6988 | T = Context.Id##Ty; \ |
| 6989 | break; |
| 6990 | #include "clang/Basic/OpenCLExtensionTypes.def" |
| Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 6991 | case PREDEF_TYPE_SAMPLER_ID: |
| 6992 | T = Context.OCLSamplerTy; |
| 6993 | break; |
| 6994 | case PREDEF_TYPE_EVENT_ID: |
| 6995 | T = Context.OCLEventTy; |
| 6996 | break; |
| Alexey Bader | 9c8453f | 2015-09-15 11:18:52 +0000 | [diff] [blame] | 6997 | case PREDEF_TYPE_CLK_EVENT_ID: |
| 6998 | T = Context.OCLClkEventTy; |
| 6999 | break; |
| 7000 | case PREDEF_TYPE_QUEUE_ID: |
| 7001 | T = Context.OCLQueueTy; |
| 7002 | break; |
| Alexey Bader | 9c8453f | 2015-09-15 11:18:52 +0000 | [diff] [blame] | 7003 | case PREDEF_TYPE_RESERVE_ID_ID: |
| 7004 | T = Context.OCLReserveIDTy; |
| 7005 | break; |
| Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 7006 | case PREDEF_TYPE_AUTO_DEDUCT: |
| 7007 | T = Context.getAutoDeductType(); |
| 7008 | break; |
| Alexey Bader | bdf7c84 | 2015-09-15 12:18:29 +0000 | [diff] [blame] | 7009 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
| 7010 | T = Context.getAutoRRefDeductType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7011 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7012 | case PREDEF_TYPE_ARC_UNBRIDGED_CAST: |
| 7013 | T = Context.ARCUnbridgedCastTy; |
| 7014 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7015 | case PREDEF_TYPE_BUILTIN_FN: |
| 7016 | T = Context.BuiltinFnTy; |
| 7017 | break; |
| Alexey Bataev | 1a3320e | 2015-08-25 14:24:04 +0000 | [diff] [blame] | 7018 | case PREDEF_TYPE_OMP_ARRAY_SECTION: |
| 7019 | T = Context.OMPArraySectionTy; |
| 7020 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7021 | } |
| 7022 | |
| 7023 | assert(!T.isNull() && "Unknown predefined type"); |
| 7024 | return T.withFastQualifiers(FastQuals); |
| 7025 | } |
| 7026 | |
| 7027 | Index -= NUM_PREDEF_TYPE_IDS; |
| 7028 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
| 7029 | if (TypesLoaded[Index].isNull()) { |
| 7030 | TypesLoaded[Index] = readTypeRecord(Index); |
| 7031 | if (TypesLoaded[Index].isNull()) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7032 | return QualType(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7033 | |
| 7034 | TypesLoaded[Index]->setFromAST(); |
| 7035 | if (DeserializationListener) |
| 7036 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
| 7037 | TypesLoaded[Index]); |
| 7038 | } |
| 7039 | |
| 7040 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
| 7041 | } |
| 7042 | |
| 7043 | QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) { |
| 7044 | return GetType(getGlobalTypeID(F, LocalID)); |
| 7045 | } |
| 7046 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7047 | serialization::TypeID |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7048 | ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const { |
| 7049 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 7050 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7051 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7052 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 7053 | return LocalID; |
| 7054 | |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 7055 | if (!F.ModuleOffsetMap.empty()) |
| 7056 | ReadModuleOffsetMap(F); |
| 7057 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7058 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 7059 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 7060 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7061 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7062 | unsigned GlobalIndex = LocalIndex + I->second; |
| 7063 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 7064 | } |
| 7065 | |
| 7066 | TemplateArgumentLocInfo |
| 7067 | ASTReader::GetTemplateArgumentLocInfo(ModuleFile &F, |
| 7068 | TemplateArgument::ArgKind Kind, |
| 7069 | const RecordData &Record, |
| 7070 | unsigned &Index) { |
| 7071 | switch (Kind) { |
| 7072 | case TemplateArgument::Expression: |
| 7073 | return ReadExpr(F); |
| 7074 | case TemplateArgument::Type: |
| 7075 | return GetTypeSourceInfo(F, Record, Index); |
| 7076 | case TemplateArgument::Template: { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7077 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7078 | Index); |
| 7079 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
| 7080 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
| 7081 | SourceLocation()); |
| 7082 | } |
| 7083 | case TemplateArgument::TemplateExpansion: { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7084 | NestedNameSpecifierLoc QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7085 | Index); |
| 7086 | SourceLocation TemplateNameLoc = ReadSourceLocation(F, Record, Index); |
| 7087 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Index); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7088 | return TemplateArgumentLocInfo(QualifierLoc, TemplateNameLoc, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7089 | EllipsisLoc); |
| 7090 | } |
| 7091 | case TemplateArgument::Null: |
| 7092 | case TemplateArgument::Integral: |
| 7093 | case TemplateArgument::Declaration: |
| 7094 | case TemplateArgument::NullPtr: |
| 7095 | case TemplateArgument::Pack: |
| 7096 | // FIXME: Is this right? |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7097 | return TemplateArgumentLocInfo(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7098 | } |
| 7099 | llvm_unreachable("unexpected template argument loc"); |
| 7100 | } |
| 7101 | |
| 7102 | TemplateArgumentLoc |
| 7103 | ASTReader::ReadTemplateArgumentLoc(ModuleFile &F, |
| 7104 | const RecordData &Record, unsigned &Index) { |
| 7105 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Index); |
| 7106 | |
| 7107 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 7108 | if (Record[Index++]) // bool InfoHasSameExpr. |
| 7109 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 7110 | } |
| 7111 | return TemplateArgumentLoc(Arg, GetTemplateArgumentLocInfo(F, Arg.getKind(), |
| 7112 | Record, Index)); |
| 7113 | } |
| 7114 | |
| Enea Zaffanella | 6dbe187 | 2013-08-10 07:24:53 +0000 | [diff] [blame] | 7115 | const ASTTemplateArgumentListInfo* |
| 7116 | ASTReader::ReadASTTemplateArgumentListInfo(ModuleFile &F, |
| 7117 | const RecordData &Record, |
| 7118 | unsigned &Index) { |
| 7119 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Index); |
| 7120 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Index); |
| 7121 | unsigned NumArgsAsWritten = Record[Index++]; |
| 7122 | TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); |
| 7123 | for (unsigned i = 0; i != NumArgsAsWritten; ++i) |
| 7124 | TemplArgsInfo.addArgument(ReadTemplateArgumentLoc(F, Record, Index)); |
| 7125 | return ASTTemplateArgumentListInfo::Create(getContext(), TemplArgsInfo); |
| 7126 | } |
| 7127 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7128 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
| 7129 | return GetDecl(ID); |
| 7130 | } |
| 7131 | |
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 7132 | void ASTReader::CompleteRedeclChain(const Decl *D) { |
| Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 7133 | if (NumCurrentElementsDeserializing) { |
| 7134 | // We arrange to not care about the complete redeclaration chain while we're |
| 7135 | // deserializing. Just remember that the AST has marked this one as complete |
| 7136 | // but that it's not actually complete yet, so we know we still need to |
| 7137 | // complete it later. |
| 7138 | PendingIncompleteDeclChains.push_back(const_cast<Decl*>(D)); |
| 7139 | return; |
| 7140 | } |
| 7141 | |
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 7142 | const DeclContext *DC = D->getDeclContext()->getRedeclContext(); |
| 7143 | |
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 7144 | // If this is a named declaration, complete it by looking it up |
| 7145 | // within its context. |
| 7146 | // |
| Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 7147 | // FIXME: Merging a function definition should merge |
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 7148 | // all mergeable entities within it. |
| 7149 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC) || |
| 7150 | isa<CXXRecordDecl>(DC) || isa<EnumDecl>(DC)) { |
| 7151 | if (DeclarationName Name = cast<NamedDecl>(D)->getDeclName()) { |
| Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 7152 | if (!getContext().getLangOpts().CPlusPlus && |
| 7153 | isa<TranslationUnitDecl>(DC)) { |
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 7154 | // 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] | 7155 | // the identifier instead. (For C++ modules, we don't store decls |
| 7156 | // in the serialized identifier table, so we do the lookup in the TU.) |
| 7157 | auto *II = Name.getAsIdentifierInfo(); |
| 7158 | assert(II && "non-identifier name in C?"); |
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 7159 | if (II->isOutOfDate()) |
| 7160 | updateOutOfDateIdentifier(*II); |
| 7161 | } else |
| 7162 | DC->lookup(Name); |
| Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 7163 | } else if (needsAnonymousDeclarationNumber(cast<NamedDecl>(D))) { |
| Richard Smith | 3cb1572 | 2015-08-05 22:41:45 +0000 | [diff] [blame] | 7164 | // Find all declarations of this kind from the relevant context. |
| 7165 | for (auto *DCDecl : cast<Decl>(D->getLexicalDeclContext())->redecls()) { |
| 7166 | auto *DC = cast<DeclContext>(DCDecl); |
| 7167 | SmallVector<Decl*, 8> Decls; |
| 7168 | FindExternalLexicalDecls( |
| 7169 | DC, [&](Decl::Kind K) { return K == D->getKind(); }, Decls); |
| 7170 | } |
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 7171 | } |
| 7172 | } |
| Richard Smith | 5089542 | 2015-01-31 03:04:55 +0000 | [diff] [blame] | 7173 | |
| 7174 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D)) |
| 7175 | CTSD->getSpecializedTemplate()->LoadLazySpecializations(); |
| 7176 | if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) |
| 7177 | VTSD->getSpecializedTemplate()->LoadLazySpecializations(); |
| 7178 | if (auto *FD = dyn_cast<FunctionDecl>(D)) { |
| 7179 | if (auto *Template = FD->getPrimaryTemplate()) |
| 7180 | Template->LoadLazySpecializations(); |
| 7181 | } |
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 7182 | } |
| 7183 | |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 7184 | CXXCtorInitializer ** |
| 7185 | ASTReader::GetExternalCXXCtorInitializers(uint64_t Offset) { |
| 7186 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 7187 | BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
| 7188 | SavedStreamPosition SavedPosition(Cursor); |
| 7189 | Cursor.JumpToBit(Loc.Offset); |
| 7190 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 7191 | |
| 7192 | RecordData Record; |
| 7193 | unsigned Code = Cursor.ReadCode(); |
| 7194 | unsigned RecCode = Cursor.readRecord(Code, Record); |
| 7195 | if (RecCode != DECL_CXX_CTOR_INITIALIZERS) { |
| 7196 | Error("malformed AST file: missing C++ ctor initializers"); |
| 7197 | return nullptr; |
| 7198 | } |
| 7199 | |
| 7200 | unsigned Idx = 0; |
| 7201 | return ReadCXXCtorInitializers(*Loc.F, Record, Idx); |
| 7202 | } |
| 7203 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7204 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 7205 | assert(ContextObj && "reading base specifiers with no AST context"); |
| 7206 | ASTContext &Context = *ContextObj; |
| 7207 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7208 | RecordLocation Loc = getLocalBitOffset(Offset); |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 7209 | BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7210 | SavedStreamPosition SavedPosition(Cursor); |
| 7211 | Cursor.JumpToBit(Loc.Offset); |
| 7212 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 7213 | RecordData Record; |
| 7214 | unsigned Code = Cursor.ReadCode(); |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 7215 | unsigned RecCode = Cursor.readRecord(Code, Record); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7216 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7217 | Error("malformed AST file: missing C++ base specifiers"); |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7218 | return nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7219 | } |
| 7220 | |
| 7221 | unsigned Idx = 0; |
| 7222 | unsigned NumBases = Record[Idx++]; |
| 7223 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7224 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7225 | for (unsigned I = 0; I != NumBases; ++I) |
| 7226 | Bases[I] = ReadCXXBaseSpecifier(*Loc.F, Record, Idx); |
| 7227 | return Bases; |
| 7228 | } |
| 7229 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7230 | serialization::DeclID |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7231 | ASTReader::getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const { |
| 7232 | if (LocalID < NUM_PREDEF_DECL_IDS) |
| 7233 | return LocalID; |
| 7234 | |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 7235 | if (!F.ModuleOffsetMap.empty()) |
| 7236 | ReadModuleOffsetMap(F); |
| 7237 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7238 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 7239 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
| 7240 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7241 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7242 | return LocalID + I->second; |
| 7243 | } |
| 7244 | |
| 7245 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
| 7246 | ModuleFile &M) const { |
| Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7247 | // Predefined decls aren't from any module. |
| 7248 | if (ID < NUM_PREDEF_DECL_IDS) |
| 7249 | return false; |
| 7250 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7251 | return ID - NUM_PREDEF_DECL_IDS >= M.BaseDeclID && |
| Richard Smith | bcda1a9 | 2015-07-12 23:51:20 +0000 | [diff] [blame] | 7252 | ID - NUM_PREDEF_DECL_IDS < M.BaseDeclID + M.LocalNumDecls; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7253 | } |
| 7254 | |
| Douglas Gregor | 9f78289 | 2013-01-21 15:25:38 +0000 | [diff] [blame] | 7255 | ModuleFile *ASTReader::getOwningModuleFile(const Decl *D) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7256 | if (!D->isFromASTFile()) |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7257 | return nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7258 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID()); |
| 7259 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 7260 | return I->second; |
| 7261 | } |
| 7262 | |
| 7263 | SourceLocation ASTReader::getSourceLocationForDeclID(GlobalDeclID ID) { |
| 7264 | if (ID < NUM_PREDEF_DECL_IDS) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7265 | return SourceLocation(); |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7266 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7267 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 7268 | |
| 7269 | if (Index > DeclsLoaded.size()) { |
| 7270 | Error("declaration ID out-of-range for AST file"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7271 | return SourceLocation(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7272 | } |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7273 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7274 | if (Decl *D = DeclsLoaded[Index]) |
| 7275 | return D->getLocation(); |
| 7276 | |
| Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 7277 | SourceLocation Loc; |
| 7278 | DeclCursorForID(ID, Loc); |
| 7279 | return Loc; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7280 | } |
| 7281 | |
| Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7282 | static Decl *getPredefinedDecl(ASTContext &Context, PredefinedDeclIDs ID) { |
| 7283 | switch (ID) { |
| 7284 | case PREDEF_DECL_NULL_ID: |
| 7285 | return nullptr; |
| 7286 | |
| 7287 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
| 7288 | return Context.getTranslationUnitDecl(); |
| 7289 | |
| 7290 | case PREDEF_DECL_OBJC_ID_ID: |
| 7291 | return Context.getObjCIdDecl(); |
| 7292 | |
| 7293 | case PREDEF_DECL_OBJC_SEL_ID: |
| 7294 | return Context.getObjCSelDecl(); |
| 7295 | |
| 7296 | case PREDEF_DECL_OBJC_CLASS_ID: |
| 7297 | return Context.getObjCClassDecl(); |
| 7298 | |
| 7299 | case PREDEF_DECL_OBJC_PROTOCOL_ID: |
| 7300 | return Context.getObjCProtocolDecl(); |
| 7301 | |
| 7302 | case PREDEF_DECL_INT_128_ID: |
| 7303 | return Context.getInt128Decl(); |
| 7304 | |
| 7305 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
| 7306 | return Context.getUInt128Decl(); |
| 7307 | |
| 7308 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
| 7309 | return Context.getObjCInstanceTypeDecl(); |
| 7310 | |
| 7311 | case PREDEF_DECL_BUILTIN_VA_LIST_ID: |
| 7312 | return Context.getBuiltinVaListDecl(); |
| Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 7313 | |
| Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 7314 | case PREDEF_DECL_VA_LIST_TAG: |
| 7315 | return Context.getVaListTagDecl(); |
| 7316 | |
| Charles Davis | c7d5c94 | 2015-09-17 20:55:33 +0000 | [diff] [blame] | 7317 | case PREDEF_DECL_BUILTIN_MS_VA_LIST_ID: |
| 7318 | return Context.getBuiltinMSVaListDecl(); |
| 7319 | |
| Richard Smith | f19e127 | 2015-03-07 00:04:49 +0000 | [diff] [blame] | 7320 | case PREDEF_DECL_EXTERN_C_CONTEXT_ID: |
| 7321 | return Context.getExternCContextDecl(); |
| David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 7322 | |
| 7323 | case PREDEF_DECL_MAKE_INTEGER_SEQ_ID: |
| 7324 | return Context.getMakeIntegerSeqDecl(); |
| Quentin Colombet | 043406b | 2016-02-03 22:41:00 +0000 | [diff] [blame] | 7325 | |
| 7326 | case PREDEF_DECL_CF_CONSTANT_STRING_ID: |
| 7327 | return Context.getCFConstantStringDecl(); |
| Ben Langmuir | f541674 | 2016-02-04 00:55:24 +0000 | [diff] [blame] | 7328 | |
| 7329 | case PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID: |
| 7330 | return Context.getCFConstantStringTagDecl(); |
| Eric Fiselier | 6ad6855 | 2016-07-01 01:24:09 +0000 | [diff] [blame] | 7331 | |
| 7332 | case PREDEF_DECL_TYPE_PACK_ELEMENT_ID: |
| 7333 | return Context.getTypePackElementDecl(); |
| Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7334 | } |
| Yaron Keren | 322bdad | 2015-03-06 07:49:14 +0000 | [diff] [blame] | 7335 | llvm_unreachable("PredefinedDeclIDs unknown enum value"); |
| Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7336 | } |
| 7337 | |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7338 | Decl *ASTReader::GetExistingDecl(DeclID ID) { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 7339 | assert(ContextObj && "reading decl with no AST context"); |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7340 | if (ID < NUM_PREDEF_DECL_IDS) { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 7341 | Decl *D = getPredefinedDecl(*ContextObj, (PredefinedDeclIDs)ID); |
| Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7342 | if (D) { |
| 7343 | // Track that we have merged the declaration with ID \p ID into the |
| 7344 | // pre-existing predefined declaration \p D. |
| Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 7345 | auto &Merged = KeyDecls[D->getCanonicalDecl()]; |
| Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7346 | if (Merged.empty()) |
| 7347 | Merged.push_back(ID); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7348 | } |
| Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 7349 | return D; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7350 | } |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7351 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7352 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 7353 | |
| 7354 | if (Index >= DeclsLoaded.size()) { |
| 7355 | assert(0 && "declaration ID out-of-range for AST file"); |
| 7356 | Error("declaration ID out-of-range for AST file"); |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7357 | return nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7358 | } |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7359 | |
| 7360 | return DeclsLoaded[Index]; |
| 7361 | } |
| 7362 | |
| 7363 | Decl *ASTReader::GetDecl(DeclID ID) { |
| 7364 | if (ID < NUM_PREDEF_DECL_IDS) |
| 7365 | return GetExistingDecl(ID); |
| 7366 | |
| 7367 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 7368 | |
| 7369 | if (Index >= DeclsLoaded.size()) { |
| 7370 | assert(0 && "declaration ID out-of-range for AST file"); |
| 7371 | Error("declaration ID out-of-range for AST file"); |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7372 | return nullptr; |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7373 | } |
| 7374 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7375 | if (!DeclsLoaded[Index]) { |
| 7376 | ReadDeclRecord(ID); |
| 7377 | if (DeserializationListener) |
| 7378 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 7379 | } |
| 7380 | |
| 7381 | return DeclsLoaded[Index]; |
| 7382 | } |
| 7383 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7384 | DeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile &M, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7385 | DeclID GlobalID) { |
| 7386 | if (GlobalID < NUM_PREDEF_DECL_IDS) |
| 7387 | return GlobalID; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7388 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7389 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID); |
| 7390 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 7391 | ModuleFile *Owner = I->second; |
| 7392 | |
| 7393 | llvm::DenseMap<ModuleFile *, serialization::DeclID>::iterator Pos |
| 7394 | = M.GlobalToLocalDeclIDs.find(Owner); |
| 7395 | if (Pos == M.GlobalToLocalDeclIDs.end()) |
| 7396 | return 0; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7397 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7398 | return GlobalID - Owner->BaseDeclID + Pos->second; |
| 7399 | } |
| 7400 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7401 | serialization::DeclID ASTReader::ReadDeclID(ModuleFile &F, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7402 | const RecordData &Record, |
| 7403 | unsigned &Idx) { |
| 7404 | if (Idx >= Record.size()) { |
| 7405 | Error("Corrupted AST file"); |
| 7406 | return 0; |
| 7407 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7408 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7409 | return getGlobalDeclID(F, Record[Idx++]); |
| 7410 | } |
| 7411 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 7412 | /// Resolve the offset of a statement into a statement. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7413 | /// |
| 7414 | /// This operation will read a new statement from the external |
| 7415 | /// source each time it is called, and is meant to be used via a |
| 7416 | /// LazyOffsetPtr (which is used by Decls for the body of functions, etc). |
| 7417 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
| 7418 | // Switch case IDs are per Decl. |
| 7419 | ClearSwitchCaseIDs(); |
| 7420 | |
| 7421 | // Offset here is a global offset across the entire chain. |
| 7422 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 7423 | Loc.F->DeclsCursor.JumpToBit(Loc.Offset); |
| David Blaikie | 9fd16f8 | 2017-03-08 23:57:08 +0000 | [diff] [blame] | 7424 | assert(NumCurrentElementsDeserializing == 0 && |
| 7425 | "should not be called while already deserializing"); |
| 7426 | Deserializing D(this); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7427 | return ReadStmtFromStream(*Loc.F); |
| 7428 | } |
| 7429 | |
| Richard Smith | 3cb1572 | 2015-08-05 22:41:45 +0000 | [diff] [blame] | 7430 | void ASTReader::FindExternalLexicalDecls( |
| 7431 | const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, |
| 7432 | SmallVectorImpl<Decl *> &Decls) { |
| Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7433 | bool PredefsVisited[NUM_PREDEF_DECL_IDS] = {}; |
| 7434 | |
| Richard Smith | 9ccdd93 | 2015-08-06 22:14:12 +0000 | [diff] [blame] | 7435 | auto Visit = [&] (ModuleFile *M, LexicalContents LexicalDecls) { |
| Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7436 | assert(LexicalDecls.size() % 2 == 0 && "expected an even number of entries"); |
| 7437 | for (int I = 0, N = LexicalDecls.size(); I != N; I += 2) { |
| 7438 | auto K = (Decl::Kind)+LexicalDecls[I]; |
| 7439 | if (!IsKindWeWant(K)) |
| 7440 | continue; |
| 7441 | |
| 7442 | auto ID = (serialization::DeclID)+LexicalDecls[I + 1]; |
| 7443 | |
| 7444 | // Don't add predefined declarations to the lexical context more |
| 7445 | // than once. |
| 7446 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 7447 | if (PredefsVisited[ID]) |
| 7448 | continue; |
| 7449 | |
| 7450 | PredefsVisited[ID] = true; |
| 7451 | } |
| 7452 | |
| 7453 | if (Decl *D = GetLocalDecl(*M, ID)) { |
| Richard Smith | 2317a3e | 2015-08-11 21:21:20 +0000 | [diff] [blame] | 7454 | assert(D->getKind() == K && "wrong kind for lexical decl"); |
| Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7455 | if (!DC->isDeclInLexicalTraversal(D)) |
| 7456 | Decls.push_back(D); |
| 7457 | } |
| 7458 | } |
| 7459 | }; |
| 7460 | |
| 7461 | if (isa<TranslationUnitDecl>(DC)) { |
| 7462 | for (auto Lexical : TULexicalDecls) |
| 7463 | Visit(Lexical.first, Lexical.second); |
| 7464 | } else { |
| 7465 | auto I = LexicalDecls.find(DC); |
| 7466 | if (I != LexicalDecls.end()) |
| Richard Smith | 9c9173d | 2015-08-11 22:00:24 +0000 | [diff] [blame] | 7467 | Visit(I->second.first, I->second.second); |
| Richard Smith | 82f8fcd | 2015-08-06 22:07:25 +0000 | [diff] [blame] | 7468 | } |
| 7469 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7470 | ++NumLexicalDeclContextsRead; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7471 | } |
| 7472 | |
| 7473 | namespace { |
| 7474 | |
| 7475 | class DeclIDComp { |
| 7476 | ASTReader &Reader; |
| 7477 | ModuleFile &Mod; |
| 7478 | |
| 7479 | public: |
| 7480 | DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {} |
| 7481 | |
| 7482 | bool operator()(LocalDeclID L, LocalDeclID R) const { |
| 7483 | SourceLocation LHS = getLocation(L); |
| 7484 | SourceLocation RHS = getLocation(R); |
| 7485 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7486 | } |
| 7487 | |
| 7488 | bool operator()(SourceLocation LHS, LocalDeclID R) const { |
| 7489 | SourceLocation RHS = getLocation(R); |
| 7490 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7491 | } |
| 7492 | |
| 7493 | bool operator()(LocalDeclID L, SourceLocation RHS) const { |
| 7494 | SourceLocation LHS = getLocation(L); |
| 7495 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7496 | } |
| 7497 | |
| 7498 | SourceLocation getLocation(LocalDeclID ID) const { |
| 7499 | return Reader.getSourceManager().getFileLoc( |
| 7500 | Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID))); |
| 7501 | } |
| 7502 | }; |
| 7503 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7504 | } // namespace |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7505 | |
| 7506 | void ASTReader::FindFileRegionDecls(FileID File, |
| 7507 | unsigned Offset, unsigned Length, |
| 7508 | SmallVectorImpl<Decl *> &Decls) { |
| 7509 | SourceManager &SM = getSourceManager(); |
| 7510 | |
| 7511 | llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File); |
| 7512 | if (I == FileDeclIDs.end()) |
| 7513 | return; |
| 7514 | |
| 7515 | FileDeclsInfo &DInfo = I->second; |
| 7516 | if (DInfo.Decls.empty()) |
| 7517 | return; |
| 7518 | |
| 7519 | SourceLocation |
| 7520 | BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset); |
| 7521 | SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length); |
| 7522 | |
| 7523 | DeclIDComp DIDComp(*this, *DInfo.Mod); |
| 7524 | ArrayRef<serialization::LocalDeclID>::iterator |
| 7525 | BeginIt = std::lower_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 7526 | BeginLoc, DIDComp); |
| 7527 | if (BeginIt != DInfo.Decls.begin()) |
| 7528 | --BeginIt; |
| 7529 | |
| 7530 | // If we are pointing at a top-level decl inside an objc container, we need |
| 7531 | // to backtrack until we find it otherwise we will fail to report that the |
| 7532 | // region overlaps with an objc container. |
| 7533 | while (BeginIt != DInfo.Decls.begin() && |
| 7534 | GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt)) |
| 7535 | ->isTopLevelDeclInObjCContainer()) |
| 7536 | --BeginIt; |
| 7537 | |
| 7538 | ArrayRef<serialization::LocalDeclID>::iterator |
| 7539 | EndIt = std::upper_bound(DInfo.Decls.begin(), DInfo.Decls.end(), |
| 7540 | EndLoc, DIDComp); |
| 7541 | if (EndIt != DInfo.Decls.end()) |
| 7542 | ++EndIt; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7543 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7544 | for (ArrayRef<serialization::LocalDeclID>::iterator |
| 7545 | DIt = BeginIt; DIt != EndIt; ++DIt) |
| 7546 | Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt))); |
| 7547 | } |
| 7548 | |
| Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 7549 | bool |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7550 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
| 7551 | DeclarationName Name) { |
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7552 | assert(DC->hasExternalVisibleStorage() && DC == DC->getPrimaryContext() && |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7553 | "DeclContext has no visible decls in storage"); |
| 7554 | if (!Name) |
| Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 7555 | return false; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7556 | |
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7557 | auto It = Lookups.find(DC); |
| 7558 | if (It == Lookups.end()) |
| 7559 | return false; |
| 7560 | |
| Richard Smith | 8c913ec | 2014-08-14 02:21:01 +0000 | [diff] [blame] | 7561 | Deserializing LookupResults(this); |
| 7562 | |
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7563 | // Load the list of declarations. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7564 | SmallVector<NamedDecl *, 64> Decls; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7565 | for (DeclID ID : It->second.Table.find(Name)) { |
| 7566 | NamedDecl *ND = cast<NamedDecl>(GetDecl(ID)); |
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7567 | if (ND->getDeclName() == Name) |
| 7568 | Decls.push_back(ND); |
| 7569 | } |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 7570 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7571 | ++NumVisibleDeclContextsRead; |
| 7572 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
| Richard Smith | 9ce12e3 | 2013-02-07 03:30:24 +0000 | [diff] [blame] | 7573 | return !Decls.empty(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7574 | } |
| 7575 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7576 | void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) { |
| 7577 | if (!DC->hasExternalVisibleStorage()) |
| 7578 | return; |
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7579 | |
| 7580 | auto It = Lookups.find(DC); |
| 7581 | assert(It != Lookups.end() && |
| 7582 | "have external visible storage but no lookup tables"); |
| 7583 | |
| Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 7584 | DeclsMap Decls; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7585 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7586 | for (DeclID ID : It->second.Table.findAll()) { |
| 7587 | NamedDecl *ND = cast<NamedDecl>(GetDecl(ID)); |
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7588 | Decls[ND->getDeclName()].push_back(ND); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7589 | } |
| 7590 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7591 | ++NumVisibleDeclContextsRead; |
| 7592 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7593 | for (DeclsMap::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) { |
| 7594 | SetExternalVisibleDeclsForName(DC, I->first, I->second); |
| 7595 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7596 | const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false); |
| 7597 | } |
| 7598 | |
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 7599 | const serialization::reader::DeclContextLookupTable * |
| 7600 | ASTReader::getLoadedLookupTables(DeclContext *Primary) const { |
| 7601 | auto I = Lookups.find(Primary); |
| 7602 | return I == Lookups.end() ? nullptr : &I->second; |
| 7603 | } |
| 7604 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 7605 | /// Under non-PCH compilation the consumer receives the objc methods |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7606 | /// before receiving the implementation, and codegen depends on this. |
| 7607 | /// We simulate this by deserializing and passing to consumer the methods of the |
| 7608 | /// implementation before passing the deserialized implementation decl. |
| 7609 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 7610 | ASTConsumer *Consumer) { |
| 7611 | assert(ImplD && Consumer); |
| 7612 | |
| Aaron Ballman | aff18c0 | 2014-03-13 19:03:34 +0000 | [diff] [blame] | 7613 | for (auto *I : ImplD->methods()) |
| 7614 | Consumer->HandleInterestingDecl(DeclGroupRef(I)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7615 | |
| 7616 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 7617 | } |
| 7618 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7619 | void ASTReader::PassInterestingDeclToConsumer(Decl *D) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7620 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7621 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 7622 | else |
| 7623 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
| 7624 | } |
| 7625 | |
| 7626 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
| 7627 | this->Consumer = Consumer; |
| 7628 | |
| Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 7629 | if (Consumer) |
| 7630 | PassInterestingDeclsToConsumer(); |
| Richard Smith | 7f330cd | 2015-03-18 01:42:29 +0000 | [diff] [blame] | 7631 | |
| 7632 | if (DeserializationListener) |
| 7633 | DeserializationListener->ReaderInitialized(this); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7634 | } |
| 7635 | |
| 7636 | void ASTReader::PrintStats() { |
| 7637 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
| 7638 | |
| 7639 | unsigned NumTypesLoaded |
| 7640 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
| 7641 | QualType()); |
| 7642 | unsigned NumDeclsLoaded |
| 7643 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7644 | (Decl *)nullptr); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7645 | unsigned NumIdentifiersLoaded |
| 7646 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 7647 | IdentifiersLoaded.end(), |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7648 | (IdentifierInfo *)nullptr); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7649 | unsigned NumMacrosLoaded |
| 7650 | = MacrosLoaded.size() - std::count(MacrosLoaded.begin(), |
| 7651 | MacrosLoaded.end(), |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 7652 | (MacroInfo *)nullptr); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7653 | unsigned NumSelectorsLoaded |
| 7654 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 7655 | SelectorsLoaded.end(), |
| 7656 | Selector()); |
| 7657 | |
| 7658 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
| 7659 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 7660 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 7661 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
| 7662 | if (!TypesLoaded.empty()) |
| 7663 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
| 7664 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 7665 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 7666 | if (!DeclsLoaded.empty()) |
| 7667 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
| 7668 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 7669 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
| 7670 | if (!IdentifiersLoaded.empty()) |
| 7671 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
| 7672 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 7673 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
| 7674 | if (!MacrosLoaded.empty()) |
| 7675 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 7676 | NumMacrosLoaded, (unsigned)MacrosLoaded.size(), |
| 7677 | ((float)NumMacrosLoaded/MacrosLoaded.size() * 100)); |
| 7678 | if (!SelectorsLoaded.empty()) |
| 7679 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
| 7680 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 7681 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
| 7682 | if (TotalNumStatements) |
| 7683 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 7684 | NumStatementsRead, TotalNumStatements, |
| 7685 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 7686 | if (TotalNumMacros) |
| 7687 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 7688 | NumMacrosRead, TotalNumMacros, |
| 7689 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 7690 | if (TotalLexicalDeclContexts) |
| 7691 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 7692 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 7693 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 7694 | * 100)); |
| 7695 | if (TotalVisibleDeclContexts) |
| 7696 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 7697 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 7698 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 7699 | * 100)); |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7700 | if (TotalNumMethodPoolEntries) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7701 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
| 7702 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 7703 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
| 7704 | * 100)); |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7705 | if (NumMethodPoolLookups) |
| Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7706 | std::fprintf(stderr, " %u/%u method pool lookups succeeded (%f%%)\n", |
| 7707 | NumMethodPoolHits, NumMethodPoolLookups, |
| 7708 | ((float)NumMethodPoolHits/NumMethodPoolLookups * 100.0)); |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7709 | if (NumMethodPoolTableLookups) |
| Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 7710 | std::fprintf(stderr, " %u/%u method pool table lookups succeeded (%f%%)\n", |
| 7711 | NumMethodPoolTableHits, NumMethodPoolTableLookups, |
| 7712 | ((float)NumMethodPoolTableHits/NumMethodPoolTableLookups |
| 7713 | * 100.0)); |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7714 | if (NumIdentifierLookupHits) |
| Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 7715 | std::fprintf(stderr, |
| 7716 | " %u / %u identifier table lookups succeeded (%f%%)\n", |
| 7717 | NumIdentifierLookupHits, NumIdentifierLookups, |
| 7718 | (double)NumIdentifierLookupHits*100.0/NumIdentifierLookups); |
| Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 7719 | |
| Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 7720 | if (GlobalIndex) { |
| 7721 | std::fprintf(stderr, "\n"); |
| 7722 | GlobalIndex->printStats(); |
| 7723 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7724 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7725 | std::fprintf(stderr, "\n"); |
| 7726 | dump(); |
| 7727 | std::fprintf(stderr, "\n"); |
| 7728 | } |
| 7729 | |
| 7730 | template<typename Key, typename ModuleFile, unsigned InitialCapacity> |
| Vassil Vassilev | b271068 | 2017-03-02 18:13:19 +0000 | [diff] [blame] | 7731 | LLVM_DUMP_METHOD static void |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7732 | dumpModuleIDMap(StringRef Name, |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7733 | const ContinuousRangeMap<Key, ModuleFile *, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7734 | InitialCapacity> &Map) { |
| 7735 | if (Map.begin() == Map.end()) |
| 7736 | return; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7737 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7738 | using MapType = ContinuousRangeMap<Key, ModuleFile *, InitialCapacity>; |
| 7739 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7740 | llvm::errs() << Name << ":\n"; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7741 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 7742 | I != IEnd; ++I) { |
| 7743 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 7744 | << "\n"; |
| 7745 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7746 | } |
| 7747 | |
| Yaron Keren | cdae941 | 2016-01-29 19:38:18 +0000 | [diff] [blame] | 7748 | LLVM_DUMP_METHOD void ASTReader::dump() { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7749 | llvm::errs() << "*** PCH/ModuleFile Remappings:\n"; |
| 7750 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
| 7751 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
| 7752 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
| 7753 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
| 7754 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
| 7755 | dumpModuleIDMap("Global macro map", GlobalMacroMap); |
| 7756 | dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap); |
| 7757 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7758 | dumpModuleIDMap("Global preprocessed entity map", |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7759 | GlobalPreprocessedEntityMap); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 7760 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7761 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7762 | for (ModuleFile &M : ModuleMgr) |
| Duncan P. N. Exon Smith | 96a06e0 | 2017-01-28 22:15:22 +0000 | [diff] [blame] | 7763 | M.dump(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7764 | } |
| 7765 | |
| 7766 | /// Return the amount of memory used by memory buffers, breaking down |
| 7767 | /// by heap-backed versus mmap'ed memory. |
| 7768 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7769 | for (ModuleFile &I : ModuleMgr) { |
| Duncan P. N. Exon Smith | 030d7d6 | 2017-03-20 17:58:26 +0000 | [diff] [blame] | 7770 | if (llvm::MemoryBuffer *buf = I.Buffer) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7771 | size_t bytes = buf->getBufferSize(); |
| 7772 | switch (buf->getBufferKind()) { |
| 7773 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 7774 | sizes.malloc_bytes += bytes; |
| 7775 | break; |
| 7776 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 7777 | sizes.mmap_bytes += bytes; |
| 7778 | break; |
| 7779 | } |
| 7780 | } |
| 7781 | } |
| 7782 | } |
| 7783 | |
| 7784 | void ASTReader::InitializeSema(Sema &S) { |
| 7785 | SemaObj = &S; |
| 7786 | S.addExternalSource(this); |
| 7787 | |
| 7788 | // Makes sure any declarations that were deserialized "too early" |
| 7789 | // still get added to the identifier's declaration chains. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7790 | for (uint64_t ID : PreloadedDeclIDs) { |
| 7791 | NamedDecl *D = cast<NamedDecl>(GetDecl(ID)); |
| Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7792 | pushExternalDeclIntoScope(D, D->getDeclName()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7793 | } |
| Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 7794 | PreloadedDeclIDs.clear(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7795 | |
| Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7796 | // FIXME: What happens if these are changed by a module import? |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7797 | if (!FPPragmaOptions.empty()) { |
| 7798 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| Adam Nemet | 484aa45 | 2017-03-27 19:17:25 +0000 | [diff] [blame] | 7799 | SemaObj->FPFeatures = FPOptions(FPPragmaOptions[0]); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7800 | } |
| 7801 | |
| Yaxun Liu | 5b74665 | 2016-12-18 05:18:55 +0000 | [diff] [blame] | 7802 | SemaObj->OpenCLFeatures.copy(OpenCLExtensions); |
| 7803 | SemaObj->OpenCLTypeExtMap = OpenCLTypeExtMap; |
| 7804 | SemaObj->OpenCLDeclExtMap = OpenCLDeclExtMap; |
| Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7805 | |
| 7806 | UpdateSema(); |
| 7807 | } |
| 7808 | |
| 7809 | void ASTReader::UpdateSema() { |
| 7810 | assert(SemaObj && "no Sema to update"); |
| 7811 | |
| 7812 | // Load the offsets of the declarations that Sema references. |
| 7813 | // They will be lazily deserialized when needed. |
| 7814 | if (!SemaDeclRefs.empty()) { |
| Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 7815 | assert(SemaDeclRefs.size() % 3 == 0); |
| 7816 | for (unsigned I = 0; I != SemaDeclRefs.size(); I += 3) { |
| Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7817 | if (!SemaObj->StdNamespace) |
| 7818 | SemaObj->StdNamespace = SemaDeclRefs[I]; |
| 7819 | if (!SemaObj->StdBadAlloc) |
| 7820 | SemaObj->StdBadAlloc = SemaDeclRefs[I+1]; |
| Richard Smith | 96269c5 | 2016-09-29 22:49:46 +0000 | [diff] [blame] | 7821 | if (!SemaObj->StdAlignValT) |
| 7822 | SemaObj->StdAlignValT = SemaDeclRefs[I+2]; |
| Richard Smith | 3d8e97e | 2013-10-18 06:54:39 +0000 | [diff] [blame] | 7823 | } |
| 7824 | SemaDeclRefs.clear(); |
| 7825 | } |
| Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 7826 | |
| Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 7827 | // Update the state of pragmas. Use the same API as if we had encountered the |
| 7828 | // pragma in the source. |
| Dario Domizioli | 13a0a38 | 2014-05-23 12:13:25 +0000 | [diff] [blame] | 7829 | if(OptimizeOffPragmaLocation.isValid()) |
| 7830 | SemaObj->ActOnPragmaOptimize(/* IsOn = */ false, OptimizeOffPragmaLocation); |
| Nico Weber | 779355f | 2016-03-02 23:22:00 +0000 | [diff] [blame] | 7831 | if (PragmaMSStructState != -1) |
| 7832 | SemaObj->ActOnPragmaMSStruct((PragmaMSStructKind)PragmaMSStructState); |
| Nico Weber | 4293231 | 2016-03-03 00:17:35 +0000 | [diff] [blame] | 7833 | if (PointersToMembersPragmaLocation.isValid()) { |
| 7834 | SemaObj->ActOnPragmaMSPointersToMembers( |
| 7835 | (LangOptions::PragmaMSPointersToMembersKind) |
| 7836 | PragmaMSPointersToMembersState, |
| 7837 | PointersToMembersPragmaLocation); |
| 7838 | } |
| Justin Lebar | 67a78a6 | 2016-10-08 22:15:58 +0000 | [diff] [blame] | 7839 | SemaObj->ForceCUDAHostDeviceDepth = ForceCUDAHostDeviceDepth; |
| Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 7840 | |
| 7841 | if (PragmaPackCurrentValue) { |
| 7842 | // The bottom of the stack might have a default value. It must be adjusted |
| 7843 | // to the current value to ensure that the packing state is preserved after |
| 7844 | // popping entries that were included/imported from a PCH/module. |
| 7845 | bool DropFirst = false; |
| 7846 | if (!PragmaPackStack.empty() && |
| 7847 | PragmaPackStack.front().Location.isInvalid()) { |
| 7848 | assert(PragmaPackStack.front().Value == SemaObj->PackStack.DefaultValue && |
| 7849 | "Expected a default alignment value"); |
| 7850 | SemaObj->PackStack.Stack.emplace_back( |
| 7851 | PragmaPackStack.front().SlotLabel, SemaObj->PackStack.CurrentValue, |
| Alex Lorenz | 45b4014 | 2017-07-28 14:41:21 +0000 | [diff] [blame] | 7852 | SemaObj->PackStack.CurrentPragmaLocation, |
| 7853 | PragmaPackStack.front().PushLocation); |
| Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 7854 | DropFirst = true; |
| 7855 | } |
| 7856 | for (const auto &Entry : |
| 7857 | llvm::makeArrayRef(PragmaPackStack).drop_front(DropFirst ? 1 : 0)) |
| 7858 | SemaObj->PackStack.Stack.emplace_back(Entry.SlotLabel, Entry.Value, |
| Alex Lorenz | 45b4014 | 2017-07-28 14:41:21 +0000 | [diff] [blame] | 7859 | Entry.Location, Entry.PushLocation); |
| Alex Lorenz | 7d7e1e0 | 2017-03-31 15:36:21 +0000 | [diff] [blame] | 7860 | if (PragmaPackCurrentLocation.isInvalid()) { |
| 7861 | assert(*PragmaPackCurrentValue == SemaObj->PackStack.DefaultValue && |
| 7862 | "Expected a default alignment value"); |
| 7863 | // Keep the current values. |
| 7864 | } else { |
| 7865 | SemaObj->PackStack.CurrentValue = *PragmaPackCurrentValue; |
| 7866 | SemaObj->PackStack.CurrentPragmaLocation = PragmaPackCurrentLocation; |
| 7867 | } |
| 7868 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7869 | } |
| 7870 | |
| Richard Smith | a8d5b6a | 2015-07-17 19:51:03 +0000 | [diff] [blame] | 7871 | IdentifierInfo *ASTReader::get(StringRef Name) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7872 | // Note that we are loading an identifier. |
| 7873 | Deserializing AnIdentifier(this); |
| Douglas Gregor | e060e57 | 2013-01-25 01:03:03 +0000 | [diff] [blame] | 7874 | |
| Douglas Gregor | 7211ac1 | 2013-01-25 23:32:03 +0000 | [diff] [blame] | 7875 | IdentifierLookupVisitor Visitor(Name, /*PriorGeneration=*/0, |
| Douglas Gregor | 00a50f7 | 2013-01-25 00:38:33 +0000 | [diff] [blame] | 7876 | NumIdentifierLookups, |
| 7877 | NumIdentifierLookupHits); |
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7878 | |
| 7879 | // We don't need to do identifier table lookups in C++ modules (we preload |
| 7880 | // all interesting declarations, and don't need to use the scope for name |
| 7881 | // lookups). Perform the lookup in PCH files, though, since we don't build |
| 7882 | // 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] | 7883 | if (PP.getLangOpts().CPlusPlus) { |
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7884 | for (auto F : ModuleMgr.pch_modules()) |
| Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7885 | if (Visitor(*F)) |
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7886 | break; |
| 7887 | } else { |
| 7888 | // If there is a global index, look there first to determine which modules |
| 7889 | // provably do not have any results for this identifier. |
| 7890 | GlobalModuleIndex::HitSet Hits; |
| 7891 | GlobalModuleIndex::HitSet *HitsPtr = nullptr; |
| 7892 | if (!loadGlobalIndex()) { |
| 7893 | if (GlobalIndex->lookupIdentifier(Name, Hits)) { |
| 7894 | HitsPtr = &Hits; |
| 7895 | } |
| 7896 | } |
| 7897 | |
| Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 7898 | ModuleMgr.visit(Visitor, HitsPtr); |
| Richard Smith | 33e0f7e | 2015-07-22 02:08:40 +0000 | [diff] [blame] | 7899 | } |
| 7900 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7901 | IdentifierInfo *II = Visitor.getIdentifierInfo(); |
| 7902 | markIdentifierUpToDate(II); |
| 7903 | return II; |
| 7904 | } |
| 7905 | |
| 7906 | namespace clang { |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7907 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 7908 | /// An identifier-lookup iterator that enumerates all of the |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7909 | /// identifiers stored within a set of AST files. |
| 7910 | class ASTIdentifierIterator : public IdentifierIterator { |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 7911 | /// The AST reader whose identifiers are being enumerated. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7912 | const ASTReader &Reader; |
| 7913 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 7914 | /// The current index into the chain of AST files stored in |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7915 | /// the AST reader. |
| 7916 | unsigned Index; |
| 7917 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 7918 | /// The current position within the identifier lookup table |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7919 | /// of the current AST file. |
| 7920 | ASTIdentifierLookupTable::key_iterator Current; |
| 7921 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 7922 | /// The end position within the identifier lookup table of |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7923 | /// the current AST file. |
| 7924 | ASTIdentifierLookupTable::key_iterator End; |
| 7925 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 7926 | /// Whether to skip any modules in the ASTReader. |
| Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7927 | bool SkipModules; |
| 7928 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7929 | public: |
| Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7930 | explicit ASTIdentifierIterator(const ASTReader &Reader, |
| 7931 | bool SkipModules = false); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7932 | |
| Craig Topper | 3e89dfe | 2014-03-13 02:13:41 +0000 | [diff] [blame] | 7933 | StringRef Next() override; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7934 | }; |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7935 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7936 | } // namespace clang |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7937 | |
| Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7938 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader, |
| 7939 | bool SkipModules) |
| 7940 | : Reader(Reader), Index(Reader.ModuleMgr.size()), SkipModules(SkipModules) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7941 | } |
| 7942 | |
| 7943 | StringRef ASTIdentifierIterator::Next() { |
| 7944 | while (Current == End) { |
| 7945 | // If we have exhausted all of our AST files, we're done. |
| 7946 | if (Index == 0) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7947 | return StringRef(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7948 | |
| 7949 | --Index; |
| Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7950 | ModuleFile &F = Reader.ModuleMgr[Index]; |
| 7951 | if (SkipModules && F.isModule()) |
| 7952 | continue; |
| 7953 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7954 | ASTIdentifierLookupTable *IdTable = |
| 7955 | (ASTIdentifierLookupTable *)F.IdentifierLookupTable; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7956 | Current = IdTable->key_begin(); |
| 7957 | End = IdTable->key_end(); |
| 7958 | } |
| 7959 | |
| 7960 | // We have any identifiers remaining in the current AST file; return |
| 7961 | // the next one. |
| Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 7962 | StringRef Result = *Current; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7963 | ++Current; |
| Douglas Gregor | bfd73d7 | 2013-01-23 18:53:14 +0000 | [diff] [blame] | 7964 | return Result; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 7965 | } |
| 7966 | |
| Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7967 | namespace { |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7968 | |
| Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7969 | /// A utility for appending two IdentifierIterators. |
| 7970 | class ChainedIdentifierIterator : public IdentifierIterator { |
| 7971 | std::unique_ptr<IdentifierIterator> Current; |
| 7972 | std::unique_ptr<IdentifierIterator> Queued; |
| 7973 | |
| 7974 | public: |
| 7975 | ChainedIdentifierIterator(std::unique_ptr<IdentifierIterator> First, |
| 7976 | std::unique_ptr<IdentifierIterator> Second) |
| 7977 | : Current(std::move(First)), Queued(std::move(Second)) {} |
| 7978 | |
| 7979 | StringRef Next() override { |
| 7980 | if (!Current) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 7981 | return StringRef(); |
| Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7982 | |
| 7983 | StringRef result = Current->Next(); |
| 7984 | if (!result.empty()) |
| 7985 | return result; |
| 7986 | |
| 7987 | // Try the queued iterator, which may itself be empty. |
| 7988 | Current.reset(); |
| 7989 | std::swap(Current, Queued); |
| 7990 | return Next(); |
| 7991 | } |
| 7992 | }; |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 7993 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 7994 | } // namespace |
| Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7995 | |
| Argyrios Kyrtzidis | 9aca3c6 | 2013-04-17 22:10:55 +0000 | [diff] [blame] | 7996 | IdentifierIterator *ASTReader::getIdentifiers() { |
| Ben Langmuir | 537c5b5 | 2016-05-04 00:53:13 +0000 | [diff] [blame] | 7997 | if (!loadGlobalIndex()) { |
| 7998 | std::unique_ptr<IdentifierIterator> ReaderIter( |
| 7999 | new ASTIdentifierIterator(*this, /*SkipModules=*/true)); |
| 8000 | std::unique_ptr<IdentifierIterator> ModulesIter( |
| 8001 | GlobalIndex->createIdentifierIterator()); |
| 8002 | return new ChainedIdentifierIterator(std::move(ReaderIter), |
| 8003 | std::move(ModulesIter)); |
| 8004 | } |
| Argyrios Kyrtzidis | 9aca3c6 | 2013-04-17 22:10:55 +0000 | [diff] [blame] | 8005 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8006 | return new ASTIdentifierIterator(*this); |
| 8007 | } |
| 8008 | |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 8009 | namespace clang { |
| 8010 | namespace serialization { |
| 8011 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8012 | class ReadMethodPoolVisitor { |
| 8013 | ASTReader &Reader; |
| 8014 | Selector Sel; |
| 8015 | unsigned PriorGeneration; |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 8016 | unsigned InstanceBits = 0; |
| 8017 | unsigned FactoryBits = 0; |
| 8018 | bool InstanceHasMoreThanOneDecl = false; |
| 8019 | bool FactoryHasMoreThanOneDecl = false; |
| Dmitri Gribenko | f857950 | 2013-01-12 19:30:44 +0000 | [diff] [blame] | 8020 | SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 8021 | SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8022 | |
| 8023 | public: |
| Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 8024 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8025 | unsigned PriorGeneration) |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 8026 | : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration) {} |
| Nico Weber | 2e0c8f7 | 2014-12-27 03:58:08 +0000 | [diff] [blame] | 8027 | |
| Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 8028 | bool operator()(ModuleFile &M) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8029 | if (!M.SelectorLookupTable) |
| 8030 | return false; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8031 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8032 | // If we've already searched this module file, skip it now. |
| Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 8033 | if (M.Generation <= PriorGeneration) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8034 | return true; |
| 8035 | |
| Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 8036 | ++Reader.NumMethodPoolTableLookups; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8037 | ASTSelectorLookupTable *PoolTable |
| 8038 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 8039 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8040 | if (Pos == PoolTable->end()) |
| 8041 | return false; |
| Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 8042 | |
| Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 8043 | ++Reader.NumMethodPoolTableHits; |
| 8044 | ++Reader.NumSelectorsRead; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8045 | // FIXME: Not quite happy with the statistics here. We probably should |
| 8046 | // disable this tracking when called via LoadSelector. |
| 8047 | // Also, should entries without methods count as misses? |
| Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 8048 | ++Reader.NumMethodPoolEntriesRead; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8049 | ASTSelectorLookupTrait::data_type Data = *Pos; |
| Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 8050 | if (Reader.DeserializationListener) |
| 8051 | Reader.DeserializationListener->SelectorRead(Data.ID, Sel); |
| Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 8052 | |
| Richard Smith | bdf2d93 | 2015-07-30 03:37:16 +0000 | [diff] [blame] | 8053 | InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 8054 | FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 8055 | InstanceBits = Data.InstanceBits; |
| 8056 | FactoryBits = Data.FactoryBits; |
| 8057 | InstanceHasMoreThanOneDecl = Data.InstanceHasMoreThanOneDecl; |
| 8058 | FactoryHasMoreThanOneDecl = Data.FactoryHasMoreThanOneDecl; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8059 | return true; |
| 8060 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8061 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8062 | /// Retrieve the instance methods found by this visitor. |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8063 | ArrayRef<ObjCMethodDecl *> getInstanceMethods() const { |
| 8064 | return InstanceMethods; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8065 | } |
| 8066 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8067 | /// Retrieve the instance methods found by this visitor. |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8068 | ArrayRef<ObjCMethodDecl *> getFactoryMethods() const { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8069 | return FactoryMethods; |
| 8070 | } |
| Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 8071 | |
| 8072 | unsigned getInstanceBits() const { return InstanceBits; } |
| 8073 | unsigned getFactoryBits() const { return FactoryBits; } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 8074 | |
| Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 8075 | bool instanceHasMoreThanOneDecl() const { |
| 8076 | return InstanceHasMoreThanOneDecl; |
| 8077 | } |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 8078 | |
| Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 8079 | bool factoryHasMoreThanOneDecl() const { return FactoryHasMoreThanOneDecl; } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8080 | }; |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 8081 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 8082 | } // namespace serialization |
| 8083 | } // namespace clang |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8084 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8085 | /// Add the given set of methods to the method list. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8086 | static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods, |
| 8087 | ObjCMethodList &List) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8088 | for (unsigned I = 0, N = Methods.size(); I != N; ++I) { |
| 8089 | S.addMethodToGlobalList(&List, Methods[I]); |
| 8090 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8091 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8092 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8093 | void ASTReader::ReadMethodPool(Selector Sel) { |
| 8094 | // Get the selector generation and update it to the current generation. |
| 8095 | unsigned &Generation = SelectorGeneration[Sel]; |
| 8096 | unsigned PriorGeneration = Generation; |
| Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 8097 | Generation = getGeneration(); |
| Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 8098 | SelectorOutOfDate[Sel] = false; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8099 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8100 | // Search for methods defined with this selector. |
| Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 8101 | ++NumMethodPoolLookups; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8102 | ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration); |
| Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 8103 | ModuleMgr.visit(Visitor); |
| 8104 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8105 | if (Visitor.getInstanceMethods().empty() && |
| Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 8106 | Visitor.getFactoryMethods().empty()) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8107 | return; |
| Douglas Gregor | ad2f7a5 | 2013-01-28 17:54:36 +0000 | [diff] [blame] | 8108 | |
| 8109 | ++NumMethodPoolHits; |
| 8110 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8111 | if (!getSema()) |
| 8112 | return; |
| 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 | Sema &S = *getSema(); |
| 8115 | Sema::GlobalMethodPool::iterator Pos |
| 8116 | = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first; |
| Ben Langmuir | a0c32e9 | 2015-01-12 19:27:00 +0000 | [diff] [blame] | 8117 | |
| Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 8118 | Pos->second.first.setBits(Visitor.getInstanceBits()); |
| Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 8119 | Pos->second.first.setHasMoreThanOneDecl(Visitor.instanceHasMoreThanOneDecl()); |
| Argyrios Kyrtzidis | d3da6e0 | 2013-04-17 00:08:58 +0000 | [diff] [blame] | 8120 | Pos->second.second.setBits(Visitor.getFactoryBits()); |
| Nico Weber | ff4b35e | 2014-12-27 22:14:15 +0000 | [diff] [blame] | 8121 | Pos->second.second.setHasMoreThanOneDecl(Visitor.factoryHasMoreThanOneDecl()); |
| Ben Langmuir | a0c32e9 | 2015-01-12 19:27:00 +0000 | [diff] [blame] | 8122 | |
| 8123 | // Add methods to the global pool *after* setting hasMoreThanOneDecl, since |
| 8124 | // when building a module we keep every method individually and may need to |
| 8125 | // update hasMoreThanOneDecl as we add the methods. |
| 8126 | addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first); |
| 8127 | addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8128 | } |
| 8129 | |
| Manman Ren | a0f31a0 | 2016-04-29 19:04:05 +0000 | [diff] [blame] | 8130 | void ASTReader::updateOutOfDateSelector(Selector Sel) { |
| 8131 | if (SelectorOutOfDate[Sel]) |
| 8132 | ReadMethodPool(Sel); |
| 8133 | } |
| 8134 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8135 | void ASTReader::ReadKnownNamespaces( |
| 8136 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
| 8137 | Namespaces.clear(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8138 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8139 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 8140 | if (NamespaceDecl *Namespace |
| 8141 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8142 | Namespaces.push_back(Namespace); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8143 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8144 | } |
| 8145 | |
| Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 8146 | void ASTReader::ReadUndefinedButUsed( |
| Richard Smith | d6a04d7 | 2016-03-25 21:49:43 +0000 | [diff] [blame] | 8147 | llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) { |
| Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 8148 | for (unsigned Idx = 0, N = UndefinedButUsed.size(); Idx != N;) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8149 | NamedDecl *D = cast<NamedDecl>(GetDecl(UndefinedButUsed[Idx++])); |
| Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 8150 | SourceLocation Loc = |
| Nick Lewycky | 9c7eb1d | 2013-02-01 08:13:20 +0000 | [diff] [blame] | 8151 | SourceLocation::getFromRawEncoding(UndefinedButUsed[Idx++]); |
| Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 8152 | Undefined.insert(std::make_pair(D, Loc)); |
| 8153 | } |
| 8154 | } |
| Nick Lewycky | 8334af8 | 2013-01-26 00:35:08 +0000 | [diff] [blame] | 8155 | |
| Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 8156 | void ASTReader::ReadMismatchingDeleteExpressions(llvm::MapVector< |
| 8157 | FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> & |
| 8158 | Exprs) { |
| 8159 | for (unsigned Idx = 0, N = DelayedDeleteExprs.size(); Idx != N;) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8160 | FieldDecl *FD = cast<FieldDecl>(GetDecl(DelayedDeleteExprs[Idx++])); |
| Ismail Pazarbasi | e5768d1 | 2015-05-18 19:59:11 +0000 | [diff] [blame] | 8161 | uint64_t Count = DelayedDeleteExprs[Idx++]; |
| 8162 | for (uint64_t C = 0; C < Count; ++C) { |
| 8163 | SourceLocation DeleteLoc = |
| 8164 | SourceLocation::getFromRawEncoding(DelayedDeleteExprs[Idx++]); |
| 8165 | const bool IsArrayForm = DelayedDeleteExprs[Idx++]; |
| 8166 | Exprs[FD].push_back(std::make_pair(DeleteLoc, IsArrayForm)); |
| 8167 | } |
| 8168 | } |
| 8169 | } |
| 8170 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8171 | void ASTReader::ReadTentativeDefinitions( |
| 8172 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8173 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 8174 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8175 | if (Var) |
| 8176 | TentativeDefs.push_back(Var); |
| 8177 | } |
| 8178 | TentativeDefinitions.clear(); |
| 8179 | } |
| 8180 | |
| 8181 | void ASTReader::ReadUnusedFileScopedDecls( |
| 8182 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8183 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 8184 | DeclaratorDecl *D |
| 8185 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8186 | if (D) |
| 8187 | Decls.push_back(D); |
| 8188 | } |
| 8189 | UnusedFileScopedDecls.clear(); |
| 8190 | } |
| 8191 | |
| 8192 | void ASTReader::ReadDelegatingConstructors( |
| 8193 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8194 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 8195 | CXXConstructorDecl *D |
| 8196 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8197 | if (D) |
| 8198 | Decls.push_back(D); |
| 8199 | } |
| 8200 | DelegatingCtorDecls.clear(); |
| 8201 | } |
| 8202 | |
| 8203 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8204 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 8205 | TypedefNameDecl *D |
| 8206 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8207 | if (D) |
| 8208 | Decls.push_back(D); |
| 8209 | } |
| 8210 | ExtVectorDecls.clear(); |
| 8211 | } |
| 8212 | |
| Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 8213 | void ASTReader::ReadUnusedLocalTypedefNameCandidates( |
| 8214 | llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8215 | for (unsigned I = 0, N = UnusedLocalTypedefNameCandidates.size(); I != N; |
| 8216 | ++I) { |
| 8217 | TypedefNameDecl *D = dyn_cast_or_null<TypedefNameDecl>( |
| 8218 | GetDecl(UnusedLocalTypedefNameCandidates[I])); |
| Nico Weber | 7288943 | 2014-09-06 01:25:55 +0000 | [diff] [blame] | 8219 | if (D) |
| 8220 | Decls.insert(D); |
| 8221 | } |
| 8222 | UnusedLocalTypedefNameCandidates.clear(); |
| 8223 | } |
| 8224 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8225 | void ASTReader::ReadReferencedSelectors( |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 8226 | SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8227 | if (ReferencedSelectorsData.empty()) |
| 8228 | return; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8229 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8230 | // If there are @selector references added them to its pool. This is for |
| 8231 | // implementation of -Wselector. |
| 8232 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 8233 | unsigned I = 0; |
| 8234 | while (I < DataSize) { |
| 8235 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 8236 | SourceLocation SelLoc |
| 8237 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 8238 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 8239 | } |
| 8240 | ReferencedSelectorsData.clear(); |
| 8241 | } |
| 8242 | |
| 8243 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 8244 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WeakIDs) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8245 | if (WeakUndeclaredIdentifiers.empty()) |
| 8246 | return; |
| 8247 | |
| 8248 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; /*none*/) { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8249 | IdentifierInfo *WeakId |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8250 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8251 | IdentifierInfo *AliasId |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8252 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 8253 | SourceLocation Loc |
| 8254 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 8255 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 8256 | WeakInfo WI(AliasId, Loc); |
| 8257 | WI.setUsed(Used); |
| 8258 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 8259 | } |
| 8260 | WeakUndeclaredIdentifiers.clear(); |
| 8261 | } |
| 8262 | |
| 8263 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 8264 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; /* In loop */) { |
| 8265 | ExternalVTableUse VT; |
| 8266 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 8267 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 8268 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 8269 | VTables.push_back(VT); |
| 8270 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8271 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8272 | VTableUses.clear(); |
| 8273 | } |
| 8274 | |
| 8275 | void ASTReader::ReadPendingInstantiations( |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 8276 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation>> &Pending) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8277 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8278 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8279 | SourceLocation Loc |
| 8280 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 8281 | |
| 8282 | Pending.push_back(std::make_pair(D, Loc)); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8283 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8284 | PendingInstantiations.clear(); |
| 8285 | } |
| 8286 | |
| Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8287 | void ASTReader::ReadLateParsedTemplates( |
| Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 8288 | llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> |
| 8289 | &LPTMap) { |
| Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8290 | for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N; |
| 8291 | /* In loop */) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8292 | FunctionDecl *FD = cast<FunctionDecl>(GetDecl(LateParsedTemplates[Idx++])); |
| Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8293 | |
| Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 8294 | auto LT = llvm::make_unique<LateParsedTemplate>(); |
| Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8295 | LT->D = GetDecl(LateParsedTemplates[Idx++]); |
| 8296 | |
| 8297 | ModuleFile *F = getOwningModuleFile(LT->D); |
| 8298 | assert(F && "No module"); |
| 8299 | |
| 8300 | unsigned TokN = LateParsedTemplates[Idx++]; |
| 8301 | LT->Toks.reserve(TokN); |
| 8302 | for (unsigned T = 0; T < TokN; ++T) |
| 8303 | LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx)); |
| 8304 | |
| Justin Lebar | 28f09c5 | 2016-10-10 16:26:08 +0000 | [diff] [blame] | 8305 | LPTMap.insert(std::make_pair(FD, std::move(LT))); |
| Richard Smith | e40f2ba | 2013-08-07 21:41:30 +0000 | [diff] [blame] | 8306 | } |
| 8307 | |
| 8308 | LateParsedTemplates.clear(); |
| 8309 | } |
| 8310 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8311 | void ASTReader::LoadSelector(Selector Sel) { |
| 8312 | // It would be complicated to avoid reading the methods anyway. So don't. |
| 8313 | ReadMethodPool(Sel); |
| 8314 | } |
| 8315 | |
| 8316 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
| 8317 | assert(ID && "Non-zero identifier ID required"); |
| 8318 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
| 8319 | IdentifiersLoaded[ID - 1] = II; |
| 8320 | if (DeserializationListener) |
| 8321 | DeserializationListener->IdentifierRead(ID, II); |
| 8322 | } |
| 8323 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8324 | /// Set the globally-visible declarations associated with the given |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8325 | /// identifier. |
| 8326 | /// |
| 8327 | /// If the AST reader is currently in a state where the given declaration IDs |
| 8328 | /// cannot safely be resolved, they are queued until it is safe to resolve |
| 8329 | /// them. |
| 8330 | /// |
| 8331 | /// \param II an IdentifierInfo that refers to one or more globally-visible |
| 8332 | /// declarations. |
| 8333 | /// |
| 8334 | /// \param DeclIDs the set of declaration IDs with the name @p II that are |
| 8335 | /// visible at global scope. |
| 8336 | /// |
| Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8337 | /// \param Decls if non-null, this vector will be populated with the set of |
| 8338 | /// deserialized declarations. These declarations will not be pushed into |
| 8339 | /// scope. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8340 | void |
| 8341 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
| 8342 | const SmallVectorImpl<uint32_t> &DeclIDs, |
| Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 8343 | SmallVectorImpl<Decl *> *Decls) { |
| 8344 | if (NumCurrentElementsDeserializing && !Decls) { |
| 8345 | PendingIdentifierInfos[II].append(DeclIDs.begin(), DeclIDs.end()); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8346 | return; |
| 8347 | } |
| 8348 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8349 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 8350 | if (!SemaObj) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8351 | // Queue this declaration so that it will be added to the |
| 8352 | // translation unit scope and identifier's declaration chain |
| 8353 | // once a Sema object is known. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8354 | PreloadedDeclIDs.push_back(DeclIDs[I]); |
| Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 8355 | continue; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8356 | } |
| Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 8357 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8358 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| Ben Langmuir | 5418f40 | 2014-09-10 21:29:41 +0000 | [diff] [blame] | 8359 | |
| 8360 | // If we're simply supposed to record the declarations, do so now. |
| 8361 | if (Decls) { |
| 8362 | Decls->push_back(D); |
| 8363 | continue; |
| 8364 | } |
| 8365 | |
| 8366 | // Introduce this declaration into the translation-unit scope |
| 8367 | // and add it to the declaration chain for this identifier, so |
| 8368 | // that (unqualified) name lookup will find it. |
| 8369 | pushExternalDeclIntoScope(D, II); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8370 | } |
| 8371 | } |
| 8372 | |
| Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 8373 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8374 | if (ID == 0) |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8375 | return nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8376 | |
| 8377 | if (IdentifiersLoaded.empty()) { |
| 8378 | Error("no identifier table in AST file"); |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8379 | return nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8380 | } |
| 8381 | |
| 8382 | ID -= 1; |
| 8383 | if (!IdentifiersLoaded[ID]) { |
| 8384 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 8385 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
| 8386 | ModuleFile *M = I->second; |
| 8387 | unsigned Index = ID - M->BaseIdentifierID; |
| 8388 | const char *Str = M->IdentifierTableData + M->IdentifierOffsets[Index]; |
| 8389 | |
| 8390 | // All of the strings in the AST file are preceded by a 16-bit length. |
| 8391 | // Extract that 16-bit length to avoid having to execute strlen(). |
| 8392 | // NOTE: 'StrLenPtr' is an 'unsigned char*' so that we load bytes as |
| 8393 | // unsigned integers. This is important to avoid integer overflow when |
| 8394 | // we cast them to 'unsigned'. |
| 8395 | const unsigned char *StrLenPtr = (const unsigned char*) Str - 2; |
| 8396 | unsigned StrLen = (((unsigned) StrLenPtr[0]) |
| 8397 | | (((unsigned) StrLenPtr[1]) << 8)) - 1; |
| Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 8398 | auto &II = PP.getIdentifierTable().get(StringRef(Str, StrLen)); |
| 8399 | IdentifiersLoaded[ID] = &II; |
| 8400 | markIdentifierFromAST(*this, II); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8401 | if (DeserializationListener) |
| Richard Smith | eb4b58f6 | 2016-02-05 01:40:54 +0000 | [diff] [blame] | 8402 | DeserializationListener->IdentifierRead(ID + 1, &II); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8403 | } |
| 8404 | |
| 8405 | return IdentifiersLoaded[ID]; |
| 8406 | } |
| 8407 | |
| Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 8408 | IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) { |
| 8409 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8410 | } |
| 8411 | |
| 8412 | IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) { |
| 8413 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 8414 | return LocalID; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8415 | |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8416 | if (!M.ModuleOffsetMap.empty()) |
| 8417 | ReadModuleOffsetMap(M); |
| 8418 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8419 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8420 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8421 | assert(I != M.IdentifierRemap.end() |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8422 | && "Invalid index into identifier index remap"); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8423 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8424 | return LocalID + I->second; |
| 8425 | } |
| 8426 | |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8427 | MacroInfo *ASTReader::getMacro(MacroID ID) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8428 | if (ID == 0) |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8429 | return nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8430 | |
| 8431 | if (MacrosLoaded.empty()) { |
| 8432 | Error("no macro table in AST file"); |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8433 | return nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8434 | } |
| 8435 | |
| 8436 | ID -= NUM_PREDEF_MACRO_IDS; |
| 8437 | if (!MacrosLoaded[ID]) { |
| 8438 | GlobalMacroMapType::iterator I |
| 8439 | = GlobalMacroMap.find(ID + NUM_PREDEF_MACRO_IDS); |
| 8440 | assert(I != GlobalMacroMap.end() && "Corrupted global macro map"); |
| 8441 | ModuleFile *M = I->second; |
| 8442 | unsigned Index = ID - M->BaseMacroID; |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8443 | MacrosLoaded[ID] = ReadMacroRecord(*M, M->MacroOffsets[Index]); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8444 | |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 8445 | if (DeserializationListener) |
| 8446 | DeserializationListener->MacroRead(ID + NUM_PREDEF_MACRO_IDS, |
| 8447 | MacrosLoaded[ID]); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8448 | } |
| 8449 | |
| 8450 | return MacrosLoaded[ID]; |
| 8451 | } |
| 8452 | |
| 8453 | MacroID ASTReader::getGlobalMacroID(ModuleFile &M, unsigned LocalID) { |
| 8454 | if (LocalID < NUM_PREDEF_MACRO_IDS) |
| 8455 | return LocalID; |
| 8456 | |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8457 | if (!M.ModuleOffsetMap.empty()) |
| 8458 | ReadModuleOffsetMap(M); |
| 8459 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8460 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8461 | = M.MacroRemap.find(LocalID - NUM_PREDEF_MACRO_IDS); |
| 8462 | assert(I != M.MacroRemap.end() && "Invalid index into macro index remap"); |
| 8463 | |
| 8464 | return LocalID + I->second; |
| 8465 | } |
| 8466 | |
| 8467 | serialization::SubmoduleID |
| 8468 | ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) { |
| 8469 | if (LocalID < NUM_PREDEF_SUBMODULE_IDS) |
| 8470 | return LocalID; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8471 | |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8472 | if (!M.ModuleOffsetMap.empty()) |
| 8473 | ReadModuleOffsetMap(M); |
| 8474 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8475 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8476 | = M.SubmoduleRemap.find(LocalID - NUM_PREDEF_SUBMODULE_IDS); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8477 | assert(I != M.SubmoduleRemap.end() |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8478 | && "Invalid index into submodule index remap"); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8479 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8480 | return LocalID + I->second; |
| 8481 | } |
| 8482 | |
| 8483 | Module *ASTReader::getSubmodule(SubmoduleID GlobalID) { |
| 8484 | if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) { |
| 8485 | assert(GlobalID == 0 && "Unhandled global submodule ID"); |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8486 | return nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8487 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8488 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8489 | if (GlobalID > SubmodulesLoaded.size()) { |
| 8490 | Error("submodule ID out of range in AST file"); |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8491 | return nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8492 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8493 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8494 | return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS]; |
| 8495 | } |
| Douglas Gregor | c147b0b | 2013-01-12 01:29:50 +0000 | [diff] [blame] | 8496 | |
| 8497 | Module *ASTReader::getModule(unsigned ID) { |
| 8498 | return getSubmodule(ID); |
| 8499 | } |
| 8500 | |
| Hans Wennborg | 08c5a7b | 2018-06-25 13:23:49 +0000 | [diff] [blame] | 8501 | bool ASTReader::DeclIsFromPCHWithObjectFile(const Decl *D) { |
| 8502 | ModuleFile *MF = getOwningModuleFile(D); |
| 8503 | return MF && MF->PCHHasObjectFile; |
| 8504 | } |
| 8505 | |
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 8506 | ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &F, unsigned ID) { |
| 8507 | if (ID & 1) { |
| 8508 | // It's a module, look it up by submodule ID. |
| 8509 | auto I = GlobalSubmoduleMap.find(getGlobalSubmoduleID(F, ID >> 1)); |
| 8510 | return I == GlobalSubmoduleMap.end() ? nullptr : I->second; |
| 8511 | } else { |
| 8512 | // It's a prefix (preamble, PCH, ...). Look it up by index. |
| 8513 | unsigned IndexFromEnd = ID >> 1; |
| 8514 | assert(IndexFromEnd && "got reference to unknown module file"); |
| 8515 | return getModuleManager().pch_modules().end()[-IndexFromEnd]; |
| 8516 | } |
| 8517 | } |
| 8518 | |
| 8519 | unsigned ASTReader::getModuleFileID(ModuleFile *F) { |
| 8520 | if (!F) |
| 8521 | return 1; |
| 8522 | |
| 8523 | // For a file representing a module, use the submodule ID of the top-level |
| 8524 | // module as the file ID. For any other kind of file, the number of such |
| 8525 | // files loaded beforehand will be the same on reload. |
| 8526 | // FIXME: Is this true even if we have an explicit module file and a PCH? |
| 8527 | if (F->isModule()) |
| 8528 | return ((F->BaseSubmoduleID + NUM_PREDEF_SUBMODULE_IDS) << 1) | 1; |
| 8529 | |
| 8530 | auto PCHModules = getModuleManager().pch_modules(); |
| 8531 | auto I = std::find(PCHModules.begin(), PCHModules.end(), F); |
| 8532 | assert(I != PCHModules.end() && "emitting reference to unknown file"); |
| 8533 | return (I - PCHModules.end()) << 1; |
| 8534 | } |
| 8535 | |
| Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8536 | llvm::Optional<ExternalASTSource::ASTSourceDescriptor> |
| 8537 | ASTReader::getSourceDescriptor(unsigned ID) { |
| 8538 | if (const Module *M = getSubmodule(ID)) |
| Adrian Prantl | c6458d6 | 2015-09-19 00:10:32 +0000 | [diff] [blame] | 8539 | return ExternalASTSource::ASTSourceDescriptor(*M); |
| Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8540 | |
| 8541 | // If there is only a single PCH, return it instead. |
| Hiroshi Inoue | 3170de0 | 2017-07-01 08:46:43 +0000 | [diff] [blame] | 8542 | // Chained PCH are not supported. |
| Saleem Abdulrasool | 97d2555 | 2017-03-02 17:37:11 +0000 | [diff] [blame] | 8543 | const auto &PCHChain = ModuleMgr.pch_modules(); |
| 8544 | if (std::distance(std::begin(PCHChain), std::end(PCHChain))) { |
| Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8545 | ModuleFile &MF = ModuleMgr.getPrimaryModule(); |
| Adrian Prantl | 3a2d494 | 2016-01-22 23:30:56 +0000 | [diff] [blame] | 8546 | StringRef ModuleName = llvm::sys::path::filename(MF.OriginalSourceFileName); |
| Adrian Prantl | 9bc3c4f | 2016-04-27 17:06:22 +0000 | [diff] [blame] | 8547 | StringRef FileName = llvm::sys::path::filename(MF.FileName); |
| 8548 | return ASTReader::ASTSourceDescriptor(ModuleName, MF.OriginalDir, FileName, |
| 8549 | MF.Signature); |
| Adrian Prantl | 15bcf70 | 2015-06-30 17:39:43 +0000 | [diff] [blame] | 8550 | } |
| 8551 | return None; |
| 8552 | } |
| 8553 | |
| David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 8554 | ExternalASTSource::ExtKind ASTReader::hasExternalDefinitions(const Decl *FD) { |
| Richard Smith | a465362 | 2017-09-06 20:01:14 +0000 | [diff] [blame] | 8555 | auto I = DefinitionSource.find(FD); |
| 8556 | if (I == DefinitionSource.end()) |
| David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 8557 | return EK_ReplyHazy; |
| David Blaikie | e6b7c28 | 2017-04-11 20:46:34 +0000 | [diff] [blame] | 8558 | return I->second ? EK_Never : EK_Always; |
| David Blaikie | 9ffe5a3 | 2017-01-30 05:00:26 +0000 | [diff] [blame] | 8559 | } |
| 8560 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8561 | Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) { |
| 8562 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 8563 | } |
| 8564 | |
| 8565 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
| 8566 | if (ID == 0) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8567 | return Selector(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8568 | |
| 8569 | if (ID > SelectorsLoaded.size()) { |
| 8570 | Error("selector ID out of range in AST file"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8571 | return Selector(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8572 | } |
| 8573 | |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8574 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == nullptr) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8575 | // Load this selector from the selector table. |
| 8576 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 8577 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
| 8578 | ModuleFile &M = *I->second; |
| 8579 | ASTSelectorLookupTrait Trait(*this, M); |
| 8580 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
| 8581 | SelectorsLoaded[ID - 1] = |
| 8582 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
| 8583 | if (DeserializationListener) |
| 8584 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 8585 | } |
| 8586 | |
| 8587 | return SelectorsLoaded[ID - 1]; |
| 8588 | } |
| 8589 | |
| 8590 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
| 8591 | return DecodeSelector(ID); |
| 8592 | } |
| 8593 | |
| 8594 | uint32_t ASTReader::GetNumExternalSelectors() { |
| 8595 | // ID 0 (the null selector) is considered an external selector. |
| 8596 | return getTotalNumSelectors() + 1; |
| 8597 | } |
| 8598 | |
| 8599 | serialization::SelectorID |
| 8600 | ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const { |
| 8601 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 8602 | return LocalID; |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8603 | |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 8604 | if (!M.ModuleOffsetMap.empty()) |
| 8605 | ReadModuleOffsetMap(M); |
| 8606 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8607 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8608 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8609 | assert(I != M.SelectorRemap.end() |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8610 | && "Invalid index into selector index remap"); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8611 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8612 | return LocalID + I->second; |
| 8613 | } |
| 8614 | |
| 8615 | DeclarationName |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8616 | ASTReader::ReadDeclarationName(ModuleFile &F, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8617 | const RecordData &Record, unsigned &Idx) { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8618 | ASTContext &Context = getContext(); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8619 | DeclarationName::NameKind Kind = (DeclarationName::NameKind)Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8620 | switch (Kind) { |
| 8621 | case DeclarationName::Identifier: |
| Douglas Gregor | c8a992f | 2013-01-21 16:52:34 +0000 | [diff] [blame] | 8622 | return DeclarationName(GetIdentifierInfo(F, Record, Idx)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8623 | |
| 8624 | case DeclarationName::ObjCZeroArgSelector: |
| 8625 | case DeclarationName::ObjCOneArgSelector: |
| 8626 | case DeclarationName::ObjCMultiArgSelector: |
| 8627 | return DeclarationName(ReadSelector(F, Record, Idx)); |
| 8628 | |
| 8629 | case DeclarationName::CXXConstructorName: |
| 8630 | return Context.DeclarationNames.getCXXConstructorName( |
| 8631 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 8632 | |
| 8633 | case DeclarationName::CXXDestructorName: |
| 8634 | return Context.DeclarationNames.getCXXDestructorName( |
| 8635 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 8636 | |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8637 | case DeclarationName::CXXDeductionGuideName: |
| 8638 | return Context.DeclarationNames.getCXXDeductionGuideName( |
| 8639 | ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
| 8640 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8641 | case DeclarationName::CXXConversionFunctionName: |
| 8642 | return Context.DeclarationNames.getCXXConversionFunctionName( |
| 8643 | Context.getCanonicalType(readType(F, Record, Idx))); |
| 8644 | |
| 8645 | case DeclarationName::CXXOperatorName: |
| 8646 | return Context.DeclarationNames.getCXXOperatorName( |
| 8647 | (OverloadedOperatorKind)Record[Idx++]); |
| 8648 | |
| 8649 | case DeclarationName::CXXLiteralOperatorName: |
| 8650 | return Context.DeclarationNames.getCXXLiteralOperatorName( |
| 8651 | GetIdentifierInfo(F, Record, Idx)); |
| 8652 | |
| 8653 | case DeclarationName::CXXUsingDirective: |
| 8654 | return DeclarationName::getUsingDirectiveName(); |
| 8655 | } |
| 8656 | |
| 8657 | llvm_unreachable("Invalid NameKind!"); |
| 8658 | } |
| 8659 | |
| 8660 | void ASTReader::ReadDeclarationNameLoc(ModuleFile &F, |
| 8661 | DeclarationNameLoc &DNLoc, |
| 8662 | DeclarationName Name, |
| 8663 | const RecordData &Record, unsigned &Idx) { |
| 8664 | switch (Name.getNameKind()) { |
| 8665 | case DeclarationName::CXXConstructorName: |
| 8666 | case DeclarationName::CXXDestructorName: |
| 8667 | case DeclarationName::CXXConversionFunctionName: |
| 8668 | DNLoc.NamedType.TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8669 | break; |
| 8670 | |
| 8671 | case DeclarationName::CXXOperatorName: |
| 8672 | DNLoc.CXXOperatorName.BeginOpNameLoc |
| 8673 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 8674 | DNLoc.CXXOperatorName.EndOpNameLoc |
| 8675 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 8676 | break; |
| 8677 | |
| 8678 | case DeclarationName::CXXLiteralOperatorName: |
| 8679 | DNLoc.CXXLiteralOperatorName.OpNameLoc |
| 8680 | = ReadSourceLocation(F, Record, Idx).getRawEncoding(); |
| 8681 | break; |
| 8682 | |
| 8683 | case DeclarationName::Identifier: |
| 8684 | case DeclarationName::ObjCZeroArgSelector: |
| 8685 | case DeclarationName::ObjCOneArgSelector: |
| 8686 | case DeclarationName::ObjCMultiArgSelector: |
| 8687 | case DeclarationName::CXXUsingDirective: |
| Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 8688 | case DeclarationName::CXXDeductionGuideName: |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8689 | break; |
| 8690 | } |
| 8691 | } |
| 8692 | |
| 8693 | void ASTReader::ReadDeclarationNameInfo(ModuleFile &F, |
| 8694 | DeclarationNameInfo &NameInfo, |
| 8695 | const RecordData &Record, unsigned &Idx) { |
| 8696 | NameInfo.setName(ReadDeclarationName(F, Record, Idx)); |
| 8697 | NameInfo.setLoc(ReadSourceLocation(F, Record, Idx)); |
| 8698 | DeclarationNameLoc DNLoc; |
| 8699 | ReadDeclarationNameLoc(F, DNLoc, NameInfo.getName(), Record, Idx); |
| 8700 | NameInfo.setInfo(DNLoc); |
| 8701 | } |
| 8702 | |
| 8703 | void ASTReader::ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info, |
| 8704 | const RecordData &Record, unsigned &Idx) { |
| 8705 | Info.QualifierLoc = ReadNestedNameSpecifierLoc(F, Record, Idx); |
| 8706 | unsigned NumTPLists = Record[Idx++]; |
| 8707 | Info.NumTemplParamLists = NumTPLists; |
| 8708 | if (NumTPLists) { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8709 | Info.TemplParamLists = |
| 8710 | new (getContext()) TemplateParameterList *[NumTPLists]; |
| Eugene Zelenko | e95e7d5 | 2016-09-07 21:53:17 +0000 | [diff] [blame] | 8711 | for (unsigned i = 0; i != NumTPLists; ++i) |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8712 | Info.TemplParamLists[i] = ReadTemplateParameterList(F, Record, Idx); |
| 8713 | } |
| 8714 | } |
| 8715 | |
| 8716 | TemplateName |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8717 | ASTReader::ReadTemplateName(ModuleFile &F, const RecordData &Record, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8718 | unsigned &Idx) { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8719 | ASTContext &Context = getContext(); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8720 | TemplateName::NameKind Kind = (TemplateName::NameKind)Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8721 | switch (Kind) { |
| 8722 | case TemplateName::Template: |
| 8723 | return TemplateName(ReadDeclAs<TemplateDecl>(F, Record, Idx)); |
| 8724 | |
| 8725 | case TemplateName::OverloadedTemplate: { |
| 8726 | unsigned size = Record[Idx++]; |
| 8727 | UnresolvedSet<8> Decls; |
| 8728 | while (size--) |
| 8729 | Decls.addDecl(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
| 8730 | |
| 8731 | return Context.getOverloadedTemplateName(Decls.begin(), Decls.end()); |
| 8732 | } |
| 8733 | |
| 8734 | case TemplateName::QualifiedTemplate: { |
| 8735 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
| 8736 | bool hasTemplKeyword = Record[Idx++]; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8737 | TemplateDecl *Template = ReadDeclAs<TemplateDecl>(F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8738 | return Context.getQualifiedTemplateName(NNS, hasTemplKeyword, Template); |
| 8739 | } |
| 8740 | |
| 8741 | case TemplateName::DependentTemplate: { |
| 8742 | NestedNameSpecifier *NNS = ReadNestedNameSpecifier(F, Record, Idx); |
| 8743 | if (Record[Idx++]) // isIdentifier |
| 8744 | return Context.getDependentTemplateName(NNS, |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8745 | GetIdentifierInfo(F, Record, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8746 | Idx)); |
| 8747 | return Context.getDependentTemplateName(NNS, |
| 8748 | (OverloadedOperatorKind)Record[Idx++]); |
| 8749 | } |
| 8750 | |
| 8751 | case TemplateName::SubstTemplateTemplateParm: { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8752 | TemplateTemplateParmDecl *param |
| 8753 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
| 8754 | if (!param) return TemplateName(); |
| 8755 | TemplateName replacement = ReadTemplateName(F, Record, Idx); |
| 8756 | return Context.getSubstTemplateTemplateParm(param, replacement); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8757 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8758 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8759 | case TemplateName::SubstTemplateTemplateParmPack: { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8760 | TemplateTemplateParmDecl *Param |
| 8761 | = ReadDeclAs<TemplateTemplateParmDecl>(F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8762 | if (!Param) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8763 | return TemplateName(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8764 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8765 | TemplateArgument ArgPack = ReadTemplateArgument(F, Record, Idx); |
| 8766 | if (ArgPack.getKind() != TemplateArgument::Pack) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8767 | return TemplateName(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8768 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8769 | return Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 8770 | } |
| 8771 | } |
| 8772 | |
| 8773 | llvm_unreachable("Unhandled template name kind!"); |
| 8774 | } |
| 8775 | |
| Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8776 | TemplateArgument ASTReader::ReadTemplateArgument(ModuleFile &F, |
| 8777 | const RecordData &Record, |
| 8778 | unsigned &Idx, |
| 8779 | bool Canonicalize) { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8780 | ASTContext &Context = getContext(); |
| Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8781 | if (Canonicalize) { |
| 8782 | // The caller wants a canonical template argument. Sometimes the AST only |
| 8783 | // wants template arguments in canonical form (particularly as the template |
| 8784 | // argument lists of template specializations) so ensure we preserve that |
| 8785 | // canonical form across serialization. |
| 8786 | TemplateArgument Arg = ReadTemplateArgument(F, Record, Idx, false); |
| 8787 | return Context.getCanonicalTemplateArgument(Arg); |
| 8788 | } |
| 8789 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8790 | TemplateArgument::ArgKind Kind = (TemplateArgument::ArgKind)Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8791 | switch (Kind) { |
| 8792 | case TemplateArgument::Null: |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8793 | return TemplateArgument(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8794 | case TemplateArgument::Type: |
| 8795 | return TemplateArgument(readType(F, Record, Idx)); |
| 8796 | case TemplateArgument::Declaration: { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8797 | ValueDecl *D = ReadDeclAs<ValueDecl>(F, Record, Idx); |
| David Blaikie | 0f62c8d | 2014-10-16 04:21:25 +0000 | [diff] [blame] | 8798 | return TemplateArgument(D, readType(F, Record, Idx)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8799 | } |
| 8800 | case TemplateArgument::NullPtr: |
| 8801 | return TemplateArgument(readType(F, Record, Idx), /*isNullPtr*/true); |
| 8802 | case TemplateArgument::Integral: { |
| 8803 | llvm::APSInt Value = ReadAPSInt(Record, Idx); |
| 8804 | QualType T = readType(F, Record, Idx); |
| 8805 | return TemplateArgument(Context, Value, T); |
| 8806 | } |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8807 | case TemplateArgument::Template: |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8808 | return TemplateArgument(ReadTemplateName(F, Record, Idx)); |
| 8809 | case TemplateArgument::TemplateExpansion: { |
| 8810 | TemplateName Name = ReadTemplateName(F, Record, Idx); |
| David Blaikie | 05785d1 | 2013-02-20 22:23:23 +0000 | [diff] [blame] | 8811 | Optional<unsigned> NumTemplateExpansions; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8812 | if (unsigned NumExpansions = Record[Idx++]) |
| 8813 | NumTemplateExpansions = NumExpansions - 1; |
| 8814 | return TemplateArgument(Name, NumTemplateExpansions); |
| 8815 | } |
| 8816 | case TemplateArgument::Expression: |
| 8817 | return TemplateArgument(ReadExpr(F)); |
| 8818 | case TemplateArgument::Pack: { |
| 8819 | unsigned NumArgs = Record[Idx++]; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8820 | TemplateArgument *Args = new (Context) TemplateArgument[NumArgs]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8821 | for (unsigned I = 0; I != NumArgs; ++I) |
| 8822 | Args[I] = ReadTemplateArgument(F, Record, Idx); |
| Benjamin Kramer | cce6347 | 2015-08-05 09:40:22 +0000 | [diff] [blame] | 8823 | return TemplateArgument(llvm::makeArrayRef(Args, NumArgs)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8824 | } |
| 8825 | } |
| 8826 | |
| 8827 | llvm_unreachable("Unhandled template argument kind!"); |
| 8828 | } |
| 8829 | |
| 8830 | TemplateParameterList * |
| 8831 | ASTReader::ReadTemplateParameterList(ModuleFile &F, |
| 8832 | const RecordData &Record, unsigned &Idx) { |
| 8833 | SourceLocation TemplateLoc = ReadSourceLocation(F, Record, Idx); |
| 8834 | SourceLocation LAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 8835 | SourceLocation RAngleLoc = ReadSourceLocation(F, Record, Idx); |
| 8836 | |
| 8837 | unsigned NumParams = Record[Idx++]; |
| 8838 | SmallVector<NamedDecl *, 16> Params; |
| 8839 | Params.reserve(NumParams); |
| 8840 | while (NumParams--) |
| 8841 | Params.push_back(ReadDeclAs<NamedDecl>(F, Record, Idx)); |
| 8842 | |
| Hubert Tong | e4a0c0e | 2016-07-30 22:33:34 +0000 | [diff] [blame] | 8843 | // TODO: Concepts |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8844 | TemplateParameterList *TemplateParams = TemplateParameterList::Create( |
| 8845 | getContext(), TemplateLoc, LAngleLoc, Params, RAngleLoc, nullptr); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8846 | return TemplateParams; |
| 8847 | } |
| 8848 | |
| 8849 | void |
| 8850 | ASTReader:: |
| Craig Topper | 5603df4 | 2013-07-05 19:34:19 +0000 | [diff] [blame] | 8851 | ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8852 | ModuleFile &F, const RecordData &Record, |
| Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8853 | unsigned &Idx, bool Canonicalize) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8854 | unsigned NumTemplateArgs = Record[Idx++]; |
| 8855 | TemplArgs.reserve(NumTemplateArgs); |
| 8856 | while (NumTemplateArgs--) |
| Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 8857 | TemplArgs.push_back(ReadTemplateArgument(F, Record, Idx, Canonicalize)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8858 | } |
| 8859 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 8860 | /// Read a UnresolvedSet structure. |
| Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 8861 | void ASTReader::ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8862 | const RecordData &Record, unsigned &Idx) { |
| 8863 | unsigned NumDecls = Record[Idx++]; |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8864 | Set.reserve(getContext(), NumDecls); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8865 | while (NumDecls--) { |
| Richard Smith | a4ba74c | 2013-08-30 04:46:40 +0000 | [diff] [blame] | 8866 | DeclID ID = ReadDeclID(F, Record, Idx); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8867 | AccessSpecifier AS = (AccessSpecifier)Record[Idx++]; |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8868 | Set.addLazyDecl(getContext(), ID, AS); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8869 | } |
| 8870 | } |
| 8871 | |
| 8872 | CXXBaseSpecifier |
| 8873 | ASTReader::ReadCXXBaseSpecifier(ModuleFile &F, |
| 8874 | const RecordData &Record, unsigned &Idx) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8875 | bool isVirtual = static_cast<bool>(Record[Idx++]); |
| 8876 | bool isBaseOfClass = static_cast<bool>(Record[Idx++]); |
| 8877 | AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]); |
| 8878 | bool inheritConstructors = static_cast<bool>(Record[Idx++]); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8879 | TypeSourceInfo *TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8880 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 8881 | SourceLocation EllipsisLoc = ReadSourceLocation(F, Record, Idx); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 8882 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8883 | EllipsisLoc); |
| 8884 | Result.setInheritConstructors(inheritConstructors); |
| 8885 | return Result; |
| 8886 | } |
| 8887 | |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8888 | CXXCtorInitializer ** |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8889 | ASTReader::ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record, |
| 8890 | unsigned &Idx) { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8891 | ASTContext &Context = getContext(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8892 | unsigned NumInitializers = Record[Idx++]; |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8893 | assert(NumInitializers && "wrote ctor initializers but have no inits"); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8894 | auto **CtorInitializers = new (Context) CXXCtorInitializer*[NumInitializers]; |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8895 | for (unsigned i = 0; i != NumInitializers; ++i) { |
| 8896 | TypeSourceInfo *TInfo = nullptr; |
| 8897 | bool IsBaseVirtual = false; |
| 8898 | FieldDecl *Member = nullptr; |
| 8899 | IndirectFieldDecl *IndirectMember = nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8900 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8901 | CtorInitializerType Type = (CtorInitializerType)Record[Idx++]; |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8902 | switch (Type) { |
| 8903 | case CTOR_INITIALIZER_BASE: |
| 8904 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8905 | IsBaseVirtual = Record[Idx++]; |
| 8906 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8907 | |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8908 | case CTOR_INITIALIZER_DELEGATING: |
| 8909 | TInfo = GetTypeSourceInfo(F, Record, Idx); |
| 8910 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8911 | |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8912 | case CTOR_INITIALIZER_MEMBER: |
| 8913 | Member = ReadDeclAs<FieldDecl>(F, Record, Idx); |
| 8914 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8915 | |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8916 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
| 8917 | IndirectMember = ReadDeclAs<IndirectFieldDecl>(F, Record, Idx); |
| 8918 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8919 | } |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8920 | |
| 8921 | SourceLocation MemberOrEllipsisLoc = ReadSourceLocation(F, Record, Idx); |
| 8922 | Expr *Init = ReadExpr(F); |
| 8923 | SourceLocation LParenLoc = ReadSourceLocation(F, Record, Idx); |
| 8924 | SourceLocation RParenLoc = ReadSourceLocation(F, Record, Idx); |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8925 | |
| 8926 | CXXCtorInitializer *BOMInit; |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8927 | if (Type == CTOR_INITIALIZER_BASE) |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8928 | BOMInit = new (Context) |
| 8929 | CXXCtorInitializer(Context, TInfo, IsBaseVirtual, LParenLoc, Init, |
| 8930 | RParenLoc, MemberOrEllipsisLoc); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8931 | else if (Type == CTOR_INITIALIZER_DELEGATING) |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8932 | BOMInit = new (Context) |
| 8933 | CXXCtorInitializer(Context, TInfo, LParenLoc, Init, RParenLoc); |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8934 | else if (Member) |
| 8935 | BOMInit = new (Context) |
| 8936 | CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, LParenLoc, |
| 8937 | Init, RParenLoc); |
| 8938 | else |
| 8939 | BOMInit = new (Context) |
| 8940 | CXXCtorInitializer(Context, IndirectMember, MemberOrEllipsisLoc, |
| 8941 | LParenLoc, Init, RParenLoc); |
| 8942 | |
| Richard Smith | 418ed82 | 2016-12-14 19:45:03 +0000 | [diff] [blame] | 8943 | if (/*IsWritten*/Record[Idx++]) { |
| Richard Smith | 30e304e | 2016-12-14 00:03:17 +0000 | [diff] [blame] | 8944 | unsigned SourceOrder = Record[Idx++]; |
| 8945 | BOMInit->setSourceOrder(SourceOrder); |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8946 | } |
| 8947 | |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8948 | CtorInitializers[i] = BOMInit; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8949 | } |
| 8950 | |
| Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 8951 | return CtorInitializers; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8952 | } |
| 8953 | |
| 8954 | NestedNameSpecifier * |
| 8955 | ASTReader::ReadNestedNameSpecifier(ModuleFile &F, |
| 8956 | const RecordData &Record, unsigned &Idx) { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 8957 | ASTContext &Context = getContext(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8958 | unsigned N = Record[Idx++]; |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8959 | NestedNameSpecifier *NNS = nullptr, *Prev = nullptr; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8960 | for (unsigned I = 0; I != N; ++I) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8961 | NestedNameSpecifier::SpecifierKind Kind |
| 8962 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8963 | switch (Kind) { |
| 8964 | case NestedNameSpecifier::Identifier: { |
| 8965 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
| 8966 | NNS = NestedNameSpecifier::Create(Context, Prev, II); |
| 8967 | break; |
| 8968 | } |
| 8969 | |
| 8970 | case NestedNameSpecifier::Namespace: { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8971 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8972 | NNS = NestedNameSpecifier::Create(Context, Prev, NS); |
| 8973 | break; |
| 8974 | } |
| 8975 | |
| 8976 | case NestedNameSpecifier::NamespaceAlias: { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8977 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8978 | NNS = NestedNameSpecifier::Create(Context, Prev, Alias); |
| 8979 | break; |
| 8980 | } |
| 8981 | |
| 8982 | case NestedNameSpecifier::TypeSpec: |
| 8983 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 8984 | const Type *T = readType(F, Record, Idx).getTypePtrOrNull(); |
| 8985 | if (!T) |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 8986 | return nullptr; |
| 8987 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8988 | bool Template = Record[Idx++]; |
| 8989 | NNS = NestedNameSpecifier::Create(Context, Prev, Template, T); |
| 8990 | break; |
| 8991 | } |
| 8992 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 8993 | case NestedNameSpecifier::Global: |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 8994 | NNS = NestedNameSpecifier::GlobalSpecifier(Context); |
| 8995 | // No associated value, and there can't be a prefix. |
| 8996 | break; |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 8997 | |
| 8998 | case NestedNameSpecifier::Super: { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 8999 | CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx); |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 9000 | NNS = NestedNameSpecifier::SuperSpecifier(Context, RD); |
| 9001 | break; |
| 9002 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9003 | } |
| 9004 | Prev = NNS; |
| 9005 | } |
| 9006 | return NNS; |
| 9007 | } |
| 9008 | |
| 9009 | NestedNameSpecifierLoc |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 9010 | ASTReader::ReadNestedNameSpecifierLoc(ModuleFile &F, const RecordData &Record, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9011 | unsigned &Idx) { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 9012 | ASTContext &Context = getContext(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9013 | unsigned N = Record[Idx++]; |
| 9014 | NestedNameSpecifierLocBuilder Builder; |
| 9015 | for (unsigned I = 0; I != N; ++I) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9016 | NestedNameSpecifier::SpecifierKind Kind |
| 9017 | = (NestedNameSpecifier::SpecifierKind)Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9018 | switch (Kind) { |
| 9019 | case NestedNameSpecifier::Identifier: { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 9020 | IdentifierInfo *II = GetIdentifierInfo(F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9021 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 9022 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
| 9023 | break; |
| 9024 | } |
| 9025 | |
| 9026 | case NestedNameSpecifier::Namespace: { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9027 | NamespaceDecl *NS = ReadDeclAs<NamespaceDecl>(F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9028 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 9029 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
| 9030 | break; |
| 9031 | } |
| 9032 | |
| 9033 | case NestedNameSpecifier::NamespaceAlias: { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9034 | NamespaceAliasDecl *Alias =ReadDeclAs<NamespaceAliasDecl>(F, Record, Idx); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9035 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 9036 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
| 9037 | break; |
| 9038 | } |
| 9039 | |
| 9040 | case NestedNameSpecifier::TypeSpec: |
| 9041 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 9042 | bool Template = Record[Idx++]; |
| 9043 | TypeSourceInfo *T = GetTypeSourceInfo(F, Record, Idx); |
| 9044 | if (!T) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9045 | return NestedNameSpecifierLoc(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9046 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
| 9047 | |
| 9048 | // FIXME: 'template' keyword location not saved anywhere, so we fake it. |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 9049 | Builder.Extend(Context, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9050 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 9051 | T->getTypeLoc(), ColonColonLoc); |
| 9052 | break; |
| 9053 | } |
| 9054 | |
| 9055 | case NestedNameSpecifier::Global: { |
| 9056 | SourceLocation ColonColonLoc = ReadSourceLocation(F, Record, Idx); |
| 9057 | Builder.MakeGlobal(Context, ColonColonLoc); |
| 9058 | break; |
| 9059 | } |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 9060 | |
| 9061 | case NestedNameSpecifier::Super: { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9062 | CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>(F, Record, Idx); |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 9063 | SourceRange Range = ReadSourceRange(F, Record, Idx); |
| 9064 | Builder.MakeSuper(Context, RD, Range.getBegin(), Range.getEnd()); |
| 9065 | break; |
| 9066 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9067 | } |
| 9068 | } |
| Nikola Smiljanic | 6786024 | 2014-09-26 00:28:20 +0000 | [diff] [blame] | 9069 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9070 | return Builder.getWithLocInContext(Context); |
| 9071 | } |
| 9072 | |
| 9073 | SourceRange |
| 9074 | ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record, |
| 9075 | unsigned &Idx) { |
| 9076 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 9077 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
| 9078 | return SourceRange(beg, end); |
| 9079 | } |
| 9080 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 9081 | /// Read an integral value |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9082 | llvm::APInt ASTReader::ReadAPInt(const RecordData &Record, unsigned &Idx) { |
| 9083 | unsigned BitWidth = Record[Idx++]; |
| 9084 | unsigned NumWords = llvm::APInt::getNumWords(BitWidth); |
| 9085 | llvm::APInt Result(BitWidth, NumWords, &Record[Idx]); |
| 9086 | Idx += NumWords; |
| 9087 | return Result; |
| 9088 | } |
| 9089 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 9090 | /// Read a signed integral value |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9091 | llvm::APSInt ASTReader::ReadAPSInt(const RecordData &Record, unsigned &Idx) { |
| 9092 | bool isUnsigned = Record[Idx++]; |
| 9093 | return llvm::APSInt(ReadAPInt(Record, Idx), isUnsigned); |
| 9094 | } |
| 9095 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 9096 | /// Read a floating-point value |
| Tim Northover | 178723a | 2013-01-22 09:46:51 +0000 | [diff] [blame] | 9097 | llvm::APFloat ASTReader::ReadAPFloat(const RecordData &Record, |
| 9098 | const llvm::fltSemantics &Sem, |
| 9099 | unsigned &Idx) { |
| 9100 | return llvm::APFloat(Sem, ReadAPInt(Record, Idx)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9101 | } |
| 9102 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 9103 | // Read a string |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9104 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
| 9105 | unsigned Len = Record[Idx++]; |
| 9106 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
| 9107 | Idx += Len; |
| 9108 | return Result; |
| 9109 | } |
| 9110 | |
| Richard Smith | 7ed1bc9 | 2014-12-05 22:42:13 +0000 | [diff] [blame] | 9111 | std::string ASTReader::ReadPath(ModuleFile &F, const RecordData &Record, |
| 9112 | unsigned &Idx) { |
| 9113 | std::string Filename = ReadString(Record, Idx); |
| 9114 | ResolveImportedPath(F, Filename); |
| 9115 | return Filename; |
| 9116 | } |
| 9117 | |
| Duncan P. N. Exon Smith | 0a2be46 | 2019-03-09 17:44:01 +0000 | [diff] [blame] | 9118 | std::string ASTReader::ReadPath(StringRef BaseDirectory, |
| 9119 | const RecordData &Record, unsigned &Idx) { |
| 9120 | std::string Filename = ReadString(Record, Idx); |
| 9121 | if (!BaseDirectory.empty()) |
| 9122 | ResolveImportedPath(Filename, BaseDirectory); |
| 9123 | return Filename; |
| 9124 | } |
| 9125 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 9126 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9127 | unsigned &Idx) { |
| 9128 | unsigned Major = Record[Idx++]; |
| 9129 | unsigned Minor = Record[Idx++]; |
| 9130 | unsigned Subminor = Record[Idx++]; |
| 9131 | if (Minor == 0) |
| 9132 | return VersionTuple(Major); |
| 9133 | if (Subminor == 0) |
| 9134 | return VersionTuple(Major, Minor - 1); |
| 9135 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 9136 | } |
| 9137 | |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 9138 | CXXTemporary *ASTReader::ReadCXXTemporary(ModuleFile &F, |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9139 | const RecordData &Record, |
| 9140 | unsigned &Idx) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9141 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 9142 | return CXXTemporary::Create(getContext(), Decl); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9143 | } |
| 9144 | |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 9145 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) const { |
| Argyrios Kyrtzidis | dc9fdaf | 2013-05-24 05:44:08 +0000 | [diff] [blame] | 9146 | return Diag(CurrentImportLoc, DiagID); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9147 | } |
| 9148 | |
| Richard Smith | 37a93df | 2017-02-18 00:32:02 +0000 | [diff] [blame] | 9149 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) const { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9150 | return Diags.Report(Loc, DiagID); |
| 9151 | } |
| 9152 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 9153 | /// Retrieve the identifier table associated with the |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9154 | /// preprocessor. |
| 9155 | IdentifierTable &ASTReader::getIdentifierTable() { |
| 9156 | return PP.getIdentifierTable(); |
| 9157 | } |
| 9158 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 9159 | /// Record that the given ID maps to the given switch-case |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9160 | /// statement. |
| 9161 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 9162 | assert((*CurrSwitchCaseStmts)[ID] == nullptr && |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9163 | "Already have a SwitchCase with this ID"); |
| 9164 | (*CurrSwitchCaseStmts)[ID] = SC; |
| 9165 | } |
| 9166 | |
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 9167 | /// Retrieve the switch-case statement with the given ID. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9168 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
| Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 9169 | assert((*CurrSwitchCaseStmts)[ID] != nullptr && "No SwitchCase with this ID"); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9170 | return (*CurrSwitchCaseStmts)[ID]; |
| 9171 | } |
| 9172 | |
| 9173 | void ASTReader::ClearSwitchCaseIDs() { |
| 9174 | CurrSwitchCaseStmts->clear(); |
| 9175 | } |
| 9176 | |
| 9177 | void ASTReader::ReadComments() { |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 9178 | ASTContext &Context = getContext(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9179 | std::vector<RawComment *> Comments; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9180 | for (SmallVectorImpl<std::pair<BitstreamCursor, |
| 9181 | serialization::ModuleFile *>>::iterator |
| 9182 | I = CommentsCursors.begin(), |
| 9183 | E = CommentsCursors.end(); |
| 9184 | I != E; ++I) { |
| Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 9185 | Comments.clear(); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9186 | BitstreamCursor &Cursor = I->first; |
| 9187 | serialization::ModuleFile &F = *I->second; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9188 | SavedStreamPosition SavedPosition(Cursor); |
| 9189 | |
| 9190 | RecordData Record; |
| 9191 | while (true) { |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 9192 | llvm::BitstreamEntry Entry = |
| 9193 | Cursor.advanceSkippingSubblocks(BitstreamCursor::AF_DontPopBlockAtEnd); |
| Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 9194 | |
| Chris Lattner | 7fb3bef | 2013-01-20 00:56:42 +0000 | [diff] [blame] | 9195 | switch (Entry.Kind) { |
| 9196 | case llvm::BitstreamEntry::SubBlock: // Handled for us already. |
| 9197 | case llvm::BitstreamEntry::Error: |
| 9198 | Error("malformed block record in AST file"); |
| 9199 | return; |
| 9200 | case llvm::BitstreamEntry::EndBlock: |
| 9201 | goto NextCursor; |
| 9202 | case llvm::BitstreamEntry::Record: |
| 9203 | // The interesting case. |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9204 | break; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9205 | } |
| 9206 | |
| 9207 | // Read a record. |
| 9208 | Record.clear(); |
| Chris Lattner | 0e6c940 | 2013-01-20 02:38:54 +0000 | [diff] [blame] | 9209 | switch ((CommentRecordTypes)Cursor.readRecord(Entry.ID, Record)) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9210 | case COMMENTS_RAW_COMMENT: { |
| 9211 | unsigned Idx = 0; |
| 9212 | SourceRange SR = ReadSourceRange(F, Record, Idx); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9213 | RawComment::CommentKind Kind = |
| 9214 | (RawComment::CommentKind) Record[Idx++]; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9215 | bool IsTrailingComment = Record[Idx++]; |
| 9216 | bool IsAlmostTrailingComment = Record[Idx++]; |
| Dmitri Gribenko | a7d16ce | 2013-04-10 15:35:17 +0000 | [diff] [blame] | 9217 | Comments.push_back(new (Context) RawComment( |
| David L. Jones | 13d5a87 | 2018-03-02 00:07:45 +0000 | [diff] [blame] | 9218 | SR, Kind, IsTrailingComment, IsAlmostTrailingComment)); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9219 | break; |
| 9220 | } |
| 9221 | } |
| 9222 | } |
| Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 9223 | NextCursor: |
| Bruno Cardoso Lopes | c23af57 | 2016-12-19 21:06:06 +0000 | [diff] [blame] | 9224 | // De-serialized SourceLocations get negative FileIDs for other modules, |
| 9225 | // potentially invalidating the original order. Sort it again. |
| Fangrui Song | 55fab26 | 2018-09-26 22:16:28 +0000 | [diff] [blame] | 9226 | llvm::sort(Comments, BeforeThanCompare<RawComment>(SourceMgr)); |
| Dmitri Gribenko | 9ee0e30 | 2014-03-27 15:40:39 +0000 | [diff] [blame] | 9227 | Context.Comments.addDeserializedComments(Comments); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9228 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9229 | } |
| 9230 | |
| Argyrios Kyrtzidis | a38cb20 | 2017-01-30 06:05:58 +0000 | [diff] [blame] | 9231 | void ASTReader::visitInputFiles(serialization::ModuleFile &MF, |
| 9232 | bool IncludeSystem, bool Complain, |
| 9233 | llvm::function_ref<void(const serialization::InputFile &IF, |
| 9234 | bool isSystem)> Visitor) { |
| 9235 | unsigned NumUserInputs = MF.NumUserInputFiles; |
| 9236 | unsigned NumInputs = MF.InputFilesLoaded.size(); |
| 9237 | assert(NumUserInputs <= NumInputs); |
| 9238 | unsigned N = IncludeSystem ? NumInputs : NumUserInputs; |
| 9239 | for (unsigned I = 0; I < N; ++I) { |
| 9240 | bool IsSystem = I >= NumUserInputs; |
| 9241 | InputFile IF = getInputFile(MF, I+1, Complain); |
| 9242 | Visitor(IF, IsSystem); |
| 9243 | } |
| 9244 | } |
| 9245 | |
| Richard Smith | f3f8461 | 2017-06-29 02:19:42 +0000 | [diff] [blame] | 9246 | void ASTReader::visitTopLevelModuleMaps( |
| 9247 | serialization::ModuleFile &MF, |
| 9248 | llvm::function_ref<void(const FileEntry *FE)> Visitor) { |
| 9249 | unsigned NumInputs = MF.InputFilesLoaded.size(); |
| 9250 | for (unsigned I = 0; I < NumInputs; ++I) { |
| 9251 | InputFileInfo IFI = readInputFileInfo(MF, I + 1); |
| 9252 | if (IFI.TopLevelModuleMap) |
| 9253 | // FIXME: This unnecessarily re-reads the InputFileInfo. |
| 9254 | if (auto *FE = getInputFile(MF, I + 1).getFile()) |
| 9255 | Visitor(FE); |
| 9256 | } |
| 9257 | } |
| 9258 | |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9259 | std::string ASTReader::getOwningModuleNameForDiagnostic(const Decl *D) { |
| 9260 | // If we know the owning module, use it. |
| Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 9261 | if (Module *M = D->getImportedOwningModule()) |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9262 | return M->getFullModuleName(); |
| 9263 | |
| 9264 | // Otherwise, use the name of the top-level module the decl is within. |
| 9265 | if (ModuleFile *M = getOwningModuleFile(D)) |
| 9266 | return M->ModuleName; |
| 9267 | |
| 9268 | // Not from a module. |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 9269 | return {}; |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9270 | } |
| 9271 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9272 | void ASTReader::finishPendingActions() { |
| Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 9273 | while (!PendingIdentifierInfos.empty() || !PendingFunctionTypes.empty() || |
| Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 9274 | !PendingIncompleteDeclChains.empty() || !PendingDeclChains.empty() || |
| Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 9275 | !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() || |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9276 | !PendingUpdateRecords.empty()) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9277 | // If any identifiers with corresponding top-level declarations have |
| 9278 | // been loaded, load those declarations now. |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 9279 | using TopLevelDeclsMap = |
| 9280 | llvm::DenseMap<IdentifierInfo *, SmallVector<Decl *, 2>>; |
| Craig Topper | 79be4cd | 2013-07-05 04:33:53 +0000 | [diff] [blame] | 9281 | TopLevelDeclsMap TopLevelDecls; |
| 9282 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9283 | while (!PendingIdentifierInfos.empty()) { |
| Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9284 | IdentifierInfo *II = PendingIdentifierInfos.back().first; |
| Richard Smith | f0ae3c2d | 2014-03-28 17:31:23 +0000 | [diff] [blame] | 9285 | SmallVector<uint32_t, 4> DeclIDs = |
| 9286 | std::move(PendingIdentifierInfos.back().second); |
| Douglas Gregor | cb15f08 | 2013-02-19 18:26:28 +0000 | [diff] [blame] | 9287 | PendingIdentifierInfos.pop_back(); |
| Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9288 | |
| 9289 | SetGloballyVisibleDecls(II, DeclIDs, &TopLevelDecls[II]); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9290 | } |
| Richard Smith | f0ae3c2d | 2014-03-28 17:31:23 +0000 | [diff] [blame] | 9291 | |
| Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 9292 | // Load each function type that we deferred loading because it was a |
| 9293 | // deduced type that might refer to a local type declared within itself. |
| 9294 | for (unsigned I = 0; I != PendingFunctionTypes.size(); ++I) { |
| 9295 | auto *FD = PendingFunctionTypes[I].first; |
| 9296 | FD->setType(GetType(PendingFunctionTypes[I].second)); |
| 9297 | |
| 9298 | // If we gave a function a deduced return type, remember that we need to |
| 9299 | // propagate that along the redeclaration chain. |
| 9300 | auto *DT = FD->getReturnType()->getContainedDeducedType(); |
| 9301 | if (DT && DT->isDeduced()) |
| 9302 | PendingDeducedTypeUpdates.insert( |
| 9303 | {FD->getCanonicalDecl(), FD->getReturnType()}); |
| 9304 | } |
| 9305 | PendingFunctionTypes.clear(); |
| 9306 | |
| Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 9307 | // For each decl chain that we wanted to complete while deserializing, mark |
| 9308 | // it as "still needs to be completed". |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9309 | for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) { |
| 9310 | markIncompleteDeclChain(PendingIncompleteDeclChains[I]); |
| 9311 | } |
| Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 9312 | PendingIncompleteDeclChains.clear(); |
| 9313 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9314 | // Load pending declaration chains. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9315 | for (unsigned I = 0; I != PendingDeclChains.size(); ++I) |
| Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 9316 | loadPendingDeclChain(PendingDeclChains[I].first, |
| 9317 | PendingDeclChains[I].second); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9318 | PendingDeclChains.clear(); |
| 9319 | |
| Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9320 | // Make the most recent of the top-level declarations visible. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9321 | for (TopLevelDeclsMap::iterator TLD = TopLevelDecls.begin(), |
| 9322 | TLDEnd = TopLevelDecls.end(); TLD != TLDEnd; ++TLD) { |
| 9323 | IdentifierInfo *II = TLD->first; |
| 9324 | for (unsigned I = 0, N = TLD->second.size(); I != N; ++I) { |
| 9325 | pushExternalDeclIntoScope(cast<NamedDecl>(TLD->second[I]), II); |
| Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 9326 | } |
| 9327 | } |
| 9328 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9329 | // Load any pending macro definitions. |
| 9330 | for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) { |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9331 | IdentifierInfo *II = PendingMacroIDs.begin()[I].first; |
| 9332 | SmallVector<PendingMacroInfo, 2> GlobalIDs; |
| 9333 | GlobalIDs.swap(PendingMacroIDs.begin()[I].second); |
| 9334 | // Initialize the macro history from chained-PCHs ahead of module imports. |
| Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 9335 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
| Argyrios Kyrtzidis | 719736c | 2013-01-19 03:14:56 +0000 | [diff] [blame] | 9336 | ++IDIdx) { |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9337 | const PendingMacroInfo &Info = GlobalIDs[IDIdx]; |
| Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 9338 | if (!Info.M->isModule()) |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9339 | resolvePendingMacro(II, Info); |
| 9340 | } |
| 9341 | // Handle module imports. |
| Richard Smith | 49f906a | 2014-03-01 00:08:04 +0000 | [diff] [blame] | 9342 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9343 | ++IDIdx) { |
| 9344 | const PendingMacroInfo &Info = GlobalIDs[IDIdx]; |
| Manman Ren | 11f2a47 | 2016-08-18 17:42:15 +0000 | [diff] [blame] | 9345 | if (Info.M->isModule()) |
| Argyrios Kyrtzidis | eb663da | 2013-03-22 21:12:57 +0000 | [diff] [blame] | 9346 | resolvePendingMacro(II, Info); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9347 | } |
| 9348 | } |
| 9349 | PendingMacroIDs.clear(); |
| Argyrios Kyrtzidis | 83a6e3b | 2013-02-16 00:48:59 +0000 | [diff] [blame] | 9350 | |
| 9351 | // Wire up the DeclContexts for Decls that we delayed setting until |
| 9352 | // recursive loading is completed. |
| 9353 | while (!PendingDeclContextInfos.empty()) { |
| 9354 | PendingDeclContextInfo Info = PendingDeclContextInfos.front(); |
| 9355 | PendingDeclContextInfos.pop_front(); |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9356 | DeclContext *SemaDC = cast<DeclContext>(GetDecl(Info.SemaDC)); |
| 9357 | DeclContext *LexicalDC = cast<DeclContext>(GetDecl(Info.LexicalDC)); |
| Argyrios Kyrtzidis | 83a6e3b | 2013-02-16 00:48:59 +0000 | [diff] [blame] | 9358 | Info.D->setDeclContextsImpl(SemaDC, LexicalDC, getContext()); |
| 9359 | } |
| Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 9360 | |
| Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 9361 | // Perform any pending declaration updates. |
| Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 9362 | while (!PendingUpdateRecords.empty()) { |
| Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 9363 | auto Update = PendingUpdateRecords.pop_back_val(); |
| 9364 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 9365 | loadDeclUpdateRecords(Update); |
| Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 9366 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9367 | } |
| Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 9368 | |
| 9369 | // At this point, all update records for loaded decls are in place, so any |
| 9370 | // fake class definitions should have become real. |
| 9371 | assert(PendingFakeDefinitionData.empty() && |
| 9372 | "faked up a class definition but never saw the real one"); |
| 9373 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9374 | // If we deserialized any C++ or Objective-C class definitions, any |
| 9375 | // Objective-C protocol definitions, or any redeclarable templates, make sure |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 9376 | // that all redeclarations point to the definitions. Note that this can only |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9377 | // happen now, after the redeclaration chains have been fully wired. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9378 | for (Decl *D : PendingDefinitions) { |
| 9379 | if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
| 9380 | if (const TagType *TagT = dyn_cast<TagType>(TD->getTypeForDecl())) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9381 | // Make sure that the TagType points at the definition. |
| 9382 | const_cast<TagType*>(TagT)->decl = TD; |
| 9383 | } |
| Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9384 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9385 | if (auto RD = dyn_cast<CXXRecordDecl>(D)) { |
| Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9386 | for (auto *R = getMostRecentExistingDecl(RD); R; |
| 9387 | R = R->getPreviousDecl()) { |
| 9388 | assert((R == D) == |
| 9389 | cast<CXXRecordDecl>(R)->isThisDeclarationADefinition() && |
| Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 9390 | "declaration thinks it's the definition but it isn't"); |
| Aaron Ballman | 86c9390 | 2014-03-06 23:45:36 +0000 | [diff] [blame] | 9391 | cast<CXXRecordDecl>(R)->DefinitionData = RD->DefinitionData; |
| Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 9392 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9393 | } |
| 9394 | |
| 9395 | continue; |
| 9396 | } |
| Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9397 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9398 | if (auto ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9399 | // Make sure that the ObjCInterfaceType points at the definition. |
| 9400 | const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl)) |
| 9401 | ->Decl = ID; |
| Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9402 | |
| 9403 | for (auto *R = getMostRecentExistingDecl(ID); R; R = R->getPreviousDecl()) |
| 9404 | cast<ObjCInterfaceDecl>(R)->Data = ID->Data; |
| 9405 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9406 | continue; |
| 9407 | } |
| Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9408 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9409 | if (auto PD = dyn_cast<ObjCProtocolDecl>(D)) { |
| Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9410 | for (auto *R = getMostRecentExistingDecl(PD); R; R = R->getPreviousDecl()) |
| 9411 | cast<ObjCProtocolDecl>(R)->Data = PD->Data; |
| 9412 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9413 | continue; |
| 9414 | } |
| Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9415 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9416 | auto RTD = cast<RedeclarableTemplateDecl>(D)->getCanonicalDecl(); |
| Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 9417 | for (auto *R = getMostRecentExistingDecl(RTD); R; R = R->getPreviousDecl()) |
| 9418 | cast<RedeclarableTemplateDecl>(R)->Common = RTD->Common; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 9419 | } |
| 9420 | PendingDefinitions.clear(); |
| 9421 | |
| Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 9422 | // Load the bodies of any functions or methods we've encountered. We do |
| 9423 | // this now (delayed) so that we can be sure that the declaration chains |
| 9424 | // have been fully wired up (hasBody relies on this). |
| 9425 | // FIXME: We shouldn't require complete redeclaration chains here. |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9426 | for (PendingBodiesMap::iterator PB = PendingBodies.begin(), |
| 9427 | PBEnd = PendingBodies.end(); |
| 9428 | PB != PBEnd; ++PB) { |
| 9429 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(PB->first)) { |
| Richard Smith | 0b70de1 | 2018-06-28 01:07:28 +0000 | [diff] [blame] | 9430 | // For a function defined inline within a class template, force the |
| 9431 | // canonical definition to be the one inside the canonical definition of |
| 9432 | // the template. This ensures that we instantiate from a correct view |
| 9433 | // of the template. |
| 9434 | // |
| 9435 | // Sadly we can't do this more generally: we can't be sure that all |
| 9436 | // copies of an arbitrary class definition will have the same members |
| 9437 | // defined (eg, some member functions may not be instantiated, and some |
| 9438 | // special members may or may not have been implicitly defined). |
| 9439 | if (auto *RD = dyn_cast<CXXRecordDecl>(FD->getLexicalParent())) |
| 9440 | if (RD->isDependentContext() && !RD->isThisDeclarationADefinition()) |
| 9441 | continue; |
| 9442 | |
| Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 9443 | // FIXME: Check for =delete/=default? |
| 9444 | // FIXME: Complain about ODR violations here? |
| 9445 | const FunctionDecl *Defn = nullptr; |
| 9446 | if (!getContext().getLangOpts().Modules || !FD->hasBody(Defn)) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9447 | FD->setLazyBody(PB->second); |
| Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9448 | } else { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9449 | auto *NonConstDefn = const_cast<FunctionDecl*>(Defn); |
| Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9450 | mergeDefinitionVisibility(NonConstDefn, FD); |
| 9451 | |
| 9452 | if (!FD->isLateTemplateParsed() && |
| 9453 | !NonConstDefn->isLateTemplateParsed() && |
| 9454 | FD->getODRHash() != NonConstDefn->getODRHash()) { |
| Richard Trieu | 27c1b1a | 2018-07-10 01:40:50 +0000 | [diff] [blame] | 9455 | if (!isa<CXXMethodDecl>(FD)) { |
| 9456 | PendingFunctionOdrMergeFailures[FD].push_back(NonConstDefn); |
| 9457 | } else if (FD->getLexicalParent()->isFileContext() && |
| 9458 | NonConstDefn->getLexicalParent()->isFileContext()) { |
| 9459 | // Only diagnose out-of-line method definitions. If they are |
| 9460 | // in class definitions, then an error will be generated when |
| 9461 | // processing the class bodies. |
| 9462 | PendingFunctionOdrMergeFailures[FD].push_back(NonConstDefn); |
| 9463 | } |
| Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9464 | } |
| 9465 | } |
| Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 9466 | continue; |
| 9467 | } |
| 9468 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9469 | ObjCMethodDecl *MD = cast<ObjCMethodDecl>(PB->first); |
| Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 9470 | if (!getContext().getLangOpts().Modules || !MD->hasBody()) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9471 | MD->setLazyBody(PB->second); |
| Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 9472 | } |
| 9473 | PendingBodies.clear(); |
| 9474 | |
| Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 9475 | // Do some cleanup. |
| 9476 | for (auto *ND : PendingMergedDefinitionsToDeduplicate) |
| 9477 | getContext().deduplicateMergedDefinitonsFor(ND); |
| 9478 | PendingMergedDefinitionsToDeduplicate.clear(); |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9479 | } |
| 9480 | |
| 9481 | void ASTReader::diagnoseOdrViolations() { |
| Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9482 | if (PendingOdrMergeFailures.empty() && PendingOdrMergeChecks.empty() && |
| Richard Trieu | ab4d730 | 2018-07-25 22:52:05 +0000 | [diff] [blame] | 9483 | PendingFunctionOdrMergeFailures.empty() && |
| 9484 | PendingEnumOdrMergeFailures.empty()) |
| Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 9485 | return; |
| 9486 | |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9487 | // Trigger the import of the full definition of each class that had any |
| 9488 | // odr-merging problems, so we can produce better diagnostics for them. |
| Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 9489 | // These updates may in turn find and diagnose some ODR failures, so take |
| 9490 | // ownership of the set first. |
| 9491 | auto OdrMergeFailures = std::move(PendingOdrMergeFailures); |
| 9492 | PendingOdrMergeFailures.clear(); |
| 9493 | for (auto &Merge : OdrMergeFailures) { |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9494 | Merge.first->buildLookup(); |
| 9495 | Merge.first->decls_begin(); |
| 9496 | Merge.first->bases_begin(); |
| 9497 | Merge.first->vbases_begin(); |
| Richard Trieu | e13eabe | 2017-09-30 02:19:17 +0000 | [diff] [blame] | 9498 | for (auto &RecordPair : Merge.second) { |
| 9499 | auto *RD = RecordPair.first; |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9500 | RD->decls_begin(); |
| 9501 | RD->bases_begin(); |
| 9502 | RD->vbases_begin(); |
| 9503 | } |
| 9504 | } |
| 9505 | |
| Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9506 | // Trigger the import of functions. |
| 9507 | auto FunctionOdrMergeFailures = std::move(PendingFunctionOdrMergeFailures); |
| 9508 | PendingFunctionOdrMergeFailures.clear(); |
| 9509 | for (auto &Merge : FunctionOdrMergeFailures) { |
| 9510 | Merge.first->buildLookup(); |
| 9511 | Merge.first->decls_begin(); |
| 9512 | Merge.first->getBody(); |
| 9513 | for (auto &FD : Merge.second) { |
| 9514 | FD->buildLookup(); |
| 9515 | FD->decls_begin(); |
| 9516 | FD->getBody(); |
| 9517 | } |
| 9518 | } |
| 9519 | |
| Richard Trieu | ab4d730 | 2018-07-25 22:52:05 +0000 | [diff] [blame] | 9520 | // Trigger the import of enums. |
| 9521 | auto EnumOdrMergeFailures = std::move(PendingEnumOdrMergeFailures); |
| 9522 | PendingEnumOdrMergeFailures.clear(); |
| 9523 | for (auto &Merge : EnumOdrMergeFailures) { |
| 9524 | Merge.first->decls_begin(); |
| 9525 | for (auto &Enum : Merge.second) { |
| 9526 | Enum->decls_begin(); |
| 9527 | } |
| 9528 | } |
| 9529 | |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9530 | // For each declaration from a merged context, check that the canonical |
| 9531 | // definition of that context also contains a declaration of the same |
| 9532 | // entity. |
| 9533 | // |
| 9534 | // Caution: this loop does things that might invalidate iterators into |
| 9535 | // PendingOdrMergeChecks. Don't turn this into a range-based for loop! |
| 9536 | while (!PendingOdrMergeChecks.empty()) { |
| 9537 | NamedDecl *D = PendingOdrMergeChecks.pop_back_val(); |
| 9538 | |
| 9539 | // FIXME: Skip over implicit declarations for now. This matters for things |
| 9540 | // like implicitly-declared special member functions. This isn't entirely |
| 9541 | // correct; we can end up with multiple unmerged declarations of the same |
| 9542 | // implicit entity. |
| 9543 | if (D->isImplicit()) |
| 9544 | continue; |
| 9545 | |
| 9546 | DeclContext *CanonDef = D->getDeclContext(); |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9547 | |
| 9548 | bool Found = false; |
| 9549 | const Decl *DCanon = D->getCanonicalDecl(); |
| 9550 | |
| Richard Smith | 01bdb7a | 2014-08-28 05:44:07 +0000 | [diff] [blame] | 9551 | for (auto RI : D->redecls()) { |
| 9552 | if (RI->getLexicalDeclContext() == CanonDef) { |
| 9553 | Found = true; |
| 9554 | break; |
| 9555 | } |
| 9556 | } |
| 9557 | if (Found) |
| 9558 | continue; |
| 9559 | |
| Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9560 | // Quick check failed, time to do the slow thing. Note, we can't just |
| 9561 | // look up the name of D in CanonDef here, because the member that is |
| 9562 | // in CanonDef might not be found by name lookup (it might have been |
| 9563 | // replaced by a more recent declaration in the lookup table), and we |
| 9564 | // can't necessarily find it in the redeclaration chain because it might |
| 9565 | // be merely mergeable, not redeclarable. |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9566 | llvm::SmallVector<const NamedDecl*, 4> Candidates; |
| Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9567 | for (auto *CanonMember : CanonDef->decls()) { |
| 9568 | if (CanonMember->getCanonicalDecl() == DCanon) { |
| 9569 | // This can happen if the declaration is merely mergeable and not |
| 9570 | // actually redeclarable (we looked for redeclarations earlier). |
| 9571 | // |
| 9572 | // FIXME: We should be able to detect this more efficiently, without |
| 9573 | // pulling in all of the members of CanonDef. |
| 9574 | Found = true; |
| 9575 | break; |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9576 | } |
| Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 9577 | if (auto *ND = dyn_cast<NamedDecl>(CanonMember)) |
| 9578 | if (ND->getDeclName() == D->getDeclName()) |
| 9579 | Candidates.push_back(ND); |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9580 | } |
| 9581 | |
| 9582 | if (!Found) { |
| Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 9583 | // The AST doesn't like TagDecls becoming invalid after they've been |
| 9584 | // completed. We only really need to mark FieldDecls as invalid here. |
| 9585 | if (!isa<TagDecl>(D)) |
| 9586 | D->setInvalidDecl(); |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 9587 | |
| Richard Smith | 4ab3dbd | 2015-02-13 22:43:51 +0000 | [diff] [blame] | 9588 | // Ensure we don't accidentally recursively enter deserialization while |
| 9589 | // we're producing our diagnostic. |
| 9590 | Deserializing RecursionGuard(this); |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9591 | |
| 9592 | std::string CanonDefModule = |
| 9593 | getOwningModuleNameForDiagnostic(cast<Decl>(CanonDef)); |
| 9594 | Diag(D->getLocation(), diag::err_module_odr_violation_missing_decl) |
| 9595 | << D << getOwningModuleNameForDiagnostic(D) |
| 9596 | << CanonDef << CanonDefModule.empty() << CanonDefModule; |
| 9597 | |
| 9598 | if (Candidates.empty()) |
| 9599 | Diag(cast<Decl>(CanonDef)->getLocation(), |
| 9600 | diag::note_module_odr_violation_no_possible_decls) << D; |
| 9601 | else { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9602 | for (unsigned I = 0, N = Candidates.size(); I != N; ++I) |
| 9603 | Diag(Candidates[I]->getLocation(), |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9604 | diag::note_module_odr_violation_possible_decl) |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9605 | << Candidates[I]; |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9606 | } |
| 9607 | |
| 9608 | DiagnosedOdrMergeFailures.insert(CanonDef); |
| 9609 | } |
| 9610 | } |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9611 | |
| Richard Trieu | ab4d730 | 2018-07-25 22:52:05 +0000 | [diff] [blame] | 9612 | if (OdrMergeFailures.empty() && FunctionOdrMergeFailures.empty() && |
| 9613 | EnumOdrMergeFailures.empty()) |
| Richard Smith | 4ab3dbd | 2015-02-13 22:43:51 +0000 | [diff] [blame] | 9614 | return; |
| 9615 | |
| 9616 | // Ensure we don't accidentally recursively enter deserialization while |
| 9617 | // we're producing our diagnostics. |
| 9618 | Deserializing RecursionGuard(this); |
| 9619 | |
| Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9620 | // Common code for hashing helpers. |
| 9621 | ODRHash Hash; |
| 9622 | auto ComputeQualTypeODRHash = [&Hash](QualType Ty) { |
| 9623 | Hash.clear(); |
| 9624 | Hash.AddQualType(Ty); |
| 9625 | return Hash.CalculateHash(); |
| 9626 | }; |
| 9627 | |
| 9628 | auto ComputeODRHash = [&Hash](const Stmt *S) { |
| 9629 | assert(S); |
| 9630 | Hash.clear(); |
| 9631 | Hash.AddStmt(S); |
| 9632 | return Hash.CalculateHash(); |
| 9633 | }; |
| 9634 | |
| 9635 | auto ComputeSubDeclODRHash = [&Hash](const Decl *D) { |
| 9636 | assert(D); |
| 9637 | Hash.clear(); |
| 9638 | Hash.AddSubDecl(D); |
| 9639 | return Hash.CalculateHash(); |
| 9640 | }; |
| 9641 | |
| Richard Trieu | 7282d32 | 2018-04-25 00:31:15 +0000 | [diff] [blame] | 9642 | auto ComputeTemplateArgumentODRHash = [&Hash](const TemplateArgument &TA) { |
| 9643 | Hash.clear(); |
| 9644 | Hash.AddTemplateArgument(TA); |
| 9645 | return Hash.CalculateHash(); |
| 9646 | }; |
| 9647 | |
| Richard Trieu | 9359e8f | 2018-05-30 01:12:26 +0000 | [diff] [blame] | 9648 | auto ComputeTemplateParameterListODRHash = |
| 9649 | [&Hash](const TemplateParameterList *TPL) { |
| 9650 | assert(TPL); |
| 9651 | Hash.clear(); |
| 9652 | Hash.AddTemplateParameterList(TPL); |
| 9653 | return Hash.CalculateHash(); |
| 9654 | }; |
| 9655 | |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9656 | // Issue any pending ODR-failure diagnostics. |
| Richard Smith | bb853c7 | 2014-08-13 01:23:33 +0000 | [diff] [blame] | 9657 | for (auto &Merge : OdrMergeFailures) { |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 9658 | // If we've already pointed out a specific problem with this class, don't |
| 9659 | // bother issuing a general "something's different" diagnostic. |
| David Blaikie | 82e95a3 | 2014-11-19 07:49:47 +0000 | [diff] [blame] | 9660 | if (!DiagnosedOdrMergeFailures.insert(Merge.first).second) |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9661 | continue; |
| 9662 | |
| 9663 | bool Diagnosed = false; |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9664 | CXXRecordDecl *FirstRecord = Merge.first; |
| 9665 | std::string FirstModule = getOwningModuleNameForDiagnostic(FirstRecord); |
| Richard Trieu | e13eabe | 2017-09-30 02:19:17 +0000 | [diff] [blame] | 9666 | for (auto &RecordPair : Merge.second) { |
| 9667 | CXXRecordDecl *SecondRecord = RecordPair.first; |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 9668 | // Multiple different declarations got merged together; tell the user |
| 9669 | // where they came from. |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9670 | if (FirstRecord == SecondRecord) |
| 9671 | continue; |
| 9672 | |
| 9673 | std::string SecondModule = getOwningModuleNameForDiagnostic(SecondRecord); |
| Richard Trieu | e13eabe | 2017-09-30 02:19:17 +0000 | [diff] [blame] | 9674 | |
| 9675 | auto *FirstDD = FirstRecord->DefinitionData; |
| 9676 | auto *SecondDD = RecordPair.second; |
| 9677 | |
| 9678 | assert(FirstDD && SecondDD && "Definitions without DefinitionData"); |
| 9679 | |
| 9680 | // Diagnostics from DefinitionData are emitted here. |
| 9681 | if (FirstDD != SecondDD) { |
| 9682 | enum ODRDefinitionDataDifference { |
| 9683 | NumBases, |
| 9684 | NumVBases, |
| 9685 | BaseType, |
| 9686 | BaseVirtual, |
| 9687 | BaseAccess, |
| 9688 | }; |
| 9689 | auto ODRDiagError = [FirstRecord, &FirstModule, |
| 9690 | this](SourceLocation Loc, SourceRange Range, |
| 9691 | ODRDefinitionDataDifference DiffType) { |
| 9692 | return Diag(Loc, diag::err_module_odr_violation_definition_data) |
| 9693 | << FirstRecord << FirstModule.empty() << FirstModule << Range |
| 9694 | << DiffType; |
| 9695 | }; |
| 9696 | auto ODRDiagNote = [&SecondModule, |
| 9697 | this](SourceLocation Loc, SourceRange Range, |
| 9698 | ODRDefinitionDataDifference DiffType) { |
| 9699 | return Diag(Loc, diag::note_module_odr_violation_definition_data) |
| 9700 | << SecondModule << Range << DiffType; |
| 9701 | }; |
| 9702 | |
| Richard Trieu | e13eabe | 2017-09-30 02:19:17 +0000 | [diff] [blame] | 9703 | unsigned FirstNumBases = FirstDD->NumBases; |
| 9704 | unsigned FirstNumVBases = FirstDD->NumVBases; |
| 9705 | unsigned SecondNumBases = SecondDD->NumBases; |
| 9706 | unsigned SecondNumVBases = SecondDD->NumVBases; |
| 9707 | |
| 9708 | auto GetSourceRange = [](struct CXXRecordDecl::DefinitionData *DD) { |
| 9709 | unsigned NumBases = DD->NumBases; |
| 9710 | if (NumBases == 0) return SourceRange(); |
| 9711 | auto bases = DD->bases(); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 9712 | return SourceRange(bases[0].getBeginLoc(), |
| Stephen Kelly | 1c301dc | 2018-08-09 21:09:38 +0000 | [diff] [blame] | 9713 | bases[NumBases - 1].getEndLoc()); |
| Richard Trieu | e13eabe | 2017-09-30 02:19:17 +0000 | [diff] [blame] | 9714 | }; |
| 9715 | |
| 9716 | if (FirstNumBases != SecondNumBases) { |
| 9717 | ODRDiagError(FirstRecord->getLocation(), GetSourceRange(FirstDD), |
| 9718 | NumBases) |
| 9719 | << FirstNumBases; |
| 9720 | ODRDiagNote(SecondRecord->getLocation(), GetSourceRange(SecondDD), |
| 9721 | NumBases) |
| 9722 | << SecondNumBases; |
| 9723 | Diagnosed = true; |
| 9724 | break; |
| 9725 | } |
| 9726 | |
| 9727 | if (FirstNumVBases != SecondNumVBases) { |
| 9728 | ODRDiagError(FirstRecord->getLocation(), GetSourceRange(FirstDD), |
| 9729 | NumVBases) |
| 9730 | << FirstNumVBases; |
| 9731 | ODRDiagNote(SecondRecord->getLocation(), GetSourceRange(SecondDD), |
| 9732 | NumVBases) |
| 9733 | << SecondNumVBases; |
| 9734 | Diagnosed = true; |
| 9735 | break; |
| 9736 | } |
| 9737 | |
| 9738 | auto FirstBases = FirstDD->bases(); |
| 9739 | auto SecondBases = SecondDD->bases(); |
| 9740 | unsigned i = 0; |
| 9741 | for (i = 0; i < FirstNumBases; ++i) { |
| 9742 | auto FirstBase = FirstBases[i]; |
| 9743 | auto SecondBase = SecondBases[i]; |
| 9744 | if (ComputeQualTypeODRHash(FirstBase.getType()) != |
| 9745 | ComputeQualTypeODRHash(SecondBase.getType())) { |
| 9746 | ODRDiagError(FirstRecord->getLocation(), FirstBase.getSourceRange(), |
| 9747 | BaseType) |
| 9748 | << (i + 1) << FirstBase.getType(); |
| 9749 | ODRDiagNote(SecondRecord->getLocation(), |
| 9750 | SecondBase.getSourceRange(), BaseType) |
| 9751 | << (i + 1) << SecondBase.getType(); |
| 9752 | break; |
| 9753 | } |
| 9754 | |
| 9755 | if (FirstBase.isVirtual() != SecondBase.isVirtual()) { |
| 9756 | ODRDiagError(FirstRecord->getLocation(), FirstBase.getSourceRange(), |
| 9757 | BaseVirtual) |
| 9758 | << (i + 1) << FirstBase.isVirtual() << FirstBase.getType(); |
| 9759 | ODRDiagNote(SecondRecord->getLocation(), |
| 9760 | SecondBase.getSourceRange(), BaseVirtual) |
| 9761 | << (i + 1) << SecondBase.isVirtual() << SecondBase.getType(); |
| 9762 | break; |
| 9763 | } |
| 9764 | |
| 9765 | if (FirstBase.getAccessSpecifierAsWritten() != |
| 9766 | SecondBase.getAccessSpecifierAsWritten()) { |
| 9767 | ODRDiagError(FirstRecord->getLocation(), FirstBase.getSourceRange(), |
| 9768 | BaseAccess) |
| 9769 | << (i + 1) << FirstBase.getType() |
| 9770 | << (int)FirstBase.getAccessSpecifierAsWritten(); |
| 9771 | ODRDiagNote(SecondRecord->getLocation(), |
| 9772 | SecondBase.getSourceRange(), BaseAccess) |
| 9773 | << (i + 1) << SecondBase.getType() |
| 9774 | << (int)SecondBase.getAccessSpecifierAsWritten(); |
| 9775 | break; |
| 9776 | } |
| 9777 | } |
| 9778 | |
| 9779 | if (i != FirstNumBases) { |
| 9780 | Diagnosed = true; |
| 9781 | break; |
| 9782 | } |
| 9783 | } |
| 9784 | |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9785 | using DeclHashes = llvm::SmallVector<std::pair<Decl *, unsigned>, 4>; |
| Richard Trieu | 498117b | 2017-08-23 02:43:59 +0000 | [diff] [blame] | 9786 | |
| 9787 | const ClassTemplateDecl *FirstTemplate = |
| 9788 | FirstRecord->getDescribedClassTemplate(); |
| 9789 | const ClassTemplateDecl *SecondTemplate = |
| 9790 | SecondRecord->getDescribedClassTemplate(); |
| 9791 | |
| 9792 | assert(!FirstTemplate == !SecondTemplate && |
| 9793 | "Both pointers should be null or non-null"); |
| 9794 | |
| 9795 | enum ODRTemplateDifference { |
| 9796 | ParamEmptyName, |
| 9797 | ParamName, |
| 9798 | ParamSingleDefaultArgument, |
| 9799 | ParamDifferentDefaultArgument, |
| 9800 | }; |
| 9801 | |
| 9802 | if (FirstTemplate && SecondTemplate) { |
| 9803 | DeclHashes FirstTemplateHashes; |
| 9804 | DeclHashes SecondTemplateHashes; |
| Richard Trieu | 498117b | 2017-08-23 02:43:59 +0000 | [diff] [blame] | 9805 | |
| 9806 | auto PopulateTemplateParameterHashs = |
| Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9807 | [&ComputeSubDeclODRHash](DeclHashes &Hashes, |
| 9808 | const ClassTemplateDecl *TD) { |
| Richard Trieu | 498117b | 2017-08-23 02:43:59 +0000 | [diff] [blame] | 9809 | for (auto *D : TD->getTemplateParameters()->asArray()) { |
| Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9810 | Hashes.emplace_back(D, ComputeSubDeclODRHash(D)); |
| Richard Trieu | 498117b | 2017-08-23 02:43:59 +0000 | [diff] [blame] | 9811 | } |
| 9812 | }; |
| 9813 | |
| 9814 | PopulateTemplateParameterHashs(FirstTemplateHashes, FirstTemplate); |
| 9815 | PopulateTemplateParameterHashs(SecondTemplateHashes, SecondTemplate); |
| 9816 | |
| 9817 | assert(FirstTemplateHashes.size() == SecondTemplateHashes.size() && |
| 9818 | "Number of template parameters should be equal."); |
| 9819 | |
| 9820 | auto FirstIt = FirstTemplateHashes.begin(); |
| 9821 | auto FirstEnd = FirstTemplateHashes.end(); |
| 9822 | auto SecondIt = SecondTemplateHashes.begin(); |
| 9823 | for (; FirstIt != FirstEnd; ++FirstIt, ++SecondIt) { |
| 9824 | if (FirstIt->second == SecondIt->second) |
| 9825 | continue; |
| 9826 | |
| 9827 | auto ODRDiagError = [FirstRecord, &FirstModule, |
| 9828 | this](SourceLocation Loc, SourceRange Range, |
| 9829 | ODRTemplateDifference DiffType) { |
| 9830 | return Diag(Loc, diag::err_module_odr_violation_template_parameter) |
| 9831 | << FirstRecord << FirstModule.empty() << FirstModule << Range |
| 9832 | << DiffType; |
| 9833 | }; |
| 9834 | auto ODRDiagNote = [&SecondModule, |
| 9835 | this](SourceLocation Loc, SourceRange Range, |
| 9836 | ODRTemplateDifference DiffType) { |
| 9837 | return Diag(Loc, diag::note_module_odr_violation_template_parameter) |
| 9838 | << SecondModule << Range << DiffType; |
| 9839 | }; |
| 9840 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 9841 | const NamedDecl* FirstDecl = cast<NamedDecl>(FirstIt->first); |
| 9842 | const NamedDecl* SecondDecl = cast<NamedDecl>(SecondIt->first); |
| Richard Trieu | 498117b | 2017-08-23 02:43:59 +0000 | [diff] [blame] | 9843 | |
| 9844 | assert(FirstDecl->getKind() == SecondDecl->getKind() && |
| 9845 | "Parameter Decl's should be the same kind."); |
| 9846 | |
| 9847 | DeclarationName FirstName = FirstDecl->getDeclName(); |
| 9848 | DeclarationName SecondName = SecondDecl->getDeclName(); |
| 9849 | |
| 9850 | if (FirstName != SecondName) { |
| 9851 | const bool FirstNameEmpty = |
| 9852 | FirstName.isIdentifier() && !FirstName.getAsIdentifierInfo(); |
| 9853 | const bool SecondNameEmpty = |
| 9854 | SecondName.isIdentifier() && !SecondName.getAsIdentifierInfo(); |
| 9855 | assert((!FirstNameEmpty || !SecondNameEmpty) && |
| 9856 | "Both template parameters cannot be unnamed."); |
| 9857 | ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(), |
| 9858 | FirstNameEmpty ? ParamEmptyName : ParamName) |
| 9859 | << FirstName; |
| 9860 | ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(), |
| 9861 | SecondNameEmpty ? ParamEmptyName : ParamName) |
| 9862 | << SecondName; |
| 9863 | break; |
| 9864 | } |
| 9865 | |
| 9866 | switch (FirstDecl->getKind()) { |
| 9867 | default: |
| 9868 | llvm_unreachable("Invalid template parameter type."); |
| 9869 | case Decl::TemplateTypeParm: { |
| 9870 | const auto *FirstParam = cast<TemplateTypeParmDecl>(FirstDecl); |
| 9871 | const auto *SecondParam = cast<TemplateTypeParmDecl>(SecondDecl); |
| 9872 | const bool HasFirstDefaultArgument = |
| 9873 | FirstParam->hasDefaultArgument() && |
| 9874 | !FirstParam->defaultArgumentWasInherited(); |
| 9875 | const bool HasSecondDefaultArgument = |
| 9876 | SecondParam->hasDefaultArgument() && |
| 9877 | !SecondParam->defaultArgumentWasInherited(); |
| 9878 | |
| 9879 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 9880 | ODRDiagError(FirstDecl->getLocation(), |
| 9881 | FirstDecl->getSourceRange(), |
| 9882 | ParamSingleDefaultArgument) |
| 9883 | << HasFirstDefaultArgument; |
| 9884 | ODRDiagNote(SecondDecl->getLocation(), |
| 9885 | SecondDecl->getSourceRange(), |
| 9886 | ParamSingleDefaultArgument) |
| 9887 | << HasSecondDefaultArgument; |
| 9888 | break; |
| 9889 | } |
| 9890 | |
| 9891 | assert(HasFirstDefaultArgument && HasSecondDefaultArgument && |
| 9892 | "Expecting default arguments."); |
| 9893 | |
| 9894 | ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(), |
| 9895 | ParamDifferentDefaultArgument); |
| 9896 | ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(), |
| 9897 | ParamDifferentDefaultArgument); |
| 9898 | |
| 9899 | break; |
| 9900 | } |
| 9901 | case Decl::NonTypeTemplateParm: { |
| 9902 | const auto *FirstParam = cast<NonTypeTemplateParmDecl>(FirstDecl); |
| 9903 | const auto *SecondParam = cast<NonTypeTemplateParmDecl>(SecondDecl); |
| 9904 | const bool HasFirstDefaultArgument = |
| 9905 | FirstParam->hasDefaultArgument() && |
| 9906 | !FirstParam->defaultArgumentWasInherited(); |
| 9907 | const bool HasSecondDefaultArgument = |
| 9908 | SecondParam->hasDefaultArgument() && |
| 9909 | !SecondParam->defaultArgumentWasInherited(); |
| 9910 | |
| 9911 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 9912 | ODRDiagError(FirstDecl->getLocation(), |
| 9913 | FirstDecl->getSourceRange(), |
| 9914 | ParamSingleDefaultArgument) |
| 9915 | << HasFirstDefaultArgument; |
| 9916 | ODRDiagNote(SecondDecl->getLocation(), |
| 9917 | SecondDecl->getSourceRange(), |
| 9918 | ParamSingleDefaultArgument) |
| 9919 | << HasSecondDefaultArgument; |
| 9920 | break; |
| 9921 | } |
| 9922 | |
| 9923 | assert(HasFirstDefaultArgument && HasSecondDefaultArgument && |
| 9924 | "Expecting default arguments."); |
| 9925 | |
| 9926 | ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(), |
| 9927 | ParamDifferentDefaultArgument); |
| 9928 | ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(), |
| 9929 | ParamDifferentDefaultArgument); |
| 9930 | |
| 9931 | break; |
| 9932 | } |
| 9933 | case Decl::TemplateTemplateParm: { |
| 9934 | const auto *FirstParam = cast<TemplateTemplateParmDecl>(FirstDecl); |
| 9935 | const auto *SecondParam = |
| 9936 | cast<TemplateTemplateParmDecl>(SecondDecl); |
| 9937 | const bool HasFirstDefaultArgument = |
| 9938 | FirstParam->hasDefaultArgument() && |
| 9939 | !FirstParam->defaultArgumentWasInherited(); |
| 9940 | const bool HasSecondDefaultArgument = |
| 9941 | SecondParam->hasDefaultArgument() && |
| 9942 | !SecondParam->defaultArgumentWasInherited(); |
| 9943 | |
| 9944 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 9945 | ODRDiagError(FirstDecl->getLocation(), |
| 9946 | FirstDecl->getSourceRange(), |
| 9947 | ParamSingleDefaultArgument) |
| 9948 | << HasFirstDefaultArgument; |
| 9949 | ODRDiagNote(SecondDecl->getLocation(), |
| 9950 | SecondDecl->getSourceRange(), |
| 9951 | ParamSingleDefaultArgument) |
| 9952 | << HasSecondDefaultArgument; |
| 9953 | break; |
| 9954 | } |
| 9955 | |
| 9956 | assert(HasFirstDefaultArgument && HasSecondDefaultArgument && |
| 9957 | "Expecting default arguments."); |
| 9958 | |
| 9959 | ODRDiagError(FirstDecl->getLocation(), FirstDecl->getSourceRange(), |
| 9960 | ParamDifferentDefaultArgument); |
| 9961 | ODRDiagNote(SecondDecl->getLocation(), SecondDecl->getSourceRange(), |
| 9962 | ParamDifferentDefaultArgument); |
| 9963 | |
| 9964 | break; |
| 9965 | } |
| 9966 | } |
| 9967 | |
| 9968 | break; |
| 9969 | } |
| 9970 | |
| 9971 | if (FirstIt != FirstEnd) { |
| 9972 | Diagnosed = true; |
| 9973 | break; |
| 9974 | } |
| 9975 | } |
| 9976 | |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9977 | DeclHashes FirstHashes; |
| 9978 | DeclHashes SecondHashes; |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9979 | |
| Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9980 | auto PopulateHashes = [&ComputeSubDeclODRHash, FirstRecord]( |
| 9981 | DeclHashes &Hashes, CXXRecordDecl *Record) { |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9982 | for (auto *D : Record->decls()) { |
| 9983 | // Due to decl merging, the first CXXRecordDecl is the parent of |
| 9984 | // Decls in both records. |
| 9985 | if (!ODRHash::isWhitelistedDecl(D, FirstRecord)) |
| 9986 | continue; |
| Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 9987 | Hashes.emplace_back(D, ComputeSubDeclODRHash(D)); |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9988 | } |
| 9989 | }; |
| 9990 | PopulateHashes(FirstHashes, FirstRecord); |
| 9991 | PopulateHashes(SecondHashes, SecondRecord); |
| 9992 | |
| 9993 | // Used with err_module_odr_violation_mismatch_decl and |
| 9994 | // note_module_odr_violation_mismatch_decl |
| Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 9995 | // This list should be the same Decl's as in ODRHash::isWhiteListedDecl |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 9996 | enum { |
| 9997 | EndOfClass, |
| 9998 | PublicSpecifer, |
| 9999 | PrivateSpecifer, |
| 10000 | ProtectedSpecifer, |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10001 | StaticAssert, |
| Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 10002 | Field, |
| Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10003 | CXXMethod, |
| Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 10004 | TypeAlias, |
| 10005 | TypeDef, |
| Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10006 | Var, |
| Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 10007 | Friend, |
| Richard Trieu | 9359e8f | 2018-05-30 01:12:26 +0000 | [diff] [blame] | 10008 | FunctionTemplate, |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 10009 | Other |
| 10010 | } FirstDiffType = Other, |
| 10011 | SecondDiffType = Other; |
| 10012 | |
| 10013 | auto DifferenceSelector = [](Decl *D) { |
| 10014 | assert(D && "valid Decl required"); |
| 10015 | switch (D->getKind()) { |
| 10016 | default: |
| 10017 | return Other; |
| 10018 | case Decl::AccessSpec: |
| 10019 | switch (D->getAccess()) { |
| 10020 | case AS_public: |
| 10021 | return PublicSpecifer; |
| 10022 | case AS_private: |
| 10023 | return PrivateSpecifer; |
| 10024 | case AS_protected: |
| 10025 | return ProtectedSpecifer; |
| 10026 | case AS_none: |
| Simon Pilgrim | eeb1b30 | 2017-02-22 13:21:24 +0000 | [diff] [blame] | 10027 | break; |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 10028 | } |
| Simon Pilgrim | eeb1b30 | 2017-02-22 13:21:24 +0000 | [diff] [blame] | 10029 | llvm_unreachable("Invalid access specifier"); |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10030 | case Decl::StaticAssert: |
| 10031 | return StaticAssert; |
| Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 10032 | case Decl::Field: |
| 10033 | return Field; |
| Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10034 | case Decl::CXXMethod: |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10035 | case Decl::CXXConstructor: |
| 10036 | case Decl::CXXDestructor: |
| Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10037 | return CXXMethod; |
| Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 10038 | case Decl::TypeAlias: |
| 10039 | return TypeAlias; |
| 10040 | case Decl::Typedef: |
| 10041 | return TypeDef; |
| Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10042 | case Decl::Var: |
| 10043 | return Var; |
| Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 10044 | case Decl::Friend: |
| 10045 | return Friend; |
| Richard Trieu | 9359e8f | 2018-05-30 01:12:26 +0000 | [diff] [blame] | 10046 | case Decl::FunctionTemplate: |
| 10047 | return FunctionTemplate; |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 10048 | } |
| 10049 | }; |
| 10050 | |
| 10051 | Decl *FirstDecl = nullptr; |
| 10052 | Decl *SecondDecl = nullptr; |
| 10053 | auto FirstIt = FirstHashes.begin(); |
| 10054 | auto SecondIt = SecondHashes.begin(); |
| 10055 | |
| 10056 | // If there is a diagnoseable difference, FirstDiffType and |
| 10057 | // SecondDiffType will not be Other and FirstDecl and SecondDecl will be |
| 10058 | // filled in if not EndOfClass. |
| 10059 | while (FirstIt != FirstHashes.end() || SecondIt != SecondHashes.end()) { |
| Benjamin Kramer | 6f224d2 | 2017-02-22 10:19:45 +0000 | [diff] [blame] | 10060 | if (FirstIt != FirstHashes.end() && SecondIt != SecondHashes.end() && |
| 10061 | FirstIt->second == SecondIt->second) { |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 10062 | ++FirstIt; |
| 10063 | ++SecondIt; |
| 10064 | continue; |
| Richard Trieu | dc4cb02 | 2017-02-17 07:19:24 +0000 | [diff] [blame] | 10065 | } |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 10066 | |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 10067 | FirstDecl = FirstIt == FirstHashes.end() ? nullptr : FirstIt->first; |
| 10068 | SecondDecl = SecondIt == SecondHashes.end() ? nullptr : SecondIt->first; |
| 10069 | |
| 10070 | FirstDiffType = FirstDecl ? DifferenceSelector(FirstDecl) : EndOfClass; |
| 10071 | SecondDiffType = |
| 10072 | SecondDecl ? DifferenceSelector(SecondDecl) : EndOfClass; |
| 10073 | |
| 10074 | break; |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 10075 | } |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 10076 | |
| 10077 | if (FirstDiffType == Other || SecondDiffType == Other) { |
| 10078 | // Reaching this point means an unexpected Decl was encountered |
| 10079 | // or no difference was detected. This causes a generic error |
| 10080 | // message to be emitted. |
| 10081 | Diag(FirstRecord->getLocation(), |
| 10082 | diag::err_module_odr_violation_different_definitions) |
| 10083 | << FirstRecord << FirstModule.empty() << FirstModule; |
| 10084 | |
| Richard Trieu | ca48d36 | 2017-06-21 01:43:13 +0000 | [diff] [blame] | 10085 | if (FirstDecl) { |
| 10086 | Diag(FirstDecl->getLocation(), diag::note_first_module_difference) |
| 10087 | << FirstRecord << FirstDecl->getSourceRange(); |
| 10088 | } |
| 10089 | |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 10090 | Diag(SecondRecord->getLocation(), |
| 10091 | diag::note_module_odr_violation_different_definitions) |
| 10092 | << SecondModule; |
| Richard Trieu | ca48d36 | 2017-06-21 01:43:13 +0000 | [diff] [blame] | 10093 | |
| 10094 | if (SecondDecl) { |
| 10095 | Diag(SecondDecl->getLocation(), diag::note_second_module_difference) |
| 10096 | << SecondDecl->getSourceRange(); |
| 10097 | } |
| 10098 | |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 10099 | Diagnosed = true; |
| 10100 | break; |
| 10101 | } |
| 10102 | |
| 10103 | if (FirstDiffType != SecondDiffType) { |
| 10104 | SourceLocation FirstLoc; |
| 10105 | SourceRange FirstRange; |
| 10106 | if (FirstDiffType == EndOfClass) { |
| 10107 | FirstLoc = FirstRecord->getBraceRange().getEnd(); |
| 10108 | } else { |
| 10109 | FirstLoc = FirstIt->first->getLocation(); |
| 10110 | FirstRange = FirstIt->first->getSourceRange(); |
| 10111 | } |
| 10112 | Diag(FirstLoc, diag::err_module_odr_violation_mismatch_decl) |
| 10113 | << FirstRecord << FirstModule.empty() << FirstModule << FirstRange |
| 10114 | << FirstDiffType; |
| 10115 | |
| 10116 | SourceLocation SecondLoc; |
| 10117 | SourceRange SecondRange; |
| 10118 | if (SecondDiffType == EndOfClass) { |
| 10119 | SecondLoc = SecondRecord->getBraceRange().getEnd(); |
| 10120 | } else { |
| 10121 | SecondLoc = SecondDecl->getLocation(); |
| 10122 | SecondRange = SecondDecl->getSourceRange(); |
| 10123 | } |
| 10124 | Diag(SecondLoc, diag::note_module_odr_violation_mismatch_decl) |
| 10125 | << SecondModule << SecondRange << SecondDiffType; |
| 10126 | Diagnosed = true; |
| 10127 | break; |
| 10128 | } |
| 10129 | |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10130 | assert(FirstDiffType == SecondDiffType); |
| 10131 | |
| 10132 | // Used with err_module_odr_violation_mismatch_decl_diff and |
| 10133 | // note_module_odr_violation_mismatch_decl_diff |
| Richard Trieu | 9359e8f | 2018-05-30 01:12:26 +0000 | [diff] [blame] | 10134 | enum ODRDeclDifference { |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10135 | StaticAssertCondition, |
| 10136 | StaticAssertMessage, |
| 10137 | StaticAssertOnlyMessage, |
| Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 10138 | FieldName, |
| Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 10139 | FieldTypeName, |
| Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 10140 | FieldSingleBitField, |
| Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 10141 | FieldDifferentWidthBitField, |
| 10142 | FieldSingleMutable, |
| 10143 | FieldSingleInitializer, |
| 10144 | FieldDifferentInitializers, |
| Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10145 | MethodName, |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10146 | MethodDeleted, |
| Richard Trieu | 27c1b1a | 2018-07-10 01:40:50 +0000 | [diff] [blame] | 10147 | MethodDefaulted, |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10148 | MethodVirtual, |
| 10149 | MethodStatic, |
| 10150 | MethodVolatile, |
| 10151 | MethodConst, |
| 10152 | MethodInline, |
| Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10153 | MethodNumberParameters, |
| 10154 | MethodParameterType, |
| 10155 | MethodParameterName, |
| Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10156 | MethodParameterSingleDefaultArgument, |
| 10157 | MethodParameterDifferentDefaultArgument, |
| Richard Trieu | 7282d32 | 2018-04-25 00:31:15 +0000 | [diff] [blame] | 10158 | MethodNoTemplateArguments, |
| 10159 | MethodDifferentNumberTemplateArguments, |
| 10160 | MethodDifferentTemplateArgument, |
| Richard Trieu | 27c1b1a | 2018-07-10 01:40:50 +0000 | [diff] [blame] | 10161 | MethodSingleBody, |
| 10162 | MethodDifferentBody, |
| Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 10163 | TypedefName, |
| 10164 | TypedefType, |
| Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10165 | VarName, |
| 10166 | VarType, |
| 10167 | VarSingleInitializer, |
| 10168 | VarDifferentInitializer, |
| 10169 | VarConstexpr, |
| Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 10170 | FriendTypeFunction, |
| 10171 | FriendType, |
| 10172 | FriendFunction, |
| Richard Trieu | 9359e8f | 2018-05-30 01:12:26 +0000 | [diff] [blame] | 10173 | FunctionTemplateDifferentNumberParameters, |
| 10174 | FunctionTemplateParameterDifferentKind, |
| 10175 | FunctionTemplateParameterName, |
| 10176 | FunctionTemplateParameterSingleDefaultArgument, |
| 10177 | FunctionTemplateParameterDifferentDefaultArgument, |
| 10178 | FunctionTemplateParameterDifferentType, |
| 10179 | FunctionTemplatePackParameter, |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10180 | }; |
| 10181 | |
| 10182 | // These lambdas have the common portions of the ODR diagnostics. This |
| 10183 | // has the same return as Diag(), so addition parameters can be passed |
| 10184 | // in with operator<< |
| 10185 | auto ODRDiagError = [FirstRecord, &FirstModule, this]( |
| 10186 | SourceLocation Loc, SourceRange Range, ODRDeclDifference DiffType) { |
| 10187 | return Diag(Loc, diag::err_module_odr_violation_mismatch_decl_diff) |
| 10188 | << FirstRecord << FirstModule.empty() << FirstModule << Range |
| 10189 | << DiffType; |
| 10190 | }; |
| 10191 | auto ODRDiagNote = [&SecondModule, this]( |
| 10192 | SourceLocation Loc, SourceRange Range, ODRDeclDifference DiffType) { |
| 10193 | return Diag(Loc, diag::note_module_odr_violation_mismatch_decl_diff) |
| 10194 | << SecondModule << Range << DiffType; |
| 10195 | }; |
| 10196 | |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10197 | switch (FirstDiffType) { |
| 10198 | case Other: |
| 10199 | case EndOfClass: |
| 10200 | case PublicSpecifer: |
| 10201 | case PrivateSpecifer: |
| 10202 | case ProtectedSpecifer: |
| 10203 | llvm_unreachable("Invalid diff type"); |
| 10204 | |
| 10205 | case StaticAssert: { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 10206 | StaticAssertDecl *FirstSA = cast<StaticAssertDecl>(FirstDecl); |
| 10207 | StaticAssertDecl *SecondSA = cast<StaticAssertDecl>(SecondDecl); |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10208 | |
| 10209 | Expr *FirstExpr = FirstSA->getAssertExpr(); |
| 10210 | Expr *SecondExpr = SecondSA->getAssertExpr(); |
| 10211 | unsigned FirstODRHash = ComputeODRHash(FirstExpr); |
| 10212 | unsigned SecondODRHash = ComputeODRHash(SecondExpr); |
| 10213 | if (FirstODRHash != SecondODRHash) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10214 | ODRDiagError(FirstExpr->getBeginLoc(), FirstExpr->getSourceRange(), |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10215 | StaticAssertCondition); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10216 | ODRDiagNote(SecondExpr->getBeginLoc(), SecondExpr->getSourceRange(), |
| 10217 | StaticAssertCondition); |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10218 | Diagnosed = true; |
| 10219 | break; |
| 10220 | } |
| 10221 | |
| 10222 | StringLiteral *FirstStr = FirstSA->getMessage(); |
| 10223 | StringLiteral *SecondStr = SecondSA->getMessage(); |
| 10224 | assert((FirstStr || SecondStr) && "Both messages cannot be empty"); |
| 10225 | if ((FirstStr && !SecondStr) || (!FirstStr && SecondStr)) { |
| 10226 | SourceLocation FirstLoc, SecondLoc; |
| 10227 | SourceRange FirstRange, SecondRange; |
| 10228 | if (FirstStr) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10229 | FirstLoc = FirstStr->getBeginLoc(); |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10230 | FirstRange = FirstStr->getSourceRange(); |
| 10231 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10232 | FirstLoc = FirstSA->getBeginLoc(); |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10233 | FirstRange = FirstSA->getSourceRange(); |
| 10234 | } |
| 10235 | if (SecondStr) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10236 | SecondLoc = SecondStr->getBeginLoc(); |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10237 | SecondRange = SecondStr->getSourceRange(); |
| 10238 | } else { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10239 | SecondLoc = SecondSA->getBeginLoc(); |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10240 | SecondRange = SecondSA->getSourceRange(); |
| 10241 | } |
| 10242 | ODRDiagError(FirstLoc, FirstRange, StaticAssertOnlyMessage) |
| 10243 | << (FirstStr == nullptr); |
| 10244 | ODRDiagNote(SecondLoc, SecondRange, StaticAssertOnlyMessage) |
| 10245 | << (SecondStr == nullptr); |
| 10246 | Diagnosed = true; |
| 10247 | break; |
| 10248 | } |
| 10249 | |
| 10250 | if (FirstStr && SecondStr && |
| 10251 | FirstStr->getString() != SecondStr->getString()) { |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10252 | ODRDiagError(FirstStr->getBeginLoc(), FirstStr->getSourceRange(), |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10253 | StaticAssertMessage); |
| Stephen Kelly | f2ceec4 | 2018-08-09 21:08:08 +0000 | [diff] [blame] | 10254 | ODRDiagNote(SecondStr->getBeginLoc(), SecondStr->getSourceRange(), |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 10255 | StaticAssertMessage); |
| 10256 | Diagnosed = true; |
| 10257 | break; |
| 10258 | } |
| 10259 | break; |
| 10260 | } |
| Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 10261 | case Field: { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 10262 | FieldDecl *FirstField = cast<FieldDecl>(FirstDecl); |
| 10263 | FieldDecl *SecondField = cast<FieldDecl>(SecondDecl); |
| Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 10264 | IdentifierInfo *FirstII = FirstField->getIdentifier(); |
| 10265 | IdentifierInfo *SecondII = SecondField->getIdentifier(); |
| 10266 | if (FirstII->getName() != SecondII->getName()) { |
| 10267 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 10268 | FieldName) |
| 10269 | << FirstII; |
| 10270 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 10271 | FieldName) |
| 10272 | << SecondII; |
| 10273 | |
| 10274 | Diagnosed = true; |
| 10275 | break; |
| 10276 | } |
| Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 10277 | |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 10278 | assert(getContext().hasSameType(FirstField->getType(), |
| 10279 | SecondField->getType())); |
| Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 10280 | |
| 10281 | QualType FirstType = FirstField->getType(); |
| 10282 | QualType SecondType = SecondField->getType(); |
| Richard Trieu | ce81b19 | 2017-05-17 03:23:35 +0000 | [diff] [blame] | 10283 | if (ComputeQualTypeODRHash(FirstType) != |
| 10284 | ComputeQualTypeODRHash(SecondType)) { |
| Richard Trieu | 8459ddf | 2017-02-24 02:59:12 +0000 | [diff] [blame] | 10285 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 10286 | FieldTypeName) |
| 10287 | << FirstII << FirstType; |
| 10288 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 10289 | FieldTypeName) |
| 10290 | << SecondII << SecondType; |
| 10291 | |
| 10292 | Diagnosed = true; |
| 10293 | break; |
| 10294 | } |
| 10295 | |
| Richard Trieu | 93772fc | 2017-02-24 20:59:28 +0000 | [diff] [blame] | 10296 | const bool IsFirstBitField = FirstField->isBitField(); |
| 10297 | const bool IsSecondBitField = SecondField->isBitField(); |
| 10298 | if (IsFirstBitField != IsSecondBitField) { |
| 10299 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 10300 | FieldSingleBitField) |
| 10301 | << FirstII << IsFirstBitField; |
| 10302 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 10303 | FieldSingleBitField) |
| 10304 | << SecondII << IsSecondBitField; |
| 10305 | Diagnosed = true; |
| 10306 | break; |
| 10307 | } |
| 10308 | |
| 10309 | if (IsFirstBitField && IsSecondBitField) { |
| 10310 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 10311 | FieldDifferentWidthBitField) |
| 10312 | << FirstII << FirstField->getBitWidth()->getSourceRange(); |
| 10313 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 10314 | FieldDifferentWidthBitField) |
| 10315 | << SecondII << SecondField->getBitWidth()->getSourceRange(); |
| 10316 | Diagnosed = true; |
| 10317 | break; |
| 10318 | } |
| 10319 | |
| Richard Trieu | 8d543e2 | 2017-02-24 23:35:37 +0000 | [diff] [blame] | 10320 | const bool IsFirstMutable = FirstField->isMutable(); |
| 10321 | const bool IsSecondMutable = SecondField->isMutable(); |
| 10322 | if (IsFirstMutable != IsSecondMutable) { |
| 10323 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 10324 | FieldSingleMutable) |
| 10325 | << FirstII << IsFirstMutable; |
| 10326 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 10327 | FieldSingleMutable) |
| 10328 | << SecondII << IsSecondMutable; |
| 10329 | Diagnosed = true; |
| 10330 | break; |
| 10331 | } |
| 10332 | |
| 10333 | const Expr *FirstInitializer = FirstField->getInClassInitializer(); |
| 10334 | const Expr *SecondInitializer = SecondField->getInClassInitializer(); |
| 10335 | if ((!FirstInitializer && SecondInitializer) || |
| 10336 | (FirstInitializer && !SecondInitializer)) { |
| 10337 | ODRDiagError(FirstField->getLocation(), FirstField->getSourceRange(), |
| 10338 | FieldSingleInitializer) |
| 10339 | << FirstII << (FirstInitializer != nullptr); |
| 10340 | ODRDiagNote(SecondField->getLocation(), SecondField->getSourceRange(), |
| 10341 | FieldSingleInitializer) |
| 10342 | << SecondII << (SecondInitializer != nullptr); |
| 10343 | Diagnosed = true; |
| 10344 | break; |
| 10345 | } |
| 10346 | |
| 10347 | if (FirstInitializer && SecondInitializer) { |
| 10348 | unsigned FirstInitHash = ComputeODRHash(FirstInitializer); |
| 10349 | unsigned SecondInitHash = ComputeODRHash(SecondInitializer); |
| 10350 | if (FirstInitHash != SecondInitHash) { |
| 10351 | ODRDiagError(FirstField->getLocation(), |
| 10352 | FirstField->getSourceRange(), |
| 10353 | FieldDifferentInitializers) |
| 10354 | << FirstII << FirstInitializer->getSourceRange(); |
| 10355 | ODRDiagNote(SecondField->getLocation(), |
| 10356 | SecondField->getSourceRange(), |
| 10357 | FieldDifferentInitializers) |
| 10358 | << SecondII << SecondInitializer->getSourceRange(); |
| 10359 | Diagnosed = true; |
| 10360 | break; |
| 10361 | } |
| 10362 | } |
| 10363 | |
| Richard Trieu | d078609 | 2017-02-23 00:23:01 +0000 | [diff] [blame] | 10364 | break; |
| 10365 | } |
| Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10366 | case CXXMethod: { |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10367 | enum { |
| 10368 | DiagMethod, |
| 10369 | DiagConstructor, |
| 10370 | DiagDestructor, |
| 10371 | } FirstMethodType, |
| 10372 | SecondMethodType; |
| 10373 | auto GetMethodTypeForDiagnostics = [](const CXXMethodDecl* D) { |
| 10374 | if (isa<CXXConstructorDecl>(D)) return DiagConstructor; |
| 10375 | if (isa<CXXDestructorDecl>(D)) return DiagDestructor; |
| 10376 | return DiagMethod; |
| 10377 | }; |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 10378 | const CXXMethodDecl *FirstMethod = cast<CXXMethodDecl>(FirstDecl); |
| 10379 | const CXXMethodDecl *SecondMethod = cast<CXXMethodDecl>(SecondDecl); |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10380 | FirstMethodType = GetMethodTypeForDiagnostics(FirstMethod); |
| 10381 | SecondMethodType = GetMethodTypeForDiagnostics(SecondMethod); |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10382 | auto FirstName = FirstMethod->getDeclName(); |
| 10383 | auto SecondName = SecondMethod->getDeclName(); |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10384 | if (FirstMethodType != SecondMethodType || FirstName != SecondName) { |
| Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10385 | ODRDiagError(FirstMethod->getLocation(), |
| 10386 | FirstMethod->getSourceRange(), MethodName) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10387 | << FirstMethodType << FirstName; |
| Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10388 | ODRDiagNote(SecondMethod->getLocation(), |
| 10389 | SecondMethod->getSourceRange(), MethodName) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10390 | << SecondMethodType << SecondName; |
| Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10391 | |
| 10392 | Diagnosed = true; |
| 10393 | break; |
| 10394 | } |
| 10395 | |
| Richard Trieu | 27c1b1a | 2018-07-10 01:40:50 +0000 | [diff] [blame] | 10396 | const bool FirstDeleted = FirstMethod->isDeletedAsWritten(); |
| 10397 | const bool SecondDeleted = SecondMethod->isDeletedAsWritten(); |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10398 | if (FirstDeleted != SecondDeleted) { |
| 10399 | ODRDiagError(FirstMethod->getLocation(), |
| 10400 | FirstMethod->getSourceRange(), MethodDeleted) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10401 | << FirstMethodType << FirstName << FirstDeleted; |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10402 | |
| 10403 | ODRDiagNote(SecondMethod->getLocation(), |
| 10404 | SecondMethod->getSourceRange(), MethodDeleted) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10405 | << SecondMethodType << SecondName << SecondDeleted; |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10406 | Diagnosed = true; |
| 10407 | break; |
| 10408 | } |
| 10409 | |
| Richard Trieu | 27c1b1a | 2018-07-10 01:40:50 +0000 | [diff] [blame] | 10410 | const bool FirstDefaulted = FirstMethod->isExplicitlyDefaulted(); |
| 10411 | const bool SecondDefaulted = SecondMethod->isExplicitlyDefaulted(); |
| 10412 | if (FirstDefaulted != SecondDefaulted) { |
| 10413 | ODRDiagError(FirstMethod->getLocation(), |
| 10414 | FirstMethod->getSourceRange(), MethodDefaulted) |
| 10415 | << FirstMethodType << FirstName << FirstDefaulted; |
| 10416 | |
| 10417 | ODRDiagNote(SecondMethod->getLocation(), |
| 10418 | SecondMethod->getSourceRange(), MethodDefaulted) |
| 10419 | << SecondMethodType << SecondName << SecondDefaulted; |
| 10420 | Diagnosed = true; |
| 10421 | break; |
| 10422 | } |
| 10423 | |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10424 | const bool FirstVirtual = FirstMethod->isVirtualAsWritten(); |
| 10425 | const bool SecondVirtual = SecondMethod->isVirtualAsWritten(); |
| 10426 | const bool FirstPure = FirstMethod->isPure(); |
| 10427 | const bool SecondPure = SecondMethod->isPure(); |
| 10428 | if ((FirstVirtual || SecondVirtual) && |
| 10429 | (FirstVirtual != SecondVirtual || FirstPure != SecondPure)) { |
| 10430 | ODRDiagError(FirstMethod->getLocation(), |
| 10431 | FirstMethod->getSourceRange(), MethodVirtual) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10432 | << FirstMethodType << FirstName << FirstPure << FirstVirtual; |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10433 | ODRDiagNote(SecondMethod->getLocation(), |
| 10434 | SecondMethod->getSourceRange(), MethodVirtual) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10435 | << SecondMethodType << SecondName << SecondPure << SecondVirtual; |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10436 | Diagnosed = true; |
| 10437 | break; |
| 10438 | } |
| 10439 | |
| 10440 | // CXXMethodDecl::isStatic uses the canonical Decl. With Decl merging, |
| 10441 | // FirstDecl is the canonical Decl of SecondDecl, so the storage |
| 10442 | // class needs to be checked instead. |
| 10443 | const auto FirstStorage = FirstMethod->getStorageClass(); |
| 10444 | const auto SecondStorage = SecondMethod->getStorageClass(); |
| 10445 | const bool FirstStatic = FirstStorage == SC_Static; |
| 10446 | const bool SecondStatic = SecondStorage == SC_Static; |
| 10447 | if (FirstStatic != SecondStatic) { |
| 10448 | ODRDiagError(FirstMethod->getLocation(), |
| 10449 | FirstMethod->getSourceRange(), MethodStatic) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10450 | << FirstMethodType << FirstName << FirstStatic; |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10451 | ODRDiagNote(SecondMethod->getLocation(), |
| 10452 | SecondMethod->getSourceRange(), MethodStatic) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10453 | << SecondMethodType << SecondName << SecondStatic; |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10454 | Diagnosed = true; |
| 10455 | break; |
| 10456 | } |
| 10457 | |
| 10458 | const bool FirstVolatile = FirstMethod->isVolatile(); |
| 10459 | const bool SecondVolatile = SecondMethod->isVolatile(); |
| 10460 | if (FirstVolatile != SecondVolatile) { |
| 10461 | ODRDiagError(FirstMethod->getLocation(), |
| 10462 | FirstMethod->getSourceRange(), MethodVolatile) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10463 | << FirstMethodType << FirstName << FirstVolatile; |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10464 | ODRDiagNote(SecondMethod->getLocation(), |
| 10465 | SecondMethod->getSourceRange(), MethodVolatile) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10466 | << SecondMethodType << SecondName << SecondVolatile; |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10467 | Diagnosed = true; |
| 10468 | break; |
| 10469 | } |
| 10470 | |
| 10471 | const bool FirstConst = FirstMethod->isConst(); |
| 10472 | const bool SecondConst = SecondMethod->isConst(); |
| 10473 | if (FirstConst != SecondConst) { |
| 10474 | ODRDiagError(FirstMethod->getLocation(), |
| 10475 | FirstMethod->getSourceRange(), MethodConst) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10476 | << FirstMethodType << FirstName << FirstConst; |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10477 | ODRDiagNote(SecondMethod->getLocation(), |
| 10478 | SecondMethod->getSourceRange(), MethodConst) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10479 | << SecondMethodType << SecondName << SecondConst; |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10480 | Diagnosed = true; |
| 10481 | break; |
| 10482 | } |
| 10483 | |
| 10484 | const bool FirstInline = FirstMethod->isInlineSpecified(); |
| 10485 | const bool SecondInline = SecondMethod->isInlineSpecified(); |
| 10486 | if (FirstInline != SecondInline) { |
| 10487 | ODRDiagError(FirstMethod->getLocation(), |
| 10488 | FirstMethod->getSourceRange(), MethodInline) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10489 | << FirstMethodType << FirstName << FirstInline; |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10490 | ODRDiagNote(SecondMethod->getLocation(), |
| 10491 | SecondMethod->getSourceRange(), MethodInline) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10492 | << SecondMethodType << SecondName << SecondInline; |
| Richard Trieu | 583e2c1 | 2017-03-04 00:08:58 +0000 | [diff] [blame] | 10493 | Diagnosed = true; |
| 10494 | break; |
| 10495 | } |
| 10496 | |
| Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10497 | const unsigned FirstNumParameters = FirstMethod->param_size(); |
| 10498 | const unsigned SecondNumParameters = SecondMethod->param_size(); |
| 10499 | if (FirstNumParameters != SecondNumParameters) { |
| 10500 | ODRDiagError(FirstMethod->getLocation(), |
| 10501 | FirstMethod->getSourceRange(), MethodNumberParameters) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10502 | << FirstMethodType << FirstName << FirstNumParameters; |
| Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10503 | ODRDiagNote(SecondMethod->getLocation(), |
| 10504 | SecondMethod->getSourceRange(), MethodNumberParameters) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10505 | << SecondMethodType << SecondName << SecondNumParameters; |
| Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10506 | Diagnosed = true; |
| 10507 | break; |
| 10508 | } |
| 10509 | |
| 10510 | // Need this status boolean to know when break out of the switch. |
| 10511 | bool ParameterMismatch = false; |
| 10512 | for (unsigned I = 0; I < FirstNumParameters; ++I) { |
| 10513 | const ParmVarDecl *FirstParam = FirstMethod->getParamDecl(I); |
| 10514 | const ParmVarDecl *SecondParam = SecondMethod->getParamDecl(I); |
| 10515 | |
| 10516 | QualType FirstParamType = FirstParam->getType(); |
| 10517 | QualType SecondParamType = SecondParam->getType(); |
| 10518 | if (FirstParamType != SecondParamType && |
| 10519 | ComputeQualTypeODRHash(FirstParamType) != |
| 10520 | ComputeQualTypeODRHash(SecondParamType)) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 10521 | if (const DecayedType *ParamDecayedType = |
| Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10522 | FirstParamType->getAs<DecayedType>()) { |
| 10523 | ODRDiagError(FirstMethod->getLocation(), |
| 10524 | FirstMethod->getSourceRange(), MethodParameterType) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10525 | << FirstMethodType << FirstName << (I + 1) << FirstParamType |
| 10526 | << true << ParamDecayedType->getOriginalType(); |
| Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10527 | } else { |
| 10528 | ODRDiagError(FirstMethod->getLocation(), |
| 10529 | FirstMethod->getSourceRange(), MethodParameterType) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10530 | << FirstMethodType << FirstName << (I + 1) << FirstParamType |
| 10531 | << false; |
| Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10532 | } |
| 10533 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 10534 | if (const DecayedType *ParamDecayedType = |
| Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10535 | SecondParamType->getAs<DecayedType>()) { |
| 10536 | ODRDiagNote(SecondMethod->getLocation(), |
| 10537 | SecondMethod->getSourceRange(), MethodParameterType) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10538 | << SecondMethodType << SecondName << (I + 1) |
| 10539 | << SecondParamType << true |
| Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10540 | << ParamDecayedType->getOriginalType(); |
| 10541 | } else { |
| 10542 | ODRDiagNote(SecondMethod->getLocation(), |
| 10543 | SecondMethod->getSourceRange(), MethodParameterType) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10544 | << SecondMethodType << SecondName << (I + 1) |
| 10545 | << SecondParamType << false; |
| Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10546 | } |
| 10547 | ParameterMismatch = true; |
| 10548 | break; |
| 10549 | } |
| 10550 | |
| 10551 | DeclarationName FirstParamName = FirstParam->getDeclName(); |
| 10552 | DeclarationName SecondParamName = SecondParam->getDeclName(); |
| 10553 | if (FirstParamName != SecondParamName) { |
| 10554 | ODRDiagError(FirstMethod->getLocation(), |
| 10555 | FirstMethod->getSourceRange(), MethodParameterName) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10556 | << FirstMethodType << FirstName << (I + 1) << FirstParamName; |
| Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10557 | ODRDiagNote(SecondMethod->getLocation(), |
| 10558 | SecondMethod->getSourceRange(), MethodParameterName) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10559 | << SecondMethodType << SecondName << (I + 1) << SecondParamName; |
| Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10560 | ParameterMismatch = true; |
| 10561 | break; |
| 10562 | } |
| Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10563 | |
| 10564 | const Expr *FirstInit = FirstParam->getInit(); |
| 10565 | const Expr *SecondInit = SecondParam->getInit(); |
| 10566 | if ((FirstInit == nullptr) != (SecondInit == nullptr)) { |
| 10567 | ODRDiagError(FirstMethod->getLocation(), |
| 10568 | FirstMethod->getSourceRange(), |
| 10569 | MethodParameterSingleDefaultArgument) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10570 | << FirstMethodType << FirstName << (I + 1) |
| 10571 | << (FirstInit == nullptr) |
| Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10572 | << (FirstInit ? FirstInit->getSourceRange() : SourceRange()); |
| 10573 | ODRDiagNote(SecondMethod->getLocation(), |
| 10574 | SecondMethod->getSourceRange(), |
| 10575 | MethodParameterSingleDefaultArgument) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10576 | << SecondMethodType << SecondName << (I + 1) |
| 10577 | << (SecondInit == nullptr) |
| Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10578 | << (SecondInit ? SecondInit->getSourceRange() : SourceRange()); |
| 10579 | ParameterMismatch = true; |
| 10580 | break; |
| 10581 | } |
| 10582 | |
| 10583 | if (FirstInit && SecondInit && |
| 10584 | ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) { |
| 10585 | ODRDiagError(FirstMethod->getLocation(), |
| 10586 | FirstMethod->getSourceRange(), |
| 10587 | MethodParameterDifferentDefaultArgument) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10588 | << FirstMethodType << FirstName << (I + 1) |
| 10589 | << FirstInit->getSourceRange(); |
| Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10590 | ODRDiagNote(SecondMethod->getLocation(), |
| 10591 | SecondMethod->getSourceRange(), |
| 10592 | MethodParameterDifferentDefaultArgument) |
| Richard Trieu | 1c71d51 | 2017-07-15 02:55:13 +0000 | [diff] [blame] | 10593 | << SecondMethodType << SecondName << (I + 1) |
| 10594 | << SecondInit->getSourceRange(); |
| Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10595 | ParameterMismatch = true; |
| 10596 | break; |
| 10597 | |
| 10598 | } |
| Richard Trieu | 0255227 | 2017-05-02 23:58:52 +0000 | [diff] [blame] | 10599 | } |
| 10600 | |
| 10601 | if (ParameterMismatch) { |
| 10602 | Diagnosed = true; |
| 10603 | break; |
| 10604 | } |
| 10605 | |
| Richard Trieu | 7282d32 | 2018-04-25 00:31:15 +0000 | [diff] [blame] | 10606 | const auto *FirstTemplateArgs = |
| 10607 | FirstMethod->getTemplateSpecializationArgs(); |
| 10608 | const auto *SecondTemplateArgs = |
| 10609 | SecondMethod->getTemplateSpecializationArgs(); |
| 10610 | |
| 10611 | if ((FirstTemplateArgs && !SecondTemplateArgs) || |
| 10612 | (!FirstTemplateArgs && SecondTemplateArgs)) { |
| 10613 | ODRDiagError(FirstMethod->getLocation(), |
| 10614 | FirstMethod->getSourceRange(), MethodNoTemplateArguments) |
| 10615 | << FirstMethodType << FirstName << (FirstTemplateArgs != nullptr); |
| 10616 | ODRDiagNote(SecondMethod->getLocation(), |
| 10617 | SecondMethod->getSourceRange(), MethodNoTemplateArguments) |
| 10618 | << SecondMethodType << SecondName |
| 10619 | << (SecondTemplateArgs != nullptr); |
| 10620 | |
| 10621 | Diagnosed = true; |
| 10622 | break; |
| 10623 | } |
| 10624 | |
| 10625 | if (FirstTemplateArgs && SecondTemplateArgs) { |
| 10626 | // Remove pack expansions from argument list. |
| 10627 | auto ExpandTemplateArgumentList = |
| 10628 | [](const TemplateArgumentList *TAL) { |
| 10629 | llvm::SmallVector<const TemplateArgument *, 8> ExpandedList; |
| 10630 | for (const TemplateArgument &TA : TAL->asArray()) { |
| 10631 | if (TA.getKind() != TemplateArgument::Pack) { |
| 10632 | ExpandedList.push_back(&TA); |
| 10633 | continue; |
| 10634 | } |
| 10635 | for (const TemplateArgument &PackTA : TA.getPackAsArray()) { |
| 10636 | ExpandedList.push_back(&PackTA); |
| 10637 | } |
| 10638 | } |
| 10639 | return ExpandedList; |
| 10640 | }; |
| 10641 | llvm::SmallVector<const TemplateArgument *, 8> FirstExpandedList = |
| 10642 | ExpandTemplateArgumentList(FirstTemplateArgs); |
| 10643 | llvm::SmallVector<const TemplateArgument *, 8> SecondExpandedList = |
| 10644 | ExpandTemplateArgumentList(SecondTemplateArgs); |
| 10645 | |
| 10646 | if (FirstExpandedList.size() != SecondExpandedList.size()) { |
| 10647 | ODRDiagError(FirstMethod->getLocation(), |
| 10648 | FirstMethod->getSourceRange(), |
| 10649 | MethodDifferentNumberTemplateArguments) |
| 10650 | << FirstMethodType << FirstName |
| 10651 | << (unsigned)FirstExpandedList.size(); |
| 10652 | ODRDiagNote(SecondMethod->getLocation(), |
| 10653 | SecondMethod->getSourceRange(), |
| 10654 | MethodDifferentNumberTemplateArguments) |
| 10655 | << SecondMethodType << SecondName |
| 10656 | << (unsigned)SecondExpandedList.size(); |
| 10657 | |
| 10658 | Diagnosed = true; |
| 10659 | break; |
| 10660 | } |
| 10661 | |
| 10662 | bool TemplateArgumentMismatch = false; |
| 10663 | for (unsigned i = 0, e = FirstExpandedList.size(); i != e; ++i) { |
| 10664 | const TemplateArgument &FirstTA = *FirstExpandedList[i], |
| 10665 | &SecondTA = *SecondExpandedList[i]; |
| 10666 | if (ComputeTemplateArgumentODRHash(FirstTA) == |
| 10667 | ComputeTemplateArgumentODRHash(SecondTA)) { |
| 10668 | continue; |
| 10669 | } |
| 10670 | |
| 10671 | ODRDiagError(FirstMethod->getLocation(), |
| 10672 | FirstMethod->getSourceRange(), |
| 10673 | MethodDifferentTemplateArgument) |
| 10674 | << FirstMethodType << FirstName << FirstTA << i + 1; |
| 10675 | ODRDiagNote(SecondMethod->getLocation(), |
| 10676 | SecondMethod->getSourceRange(), |
| 10677 | MethodDifferentTemplateArgument) |
| 10678 | << SecondMethodType << SecondName << SecondTA << i + 1; |
| 10679 | |
| 10680 | TemplateArgumentMismatch = true; |
| 10681 | break; |
| 10682 | } |
| 10683 | |
| 10684 | if (TemplateArgumentMismatch) { |
| 10685 | Diagnosed = true; |
| 10686 | break; |
| 10687 | } |
| 10688 | } |
| Richard Trieu | 27c1b1a | 2018-07-10 01:40:50 +0000 | [diff] [blame] | 10689 | |
| 10690 | // Compute the hash of the method as if it has no body. |
| 10691 | auto ComputeCXXMethodODRHash = [&Hash](const CXXMethodDecl *D) { |
| 10692 | Hash.clear(); |
| 10693 | Hash.AddFunctionDecl(D, true /*SkipBody*/); |
| 10694 | return Hash.CalculateHash(); |
| 10695 | }; |
| 10696 | |
| 10697 | // Compare the hash generated to the hash stored. A difference means |
| 10698 | // that a body was present in the original source. Due to merging, |
| 10699 | // the stardard way of detecting a body will not work. |
| 10700 | const bool HasFirstBody = |
| 10701 | ComputeCXXMethodODRHash(FirstMethod) != FirstMethod->getODRHash(); |
| 10702 | const bool HasSecondBody = |
| 10703 | ComputeCXXMethodODRHash(SecondMethod) != SecondMethod->getODRHash(); |
| 10704 | |
| 10705 | if (HasFirstBody != HasSecondBody) { |
| 10706 | ODRDiagError(FirstMethod->getLocation(), |
| 10707 | FirstMethod->getSourceRange(), MethodSingleBody) |
| 10708 | << FirstMethodType << FirstName << HasFirstBody; |
| 10709 | ODRDiagNote(SecondMethod->getLocation(), |
| 10710 | SecondMethod->getSourceRange(), MethodSingleBody) |
| 10711 | << SecondMethodType << SecondName << HasSecondBody; |
| 10712 | Diagnosed = true; |
| 10713 | break; |
| 10714 | } |
| 10715 | |
| 10716 | if (HasFirstBody && HasSecondBody) { |
| 10717 | ODRDiagError(FirstMethod->getLocation(), |
| 10718 | FirstMethod->getSourceRange(), MethodDifferentBody) |
| 10719 | << FirstMethodType << FirstName; |
| 10720 | ODRDiagNote(SecondMethod->getLocation(), |
| 10721 | SecondMethod->getSourceRange(), MethodDifferentBody) |
| 10722 | << SecondMethodType << SecondName; |
| 10723 | Diagnosed = true; |
| 10724 | break; |
| 10725 | } |
| 10726 | |
| Richard Trieu | 4814374 | 2017-02-28 21:24:38 +0000 | [diff] [blame] | 10727 | break; |
| 10728 | } |
| Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 10729 | case TypeAlias: |
| 10730 | case TypeDef: { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 10731 | TypedefNameDecl *FirstTD = cast<TypedefNameDecl>(FirstDecl); |
| 10732 | TypedefNameDecl *SecondTD = cast<TypedefNameDecl>(SecondDecl); |
| Richard Trieu | 11d566a | 2017-06-12 21:58:22 +0000 | [diff] [blame] | 10733 | auto FirstName = FirstTD->getDeclName(); |
| 10734 | auto SecondName = SecondTD->getDeclName(); |
| 10735 | if (FirstName != SecondName) { |
| 10736 | ODRDiagError(FirstTD->getLocation(), FirstTD->getSourceRange(), |
| 10737 | TypedefName) |
| 10738 | << (FirstDiffType == TypeAlias) << FirstName; |
| 10739 | ODRDiagNote(SecondTD->getLocation(), SecondTD->getSourceRange(), |
| 10740 | TypedefName) |
| 10741 | << (FirstDiffType == TypeAlias) << SecondName; |
| 10742 | Diagnosed = true; |
| 10743 | break; |
| 10744 | } |
| 10745 | |
| 10746 | QualType FirstType = FirstTD->getUnderlyingType(); |
| 10747 | QualType SecondType = SecondTD->getUnderlyingType(); |
| 10748 | if (ComputeQualTypeODRHash(FirstType) != |
| 10749 | ComputeQualTypeODRHash(SecondType)) { |
| 10750 | ODRDiagError(FirstTD->getLocation(), FirstTD->getSourceRange(), |
| 10751 | TypedefType) |
| 10752 | << (FirstDiffType == TypeAlias) << FirstName << FirstType; |
| 10753 | ODRDiagNote(SecondTD->getLocation(), SecondTD->getSourceRange(), |
| 10754 | TypedefType) |
| 10755 | << (FirstDiffType == TypeAlias) << SecondName << SecondType; |
| 10756 | Diagnosed = true; |
| 10757 | break; |
| 10758 | } |
| 10759 | break; |
| 10760 | } |
| Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10761 | case Var: { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 10762 | VarDecl *FirstVD = cast<VarDecl>(FirstDecl); |
| 10763 | VarDecl *SecondVD = cast<VarDecl>(SecondDecl); |
| Richard Trieu | 6e13ff3 | 2017-06-16 02:44:29 +0000 | [diff] [blame] | 10764 | auto FirstName = FirstVD->getDeclName(); |
| 10765 | auto SecondName = SecondVD->getDeclName(); |
| 10766 | if (FirstName != SecondName) { |
| 10767 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 10768 | VarName) |
| 10769 | << FirstName; |
| 10770 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 10771 | VarName) |
| 10772 | << SecondName; |
| 10773 | Diagnosed = true; |
| 10774 | break; |
| 10775 | } |
| 10776 | |
| 10777 | QualType FirstType = FirstVD->getType(); |
| 10778 | QualType SecondType = SecondVD->getType(); |
| 10779 | if (ComputeQualTypeODRHash(FirstType) != |
| 10780 | ComputeQualTypeODRHash(SecondType)) { |
| 10781 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 10782 | VarType) |
| 10783 | << FirstName << FirstType; |
| 10784 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 10785 | VarType) |
| 10786 | << SecondName << SecondType; |
| 10787 | Diagnosed = true; |
| 10788 | break; |
| 10789 | } |
| 10790 | |
| 10791 | const Expr *FirstInit = FirstVD->getInit(); |
| 10792 | const Expr *SecondInit = SecondVD->getInit(); |
| 10793 | if ((FirstInit == nullptr) != (SecondInit == nullptr)) { |
| 10794 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 10795 | VarSingleInitializer) |
| 10796 | << FirstName << (FirstInit == nullptr) |
| 10797 | << (FirstInit ? FirstInit->getSourceRange(): SourceRange()); |
| 10798 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 10799 | VarSingleInitializer) |
| 10800 | << SecondName << (SecondInit == nullptr) |
| 10801 | << (SecondInit ? SecondInit->getSourceRange() : SourceRange()); |
| 10802 | Diagnosed = true; |
| 10803 | break; |
| 10804 | } |
| 10805 | |
| 10806 | if (FirstInit && SecondInit && |
| 10807 | ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) { |
| 10808 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 10809 | VarDifferentInitializer) |
| 10810 | << FirstName << FirstInit->getSourceRange(); |
| 10811 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 10812 | VarDifferentInitializer) |
| 10813 | << SecondName << SecondInit->getSourceRange(); |
| 10814 | Diagnosed = true; |
| 10815 | break; |
| 10816 | } |
| 10817 | |
| 10818 | const bool FirstIsConstexpr = FirstVD->isConstexpr(); |
| 10819 | const bool SecondIsConstexpr = SecondVD->isConstexpr(); |
| 10820 | if (FirstIsConstexpr != SecondIsConstexpr) { |
| 10821 | ODRDiagError(FirstVD->getLocation(), FirstVD->getSourceRange(), |
| 10822 | VarConstexpr) |
| 10823 | << FirstName << FirstIsConstexpr; |
| 10824 | ODRDiagNote(SecondVD->getLocation(), SecondVD->getSourceRange(), |
| 10825 | VarConstexpr) |
| 10826 | << SecondName << SecondIsConstexpr; |
| 10827 | Diagnosed = true; |
| 10828 | break; |
| 10829 | } |
| 10830 | break; |
| 10831 | } |
| Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 10832 | case Friend: { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 10833 | FriendDecl *FirstFriend = cast<FriendDecl>(FirstDecl); |
| 10834 | FriendDecl *SecondFriend = cast<FriendDecl>(SecondDecl); |
| Richard Trieu | ac6a1b6 | 2017-07-08 02:04:42 +0000 | [diff] [blame] | 10835 | |
| 10836 | NamedDecl *FirstND = FirstFriend->getFriendDecl(); |
| 10837 | NamedDecl *SecondND = SecondFriend->getFriendDecl(); |
| 10838 | |
| 10839 | TypeSourceInfo *FirstTSI = FirstFriend->getFriendType(); |
| 10840 | TypeSourceInfo *SecondTSI = SecondFriend->getFriendType(); |
| 10841 | |
| 10842 | if (FirstND && SecondND) { |
| 10843 | ODRDiagError(FirstFriend->getFriendLoc(), |
| 10844 | FirstFriend->getSourceRange(), FriendFunction) |
| 10845 | << FirstND; |
| 10846 | ODRDiagNote(SecondFriend->getFriendLoc(), |
| 10847 | SecondFriend->getSourceRange(), FriendFunction) |
| 10848 | << SecondND; |
| 10849 | |
| 10850 | Diagnosed = true; |
| 10851 | break; |
| 10852 | } |
| 10853 | |
| 10854 | if (FirstTSI && SecondTSI) { |
| 10855 | QualType FirstFriendType = FirstTSI->getType(); |
| 10856 | QualType SecondFriendType = SecondTSI->getType(); |
| 10857 | assert(ComputeQualTypeODRHash(FirstFriendType) != |
| 10858 | ComputeQualTypeODRHash(SecondFriendType)); |
| 10859 | ODRDiagError(FirstFriend->getFriendLoc(), |
| 10860 | FirstFriend->getSourceRange(), FriendType) |
| 10861 | << FirstFriendType; |
| 10862 | ODRDiagNote(SecondFriend->getFriendLoc(), |
| 10863 | SecondFriend->getSourceRange(), FriendType) |
| 10864 | << SecondFriendType; |
| 10865 | Diagnosed = true; |
| 10866 | break; |
| 10867 | } |
| 10868 | |
| 10869 | ODRDiagError(FirstFriend->getFriendLoc(), FirstFriend->getSourceRange(), |
| 10870 | FriendTypeFunction) |
| 10871 | << (FirstTSI == nullptr); |
| 10872 | ODRDiagNote(SecondFriend->getFriendLoc(), |
| 10873 | SecondFriend->getSourceRange(), FriendTypeFunction) |
| 10874 | << (SecondTSI == nullptr); |
| 10875 | |
| 10876 | Diagnosed = true; |
| 10877 | break; |
| 10878 | } |
| Richard Trieu | 9359e8f | 2018-05-30 01:12:26 +0000 | [diff] [blame] | 10879 | case FunctionTemplate: { |
| 10880 | FunctionTemplateDecl *FirstTemplate = |
| 10881 | cast<FunctionTemplateDecl>(FirstDecl); |
| 10882 | FunctionTemplateDecl *SecondTemplate = |
| 10883 | cast<FunctionTemplateDecl>(SecondDecl); |
| 10884 | |
| 10885 | TemplateParameterList *FirstTPL = |
| 10886 | FirstTemplate->getTemplateParameters(); |
| 10887 | TemplateParameterList *SecondTPL = |
| 10888 | SecondTemplate->getTemplateParameters(); |
| 10889 | |
| 10890 | if (FirstTPL->size() != SecondTPL->size()) { |
| 10891 | ODRDiagError(FirstTemplate->getLocation(), |
| 10892 | FirstTemplate->getSourceRange(), |
| 10893 | FunctionTemplateDifferentNumberParameters) |
| 10894 | << FirstTemplate << FirstTPL->size(); |
| 10895 | ODRDiagNote(SecondTemplate->getLocation(), |
| 10896 | SecondTemplate->getSourceRange(), |
| 10897 | FunctionTemplateDifferentNumberParameters) |
| 10898 | << SecondTemplate << SecondTPL->size(); |
| 10899 | |
| 10900 | Diagnosed = true; |
| 10901 | break; |
| 10902 | } |
| 10903 | |
| 10904 | bool ParameterMismatch = false; |
| 10905 | for (unsigned i = 0, e = FirstTPL->size(); i != e; ++i) { |
| 10906 | NamedDecl *FirstParam = FirstTPL->getParam(i); |
| 10907 | NamedDecl *SecondParam = SecondTPL->getParam(i); |
| 10908 | |
| 10909 | if (FirstParam->getKind() != SecondParam->getKind()) { |
| 10910 | enum { |
| 10911 | TemplateTypeParameter, |
| 10912 | NonTypeTemplateParameter, |
| 10913 | TemplateTemplateParameter, |
| 10914 | }; |
| 10915 | auto GetParamType = [](NamedDecl *D) { |
| 10916 | switch (D->getKind()) { |
| 10917 | default: |
| 10918 | llvm_unreachable("Unexpected template parameter type"); |
| 10919 | case Decl::TemplateTypeParm: |
| 10920 | return TemplateTypeParameter; |
| 10921 | case Decl::NonTypeTemplateParm: |
| 10922 | return NonTypeTemplateParameter; |
| 10923 | case Decl::TemplateTemplateParm: |
| 10924 | return TemplateTemplateParameter; |
| 10925 | } |
| 10926 | }; |
| 10927 | |
| 10928 | ODRDiagError(FirstTemplate->getLocation(), |
| 10929 | FirstTemplate->getSourceRange(), |
| 10930 | FunctionTemplateParameterDifferentKind) |
| 10931 | << FirstTemplate << (i + 1) << GetParamType(FirstParam); |
| 10932 | ODRDiagNote(SecondTemplate->getLocation(), |
| 10933 | SecondTemplate->getSourceRange(), |
| 10934 | FunctionTemplateParameterDifferentKind) |
| 10935 | << SecondTemplate << (i + 1) << GetParamType(SecondParam); |
| 10936 | |
| 10937 | ParameterMismatch = true; |
| 10938 | break; |
| 10939 | } |
| 10940 | |
| 10941 | if (FirstParam->getName() != SecondParam->getName()) { |
| 10942 | ODRDiagError(FirstTemplate->getLocation(), |
| 10943 | FirstTemplate->getSourceRange(), |
| 10944 | FunctionTemplateParameterName) |
| 10945 | << FirstTemplate << (i + 1) << (bool)FirstParam->getIdentifier() |
| 10946 | << FirstParam; |
| 10947 | ODRDiagNote(SecondTemplate->getLocation(), |
| 10948 | SecondTemplate->getSourceRange(), |
| 10949 | FunctionTemplateParameterName) |
| 10950 | << SecondTemplate << (i + 1) |
| 10951 | << (bool)SecondParam->getIdentifier() << SecondParam; |
| 10952 | ParameterMismatch = true; |
| 10953 | break; |
| 10954 | } |
| 10955 | |
| 10956 | if (isa<TemplateTypeParmDecl>(FirstParam) && |
| 10957 | isa<TemplateTypeParmDecl>(SecondParam)) { |
| 10958 | TemplateTypeParmDecl *FirstTTPD = |
| 10959 | cast<TemplateTypeParmDecl>(FirstParam); |
| 10960 | TemplateTypeParmDecl *SecondTTPD = |
| 10961 | cast<TemplateTypeParmDecl>(SecondParam); |
| 10962 | bool HasFirstDefaultArgument = |
| 10963 | FirstTTPD->hasDefaultArgument() && |
| 10964 | !FirstTTPD->defaultArgumentWasInherited(); |
| 10965 | bool HasSecondDefaultArgument = |
| 10966 | SecondTTPD->hasDefaultArgument() && |
| 10967 | !SecondTTPD->defaultArgumentWasInherited(); |
| 10968 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 10969 | ODRDiagError(FirstTemplate->getLocation(), |
| 10970 | FirstTemplate->getSourceRange(), |
| 10971 | FunctionTemplateParameterSingleDefaultArgument) |
| 10972 | << FirstTemplate << (i + 1) << HasFirstDefaultArgument; |
| 10973 | ODRDiagNote(SecondTemplate->getLocation(), |
| 10974 | SecondTemplate->getSourceRange(), |
| 10975 | FunctionTemplateParameterSingleDefaultArgument) |
| 10976 | << SecondTemplate << (i + 1) << HasSecondDefaultArgument; |
| 10977 | ParameterMismatch = true; |
| 10978 | break; |
| 10979 | } |
| 10980 | |
| 10981 | if (HasFirstDefaultArgument && HasSecondDefaultArgument) { |
| 10982 | QualType FirstType = FirstTTPD->getDefaultArgument(); |
| 10983 | QualType SecondType = SecondTTPD->getDefaultArgument(); |
| 10984 | if (ComputeQualTypeODRHash(FirstType) != |
| 10985 | ComputeQualTypeODRHash(SecondType)) { |
| 10986 | ODRDiagError(FirstTemplate->getLocation(), |
| 10987 | FirstTemplate->getSourceRange(), |
| 10988 | FunctionTemplateParameterDifferentDefaultArgument) |
| 10989 | << FirstTemplate << (i + 1) << FirstType; |
| 10990 | ODRDiagNote(SecondTemplate->getLocation(), |
| 10991 | SecondTemplate->getSourceRange(), |
| 10992 | FunctionTemplateParameterDifferentDefaultArgument) |
| 10993 | << SecondTemplate << (i + 1) << SecondType; |
| 10994 | ParameterMismatch = true; |
| 10995 | break; |
| 10996 | } |
| 10997 | } |
| 10998 | |
| 10999 | if (FirstTTPD->isParameterPack() != |
| 11000 | SecondTTPD->isParameterPack()) { |
| 11001 | ODRDiagError(FirstTemplate->getLocation(), |
| 11002 | FirstTemplate->getSourceRange(), |
| 11003 | FunctionTemplatePackParameter) |
| 11004 | << FirstTemplate << (i + 1) << FirstTTPD->isParameterPack(); |
| 11005 | ODRDiagNote(SecondTemplate->getLocation(), |
| 11006 | SecondTemplate->getSourceRange(), |
| 11007 | FunctionTemplatePackParameter) |
| 11008 | << SecondTemplate << (i + 1) << SecondTTPD->isParameterPack(); |
| 11009 | ParameterMismatch = true; |
| 11010 | break; |
| 11011 | } |
| 11012 | } |
| 11013 | |
| 11014 | if (isa<TemplateTemplateParmDecl>(FirstParam) && |
| 11015 | isa<TemplateTemplateParmDecl>(SecondParam)) { |
| 11016 | TemplateTemplateParmDecl *FirstTTPD = |
| 11017 | cast<TemplateTemplateParmDecl>(FirstParam); |
| 11018 | TemplateTemplateParmDecl *SecondTTPD = |
| 11019 | cast<TemplateTemplateParmDecl>(SecondParam); |
| 11020 | |
| 11021 | TemplateParameterList *FirstTPL = |
| 11022 | FirstTTPD->getTemplateParameters(); |
| 11023 | TemplateParameterList *SecondTPL = |
| 11024 | SecondTTPD->getTemplateParameters(); |
| 11025 | |
| 11026 | if (ComputeTemplateParameterListODRHash(FirstTPL) != |
| 11027 | ComputeTemplateParameterListODRHash(SecondTPL)) { |
| 11028 | ODRDiagError(FirstTemplate->getLocation(), |
| 11029 | FirstTemplate->getSourceRange(), |
| 11030 | FunctionTemplateParameterDifferentType) |
| 11031 | << FirstTemplate << (i + 1); |
| 11032 | ODRDiagNote(SecondTemplate->getLocation(), |
| 11033 | SecondTemplate->getSourceRange(), |
| 11034 | FunctionTemplateParameterDifferentType) |
| 11035 | << SecondTemplate << (i + 1); |
| 11036 | ParameterMismatch = true; |
| 11037 | break; |
| 11038 | } |
| 11039 | |
| 11040 | bool HasFirstDefaultArgument = |
| 11041 | FirstTTPD->hasDefaultArgument() && |
| 11042 | !FirstTTPD->defaultArgumentWasInherited(); |
| 11043 | bool HasSecondDefaultArgument = |
| 11044 | SecondTTPD->hasDefaultArgument() && |
| 11045 | !SecondTTPD->defaultArgumentWasInherited(); |
| 11046 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 11047 | ODRDiagError(FirstTemplate->getLocation(), |
| 11048 | FirstTemplate->getSourceRange(), |
| 11049 | FunctionTemplateParameterSingleDefaultArgument) |
| 11050 | << FirstTemplate << (i + 1) << HasFirstDefaultArgument; |
| 11051 | ODRDiagNote(SecondTemplate->getLocation(), |
| 11052 | SecondTemplate->getSourceRange(), |
| 11053 | FunctionTemplateParameterSingleDefaultArgument) |
| 11054 | << SecondTemplate << (i + 1) << HasSecondDefaultArgument; |
| 11055 | ParameterMismatch = true; |
| 11056 | break; |
| 11057 | } |
| 11058 | |
| 11059 | if (HasFirstDefaultArgument && HasSecondDefaultArgument) { |
| 11060 | TemplateArgument FirstTA = |
| 11061 | FirstTTPD->getDefaultArgument().getArgument(); |
| 11062 | TemplateArgument SecondTA = |
| 11063 | SecondTTPD->getDefaultArgument().getArgument(); |
| 11064 | if (ComputeTemplateArgumentODRHash(FirstTA) != |
| 11065 | ComputeTemplateArgumentODRHash(SecondTA)) { |
| 11066 | ODRDiagError(FirstTemplate->getLocation(), |
| 11067 | FirstTemplate->getSourceRange(), |
| 11068 | FunctionTemplateParameterDifferentDefaultArgument) |
| 11069 | << FirstTemplate << (i + 1) << FirstTA; |
| 11070 | ODRDiagNote(SecondTemplate->getLocation(), |
| 11071 | SecondTemplate->getSourceRange(), |
| 11072 | FunctionTemplateParameterDifferentDefaultArgument) |
| 11073 | << SecondTemplate << (i + 1) << SecondTA; |
| 11074 | ParameterMismatch = true; |
| 11075 | break; |
| 11076 | } |
| 11077 | } |
| 11078 | |
| 11079 | if (FirstTTPD->isParameterPack() != |
| 11080 | SecondTTPD->isParameterPack()) { |
| 11081 | ODRDiagError(FirstTemplate->getLocation(), |
| 11082 | FirstTemplate->getSourceRange(), |
| 11083 | FunctionTemplatePackParameter) |
| 11084 | << FirstTemplate << (i + 1) << FirstTTPD->isParameterPack(); |
| 11085 | ODRDiagNote(SecondTemplate->getLocation(), |
| 11086 | SecondTemplate->getSourceRange(), |
| 11087 | FunctionTemplatePackParameter) |
| 11088 | << SecondTemplate << (i + 1) << SecondTTPD->isParameterPack(); |
| 11089 | ParameterMismatch = true; |
| 11090 | break; |
| 11091 | } |
| 11092 | } |
| 11093 | |
| 11094 | if (isa<NonTypeTemplateParmDecl>(FirstParam) && |
| 11095 | isa<NonTypeTemplateParmDecl>(SecondParam)) { |
| 11096 | NonTypeTemplateParmDecl *FirstNTTPD = |
| 11097 | cast<NonTypeTemplateParmDecl>(FirstParam); |
| 11098 | NonTypeTemplateParmDecl *SecondNTTPD = |
| 11099 | cast<NonTypeTemplateParmDecl>(SecondParam); |
| 11100 | |
| 11101 | QualType FirstType = FirstNTTPD->getType(); |
| 11102 | QualType SecondType = SecondNTTPD->getType(); |
| 11103 | if (ComputeQualTypeODRHash(FirstType) != |
| 11104 | ComputeQualTypeODRHash(SecondType)) { |
| 11105 | ODRDiagError(FirstTemplate->getLocation(), |
| 11106 | FirstTemplate->getSourceRange(), |
| 11107 | FunctionTemplateParameterDifferentType) |
| 11108 | << FirstTemplate << (i + 1); |
| 11109 | ODRDiagNote(SecondTemplate->getLocation(), |
| 11110 | SecondTemplate->getSourceRange(), |
| 11111 | FunctionTemplateParameterDifferentType) |
| 11112 | << SecondTemplate << (i + 1); |
| 11113 | ParameterMismatch = true; |
| 11114 | break; |
| 11115 | } |
| 11116 | |
| 11117 | bool HasFirstDefaultArgument = |
| 11118 | FirstNTTPD->hasDefaultArgument() && |
| 11119 | !FirstNTTPD->defaultArgumentWasInherited(); |
| 11120 | bool HasSecondDefaultArgument = |
| 11121 | SecondNTTPD->hasDefaultArgument() && |
| 11122 | !SecondNTTPD->defaultArgumentWasInherited(); |
| 11123 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 11124 | ODRDiagError(FirstTemplate->getLocation(), |
| 11125 | FirstTemplate->getSourceRange(), |
| 11126 | FunctionTemplateParameterSingleDefaultArgument) |
| 11127 | << FirstTemplate << (i + 1) << HasFirstDefaultArgument; |
| 11128 | ODRDiagNote(SecondTemplate->getLocation(), |
| 11129 | SecondTemplate->getSourceRange(), |
| 11130 | FunctionTemplateParameterSingleDefaultArgument) |
| 11131 | << SecondTemplate << (i + 1) << HasSecondDefaultArgument; |
| 11132 | ParameterMismatch = true; |
| 11133 | break; |
| 11134 | } |
| 11135 | |
| 11136 | if (HasFirstDefaultArgument && HasSecondDefaultArgument) { |
| 11137 | Expr *FirstDefaultArgument = FirstNTTPD->getDefaultArgument(); |
| 11138 | Expr *SecondDefaultArgument = SecondNTTPD->getDefaultArgument(); |
| 11139 | if (ComputeODRHash(FirstDefaultArgument) != |
| 11140 | ComputeODRHash(SecondDefaultArgument)) { |
| 11141 | ODRDiagError(FirstTemplate->getLocation(), |
| 11142 | FirstTemplate->getSourceRange(), |
| 11143 | FunctionTemplateParameterDifferentDefaultArgument) |
| 11144 | << FirstTemplate << (i + 1) << FirstDefaultArgument; |
| 11145 | ODRDiagNote(SecondTemplate->getLocation(), |
| 11146 | SecondTemplate->getSourceRange(), |
| 11147 | FunctionTemplateParameterDifferentDefaultArgument) |
| 11148 | << SecondTemplate << (i + 1) << SecondDefaultArgument; |
| 11149 | ParameterMismatch = true; |
| 11150 | break; |
| 11151 | } |
| 11152 | } |
| 11153 | |
| 11154 | if (FirstNTTPD->isParameterPack() != |
| 11155 | SecondNTTPD->isParameterPack()) { |
| 11156 | ODRDiagError(FirstTemplate->getLocation(), |
| 11157 | FirstTemplate->getSourceRange(), |
| 11158 | FunctionTemplatePackParameter) |
| 11159 | << FirstTemplate << (i + 1) << FirstNTTPD->isParameterPack(); |
| 11160 | ODRDiagNote(SecondTemplate->getLocation(), |
| 11161 | SecondTemplate->getSourceRange(), |
| 11162 | FunctionTemplatePackParameter) |
| 11163 | << SecondTemplate << (i + 1) |
| 11164 | << SecondNTTPD->isParameterPack(); |
| 11165 | ParameterMismatch = true; |
| 11166 | break; |
| 11167 | } |
| 11168 | } |
| 11169 | } |
| 11170 | |
| 11171 | if (ParameterMismatch) { |
| 11172 | Diagnosed = true; |
| 11173 | break; |
| 11174 | } |
| 11175 | |
| 11176 | break; |
| 11177 | } |
| Richard Trieu | 639d7b6 | 2017-02-22 22:22:42 +0000 | [diff] [blame] | 11178 | } |
| 11179 | |
| Eugene Zelenko | b8c9e2a | 2017-11-08 01:03:16 +0000 | [diff] [blame] | 11180 | if (Diagnosed) |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 11181 | continue; |
| 11182 | |
| Richard Trieu | 708859a | 2017-06-08 00:56:21 +0000 | [diff] [blame] | 11183 | Diag(FirstDecl->getLocation(), |
| 11184 | diag::err_module_odr_violation_mismatch_decl_unknown) |
| 11185 | << FirstRecord << FirstModule.empty() << FirstModule << FirstDiffType |
| 11186 | << FirstDecl->getSourceRange(); |
| 11187 | Diag(SecondDecl->getLocation(), |
| 11188 | diag::note_module_odr_violation_mismatch_decl_unknown) |
| 11189 | << SecondModule << FirstDiffType << SecondDecl->getSourceRange(); |
| Richard Trieu | e7f7ed2 | 2017-02-22 01:11:25 +0000 | [diff] [blame] | 11190 | Diagnosed = true; |
| Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 11191 | } |
| 11192 | |
| 11193 | if (!Diagnosed) { |
| 11194 | // All definitions are updates to the same declaration. This happens if a |
| 11195 | // module instantiates the declaration of a class template specialization |
| 11196 | // and two or more other modules instantiate its definition. |
| 11197 | // |
| 11198 | // FIXME: Indicate which modules had instantiations of this definition. |
| 11199 | // FIXME: How can this even happen? |
| 11200 | Diag(Merge.first->getLocation(), |
| 11201 | diag::err_module_odr_violation_different_instantiations) |
| 11202 | << Merge.first; |
| 11203 | } |
| 11204 | } |
| Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 11205 | |
| 11206 | // Issue ODR failures diagnostics for functions. |
| 11207 | for (auto &Merge : FunctionOdrMergeFailures) { |
| 11208 | enum ODRFunctionDifference { |
| 11209 | ReturnType, |
| 11210 | ParameterName, |
| 11211 | ParameterType, |
| 11212 | ParameterSingleDefaultArgument, |
| 11213 | ParameterDifferentDefaultArgument, |
| 11214 | FunctionBody, |
| 11215 | }; |
| 11216 | |
| 11217 | FunctionDecl *FirstFunction = Merge.first; |
| 11218 | std::string FirstModule = getOwningModuleNameForDiagnostic(FirstFunction); |
| 11219 | |
| 11220 | bool Diagnosed = false; |
| 11221 | for (auto &SecondFunction : Merge.second) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 11222 | |
| Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 11223 | if (FirstFunction == SecondFunction) |
| 11224 | continue; |
| 11225 | |
| 11226 | std::string SecondModule = |
| 11227 | getOwningModuleNameForDiagnostic(SecondFunction); |
| 11228 | |
| 11229 | auto ODRDiagError = [FirstFunction, &FirstModule, |
| 11230 | this](SourceLocation Loc, SourceRange Range, |
| 11231 | ODRFunctionDifference DiffType) { |
| 11232 | return Diag(Loc, diag::err_module_odr_violation_function) |
| 11233 | << FirstFunction << FirstModule.empty() << FirstModule << Range |
| 11234 | << DiffType; |
| 11235 | }; |
| 11236 | auto ODRDiagNote = [&SecondModule, this](SourceLocation Loc, |
| 11237 | SourceRange Range, |
| 11238 | ODRFunctionDifference DiffType) { |
| 11239 | return Diag(Loc, diag::note_module_odr_violation_function) |
| 11240 | << SecondModule << Range << DiffType; |
| 11241 | }; |
| 11242 | |
| 11243 | if (ComputeQualTypeODRHash(FirstFunction->getReturnType()) != |
| 11244 | ComputeQualTypeODRHash(SecondFunction->getReturnType())) { |
| 11245 | ODRDiagError(FirstFunction->getReturnTypeSourceRange().getBegin(), |
| 11246 | FirstFunction->getReturnTypeSourceRange(), ReturnType) |
| 11247 | << FirstFunction->getReturnType(); |
| 11248 | ODRDiagNote(SecondFunction->getReturnTypeSourceRange().getBegin(), |
| 11249 | SecondFunction->getReturnTypeSourceRange(), ReturnType) |
| 11250 | << SecondFunction->getReturnType(); |
| 11251 | Diagnosed = true; |
| 11252 | break; |
| 11253 | } |
| 11254 | |
| 11255 | assert(FirstFunction->param_size() == SecondFunction->param_size() && |
| 11256 | "Merged functions with different number of parameters"); |
| 11257 | |
| 11258 | auto ParamSize = FirstFunction->param_size(); |
| 11259 | bool ParameterMismatch = false; |
| 11260 | for (unsigned I = 0; I < ParamSize; ++I) { |
| 11261 | auto *FirstParam = FirstFunction->getParamDecl(I); |
| 11262 | auto *SecondParam = SecondFunction->getParamDecl(I); |
| 11263 | |
| 11264 | assert(getContext().hasSameType(FirstParam->getType(), |
| 11265 | SecondParam->getType()) && |
| 11266 | "Merged function has different parameter types."); |
| 11267 | |
| 11268 | if (FirstParam->getDeclName() != SecondParam->getDeclName()) { |
| 11269 | ODRDiagError(FirstParam->getLocation(), FirstParam->getSourceRange(), |
| 11270 | ParameterName) |
| 11271 | << I + 1 << FirstParam->getDeclName(); |
| 11272 | ODRDiagNote(SecondParam->getLocation(), SecondParam->getSourceRange(), |
| 11273 | ParameterName) |
| 11274 | << I + 1 << SecondParam->getDeclName(); |
| 11275 | ParameterMismatch = true; |
| 11276 | break; |
| 11277 | }; |
| 11278 | |
| 11279 | QualType FirstParamType = FirstParam->getType(); |
| 11280 | QualType SecondParamType = SecondParam->getType(); |
| 11281 | if (FirstParamType != SecondParamType && |
| 11282 | ComputeQualTypeODRHash(FirstParamType) != |
| 11283 | ComputeQualTypeODRHash(SecondParamType)) { |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 11284 | if (const DecayedType *ParamDecayedType = |
| Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 11285 | FirstParamType->getAs<DecayedType>()) { |
| 11286 | ODRDiagError(FirstParam->getLocation(), |
| 11287 | FirstParam->getSourceRange(), ParameterType) |
| 11288 | << (I + 1) << FirstParamType << true |
| 11289 | << ParamDecayedType->getOriginalType(); |
| 11290 | } else { |
| 11291 | ODRDiagError(FirstParam->getLocation(), |
| 11292 | FirstParam->getSourceRange(), ParameterType) |
| 11293 | << (I + 1) << FirstParamType << false; |
| 11294 | } |
| 11295 | |
| Vedant Kumar | 48b4f76 | 2018-04-14 01:40:48 +0000 | [diff] [blame] | 11296 | if (const DecayedType *ParamDecayedType = |
| Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 11297 | SecondParamType->getAs<DecayedType>()) { |
| 11298 | ODRDiagNote(SecondParam->getLocation(), |
| 11299 | SecondParam->getSourceRange(), ParameterType) |
| 11300 | << (I + 1) << SecondParamType << true |
| 11301 | << ParamDecayedType->getOriginalType(); |
| 11302 | } else { |
| 11303 | ODRDiagNote(SecondParam->getLocation(), |
| 11304 | SecondParam->getSourceRange(), ParameterType) |
| 11305 | << (I + 1) << SecondParamType << false; |
| 11306 | } |
| 11307 | ParameterMismatch = true; |
| 11308 | break; |
| 11309 | } |
| 11310 | |
| 11311 | const Expr *FirstInit = FirstParam->getInit(); |
| 11312 | const Expr *SecondInit = SecondParam->getInit(); |
| 11313 | if ((FirstInit == nullptr) != (SecondInit == nullptr)) { |
| 11314 | ODRDiagError(FirstParam->getLocation(), FirstParam->getSourceRange(), |
| 11315 | ParameterSingleDefaultArgument) |
| 11316 | << (I + 1) << (FirstInit == nullptr) |
| 11317 | << (FirstInit ? FirstInit->getSourceRange() : SourceRange()); |
| 11318 | ODRDiagNote(SecondParam->getLocation(), SecondParam->getSourceRange(), |
| 11319 | ParameterSingleDefaultArgument) |
| 11320 | << (I + 1) << (SecondInit == nullptr) |
| 11321 | << (SecondInit ? SecondInit->getSourceRange() : SourceRange()); |
| 11322 | ParameterMismatch = true; |
| 11323 | break; |
| 11324 | } |
| 11325 | |
| 11326 | if (FirstInit && SecondInit && |
| 11327 | ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) { |
| 11328 | ODRDiagError(FirstParam->getLocation(), FirstParam->getSourceRange(), |
| 11329 | ParameterDifferentDefaultArgument) |
| 11330 | << (I + 1) << FirstInit->getSourceRange(); |
| 11331 | ODRDiagNote(SecondParam->getLocation(), SecondParam->getSourceRange(), |
| 11332 | ParameterDifferentDefaultArgument) |
| 11333 | << (I + 1) << SecondInit->getSourceRange(); |
| 11334 | ParameterMismatch = true; |
| 11335 | break; |
| 11336 | } |
| 11337 | |
| 11338 | assert(ComputeSubDeclODRHash(FirstParam) == |
| 11339 | ComputeSubDeclODRHash(SecondParam) && |
| 11340 | "Undiagnosed parameter difference."); |
| 11341 | } |
| 11342 | |
| 11343 | if (ParameterMismatch) { |
| 11344 | Diagnosed = true; |
| 11345 | break; |
| 11346 | } |
| 11347 | |
| 11348 | // If no error has been generated before now, assume the problem is in |
| 11349 | // the body and generate a message. |
| 11350 | ODRDiagError(FirstFunction->getLocation(), |
| 11351 | FirstFunction->getSourceRange(), FunctionBody); |
| 11352 | ODRDiagNote(SecondFunction->getLocation(), |
| 11353 | SecondFunction->getSourceRange(), FunctionBody); |
| 11354 | Diagnosed = true; |
| 11355 | break; |
| 11356 | } |
| Evgeny Stupachenko | bf25d67 | 2018-01-05 02:22:52 +0000 | [diff] [blame] | 11357 | (void)Diagnosed; |
| Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 11358 | assert(Diagnosed && "Unable to emit ODR diagnostic."); |
| 11359 | } |
| Richard Trieu | ab4d730 | 2018-07-25 22:52:05 +0000 | [diff] [blame] | 11360 | |
| 11361 | // Issue ODR failures diagnostics for enums. |
| 11362 | for (auto &Merge : EnumOdrMergeFailures) { |
| 11363 | enum ODREnumDifference { |
| 11364 | SingleScopedEnum, |
| 11365 | EnumTagKeywordMismatch, |
| 11366 | SingleSpecifiedType, |
| 11367 | DifferentSpecifiedTypes, |
| 11368 | DifferentNumberEnumConstants, |
| 11369 | EnumConstantName, |
| 11370 | EnumConstantSingleInitilizer, |
| 11371 | EnumConstantDifferentInitilizer, |
| 11372 | }; |
| 11373 | |
| 11374 | // If we've already pointed out a specific problem with this enum, don't |
| 11375 | // bother issuing a general "something's different" diagnostic. |
| 11376 | if (!DiagnosedOdrMergeFailures.insert(Merge.first).second) |
| 11377 | continue; |
| 11378 | |
| 11379 | EnumDecl *FirstEnum = Merge.first; |
| 11380 | std::string FirstModule = getOwningModuleNameForDiagnostic(FirstEnum); |
| 11381 | |
| 11382 | using DeclHashes = |
| 11383 | llvm::SmallVector<std::pair<EnumConstantDecl *, unsigned>, 4>; |
| 11384 | auto PopulateHashes = [&ComputeSubDeclODRHash, FirstEnum]( |
| 11385 | DeclHashes &Hashes, EnumDecl *Enum) { |
| 11386 | for (auto *D : Enum->decls()) { |
| 11387 | // Due to decl merging, the first EnumDecl is the parent of |
| 11388 | // Decls in both records. |
| 11389 | if (!ODRHash::isWhitelistedDecl(D, FirstEnum)) |
| 11390 | continue; |
| 11391 | assert(isa<EnumConstantDecl>(D) && "Unexpected Decl kind"); |
| 11392 | Hashes.emplace_back(cast<EnumConstantDecl>(D), |
| 11393 | ComputeSubDeclODRHash(D)); |
| 11394 | } |
| 11395 | }; |
| 11396 | DeclHashes FirstHashes; |
| 11397 | PopulateHashes(FirstHashes, FirstEnum); |
| 11398 | bool Diagnosed = false; |
| 11399 | for (auto &SecondEnum : Merge.second) { |
| 11400 | |
| 11401 | if (FirstEnum == SecondEnum) |
| 11402 | continue; |
| 11403 | |
| 11404 | std::string SecondModule = |
| 11405 | getOwningModuleNameForDiagnostic(SecondEnum); |
| 11406 | |
| 11407 | auto ODRDiagError = [FirstEnum, &FirstModule, |
| 11408 | this](SourceLocation Loc, SourceRange Range, |
| 11409 | ODREnumDifference DiffType) { |
| 11410 | return Diag(Loc, diag::err_module_odr_violation_enum) |
| 11411 | << FirstEnum << FirstModule.empty() << FirstModule << Range |
| 11412 | << DiffType; |
| 11413 | }; |
| 11414 | auto ODRDiagNote = [&SecondModule, this](SourceLocation Loc, |
| 11415 | SourceRange Range, |
| 11416 | ODREnumDifference DiffType) { |
| 11417 | return Diag(Loc, diag::note_module_odr_violation_enum) |
| 11418 | << SecondModule << Range << DiffType; |
| 11419 | }; |
| 11420 | |
| 11421 | if (FirstEnum->isScoped() != SecondEnum->isScoped()) { |
| 11422 | ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(), |
| 11423 | SingleScopedEnum) |
| 11424 | << FirstEnum->isScoped(); |
| 11425 | ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(), |
| 11426 | SingleScopedEnum) |
| 11427 | << SecondEnum->isScoped(); |
| 11428 | Diagnosed = true; |
| 11429 | continue; |
| 11430 | } |
| 11431 | |
| 11432 | if (FirstEnum->isScoped() && SecondEnum->isScoped()) { |
| 11433 | if (FirstEnum->isScopedUsingClassTag() != |
| 11434 | SecondEnum->isScopedUsingClassTag()) { |
| 11435 | ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(), |
| 11436 | EnumTagKeywordMismatch) |
| 11437 | << FirstEnum->isScopedUsingClassTag(); |
| 11438 | ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(), |
| 11439 | EnumTagKeywordMismatch) |
| 11440 | << SecondEnum->isScopedUsingClassTag(); |
| 11441 | Diagnosed = true; |
| 11442 | continue; |
| 11443 | } |
| 11444 | } |
| 11445 | |
| 11446 | QualType FirstUnderlyingType = |
| 11447 | FirstEnum->getIntegerTypeSourceInfo() |
| 11448 | ? FirstEnum->getIntegerTypeSourceInfo()->getType() |
| 11449 | : QualType(); |
| 11450 | QualType SecondUnderlyingType = |
| 11451 | SecondEnum->getIntegerTypeSourceInfo() |
| 11452 | ? SecondEnum->getIntegerTypeSourceInfo()->getType() |
| 11453 | : QualType(); |
| 11454 | if (FirstUnderlyingType.isNull() != SecondUnderlyingType.isNull()) { |
| 11455 | ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(), |
| 11456 | SingleSpecifiedType) |
| 11457 | << !FirstUnderlyingType.isNull(); |
| 11458 | ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(), |
| 11459 | SingleSpecifiedType) |
| 11460 | << !SecondUnderlyingType.isNull(); |
| 11461 | Diagnosed = true; |
| 11462 | continue; |
| 11463 | } |
| 11464 | |
| 11465 | if (!FirstUnderlyingType.isNull() && !SecondUnderlyingType.isNull()) { |
| 11466 | if (ComputeQualTypeODRHash(FirstUnderlyingType) != |
| 11467 | ComputeQualTypeODRHash(SecondUnderlyingType)) { |
| 11468 | ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(), |
| 11469 | DifferentSpecifiedTypes) |
| 11470 | << FirstUnderlyingType; |
| 11471 | ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(), |
| 11472 | DifferentSpecifiedTypes) |
| 11473 | << SecondUnderlyingType; |
| 11474 | Diagnosed = true; |
| 11475 | continue; |
| 11476 | } |
| 11477 | } |
| 11478 | |
| 11479 | DeclHashes SecondHashes; |
| 11480 | PopulateHashes(SecondHashes, SecondEnum); |
| 11481 | |
| 11482 | if (FirstHashes.size() != SecondHashes.size()) { |
| 11483 | ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(), |
| 11484 | DifferentNumberEnumConstants) |
| 11485 | << (int)FirstHashes.size(); |
| 11486 | ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(), |
| 11487 | DifferentNumberEnumConstants) |
| 11488 | << (int)SecondHashes.size(); |
| 11489 | Diagnosed = true; |
| 11490 | continue; |
| 11491 | } |
| 11492 | |
| 11493 | for (unsigned I = 0; I < FirstHashes.size(); ++I) { |
| 11494 | if (FirstHashes[I].second == SecondHashes[I].second) |
| 11495 | continue; |
| 11496 | const EnumConstantDecl *FirstEnumConstant = FirstHashes[I].first; |
| 11497 | const EnumConstantDecl *SecondEnumConstant = SecondHashes[I].first; |
| 11498 | |
| 11499 | if (FirstEnumConstant->getDeclName() != |
| 11500 | SecondEnumConstant->getDeclName()) { |
| 11501 | |
| 11502 | ODRDiagError(FirstEnumConstant->getLocation(), |
| 11503 | FirstEnumConstant->getSourceRange(), EnumConstantName) |
| 11504 | << I + 1 << FirstEnumConstant; |
| 11505 | ODRDiagNote(SecondEnumConstant->getLocation(), |
| 11506 | SecondEnumConstant->getSourceRange(), EnumConstantName) |
| 11507 | << I + 1 << SecondEnumConstant; |
| 11508 | Diagnosed = true; |
| 11509 | break; |
| 11510 | } |
| 11511 | |
| 11512 | const Expr *FirstInit = FirstEnumConstant->getInitExpr(); |
| 11513 | const Expr *SecondInit = SecondEnumConstant->getInitExpr(); |
| 11514 | if (!FirstInit && !SecondInit) |
| 11515 | continue; |
| 11516 | |
| 11517 | if (!FirstInit || !SecondInit) { |
| 11518 | ODRDiagError(FirstEnumConstant->getLocation(), |
| 11519 | FirstEnumConstant->getSourceRange(), |
| 11520 | EnumConstantSingleInitilizer) |
| 11521 | << I + 1 << FirstEnumConstant << (FirstInit != nullptr); |
| 11522 | ODRDiagNote(SecondEnumConstant->getLocation(), |
| 11523 | SecondEnumConstant->getSourceRange(), |
| 11524 | EnumConstantSingleInitilizer) |
| 11525 | << I + 1 << SecondEnumConstant << (SecondInit != nullptr); |
| 11526 | Diagnosed = true; |
| 11527 | break; |
| 11528 | } |
| 11529 | |
| 11530 | if (ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) { |
| 11531 | ODRDiagError(FirstEnumConstant->getLocation(), |
| 11532 | FirstEnumConstant->getSourceRange(), |
| 11533 | EnumConstantDifferentInitilizer) |
| 11534 | << I + 1 << FirstEnumConstant; |
| 11535 | ODRDiagNote(SecondEnumConstant->getLocation(), |
| 11536 | SecondEnumConstant->getSourceRange(), |
| 11537 | EnumConstantDifferentInitilizer) |
| 11538 | << I + 1 << SecondEnumConstant; |
| 11539 | Diagnosed = true; |
| 11540 | break; |
| 11541 | } |
| 11542 | } |
| 11543 | } |
| 11544 | |
| 11545 | (void)Diagnosed; |
| 11546 | assert(Diagnosed && "Unable to emit ODR diagnostic."); |
| 11547 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 11548 | } |
| 11549 | |
| Richard Smith | ce18a18 | 2015-07-14 00:26:00 +0000 | [diff] [blame] | 11550 | void ASTReader::StartedDeserializing() { |
| David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 11551 | if (++NumCurrentElementsDeserializing == 1 && ReadTimer.get()) |
| Richard Smith | ce18a18 | 2015-07-14 00:26:00 +0000 | [diff] [blame] | 11552 | ReadTimer->startTimer(); |
| 11553 | } |
| 11554 | |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 11555 | void ASTReader::FinishedDeserializing() { |
| 11556 | assert(NumCurrentElementsDeserializing && |
| 11557 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 11558 | if (NumCurrentElementsDeserializing == 1) { |
| 11559 | // We decrease NumCurrentElementsDeserializing only after pending actions |
| 11560 | // are finished, to avoid recursively re-calling finishPendingActions(). |
| 11561 | finishPendingActions(); |
| 11562 | } |
| 11563 | --NumCurrentElementsDeserializing; |
| 11564 | |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 11565 | if (NumCurrentElementsDeserializing == 0) { |
| Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 11566 | // Propagate exception specification and deduced type updates along |
| 11567 | // redeclaration chains. |
| 11568 | // |
| 11569 | // We do this now rather than in finishPendingActions because we want to |
| 11570 | // be able to walk the complete redeclaration chains of the updated decls. |
| 11571 | while (!PendingExceptionSpecUpdates.empty() || |
| 11572 | !PendingDeducedTypeUpdates.empty()) { |
| 11573 | auto ESUpdates = std::move(PendingExceptionSpecUpdates); |
| Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 11574 | PendingExceptionSpecUpdates.clear(); |
| Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 11575 | for (auto Update : ESUpdates) { |
| Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 11576 | ProcessingUpdatesRAIIObj ProcessingUpdates(*this); |
| Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 11577 | auto *FPT = Update.second->getType()->castAs<FunctionProtoType>(); |
| Richard Smith | 1d0f199 | 2015-08-19 21:09:32 +0000 | [diff] [blame] | 11578 | auto ESI = FPT->getExtProtoInfo().ExceptionSpec; |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 11579 | if (auto *Listener = getContext().getASTMutationListener()) |
| Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 11580 | Listener->ResolvedExceptionSpec(cast<FunctionDecl>(Update.second)); |
| Richard Smith | 1d0f199 | 2015-08-19 21:09:32 +0000 | [diff] [blame] | 11581 | for (auto *Redecl : Update.second->redecls()) |
| Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 11582 | getContext().adjustExceptionSpec(cast<FunctionDecl>(Redecl), ESI); |
| Richard Smith | 7226f2a | 2015-03-23 19:54:56 +0000 | [diff] [blame] | 11583 | } |
| Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 11584 | |
| 11585 | auto DTUpdates = std::move(PendingDeducedTypeUpdates); |
| 11586 | PendingDeducedTypeUpdates.clear(); |
| 11587 | for (auto Update : DTUpdates) { |
| 11588 | ProcessingUpdatesRAIIObj ProcessingUpdates(*this); |
| 11589 | // FIXME: If the return type is already deduced, check that it matches. |
| 11590 | getContext().adjustDeducedFunctionResultType(Update.first, |
| 11591 | Update.second); |
| 11592 | } |
| Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 11593 | } |
| 11594 | |
| Richard Smith | ce18a18 | 2015-07-14 00:26:00 +0000 | [diff] [blame] | 11595 | if (ReadTimer) |
| 11596 | ReadTimer->stopTimer(); |
| 11597 | |
| Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 11598 | diagnoseOdrViolations(); |
| 11599 | |
| Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 11600 | // We are not in recursive loading, so it's safe to pass the "interesting" |
| 11601 | // decls to the consumer. |
| Richard Smith | a0ce9c4 | 2014-07-29 23:23:27 +0000 | [diff] [blame] | 11602 | if (Consumer) |
| 11603 | PassInterestingDeclsToConsumer(); |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 11604 | } |
| 11605 | } |
| 11606 | |
| Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 11607 | void ASTReader::pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name) { |
| Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 11608 | if (IdentifierInfo *II = Name.getAsIdentifierInfo()) { |
| 11609 | // Remove any fake results before adding any real ones. |
| 11610 | auto It = PendingFakeLookupResults.find(II); |
| 11611 | if (It != PendingFakeLookupResults.end()) { |
| Richard Smith | a534a31 | 2015-07-21 23:54:07 +0000 | [diff] [blame] | 11612 | for (auto *ND : It->second) |
| Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 11613 | SemaObj->IdResolver.RemoveDecl(ND); |
| Ben Langmuir | eb8bd2d | 2015-04-10 22:25:42 +0000 | [diff] [blame] | 11614 | // FIXME: this works around module+PCH performance issue. |
| 11615 | // Rather than erase the result from the map, which is O(n), just clear |
| 11616 | // the vector of NamedDecls. |
| 11617 | It->second.clear(); |
| Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 11618 | } |
| 11619 | } |
| Argyrios Kyrtzidis | e5edbf9 | 2013-04-26 21:33:35 +0000 | [diff] [blame] | 11620 | |
| 11621 | if (SemaObj->IdResolver.tryAddTopLevelDecl(D, Name) && SemaObj->TUScope) { |
| 11622 | SemaObj->TUScope->AddDecl(D); |
| 11623 | } else if (SemaObj->TUScope) { |
| 11624 | // Adding the decl to IdResolver may have failed because it was already in |
| 11625 | // (even though it was not added in scope). If it is already in, make sure |
| 11626 | // it gets in the scope as well. |
| 11627 | if (std::find(SemaObj->IdResolver.begin(Name), |
| 11628 | SemaObj->IdResolver.end(), D) != SemaObj->IdResolver.end()) |
| 11629 | SemaObj->TUScope->AddDecl(D); |
| 11630 | } |
| 11631 | } |
| 11632 | |
| Duncan P. N. Exon Smith | 8bef5cd | 2019-03-09 17:33:56 +0000 | [diff] [blame] | 11633 | ASTReader::ASTReader(Preprocessor &PP, InMemoryModuleCache &ModuleCache, |
| 11634 | ASTContext *Context, |
| David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 11635 | const PCHContainerReader &PCHContainerRdr, |
| 11636 | ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, |
| 11637 | StringRef isysroot, bool DisableValidation, |
| 11638 | bool AllowASTWithCompilerErrors, |
| 11639 | bool AllowConfigurationMismatch, bool ValidateSystemInputs, |
| 11640 | bool UseGlobalIndex, |
| 11641 | std::unique_ptr<llvm::Timer> ReadTimer) |
| 11642 | : Listener(DisableValidation |
| 11643 | ? cast<ASTReaderListener>(new SimpleASTReaderListener(PP)) |
| 11644 | : cast<ASTReaderListener>(new PCHValidator(PP, *this))), |
| David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 11645 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| David Blaikie | 9d7c1ba | 2017-01-05 18:45:43 +0000 | [diff] [blame] | 11646 | PCHContainerRdr(PCHContainerRdr), Diags(PP.getDiagnostics()), PP(PP), |
| Duncan P. N. Exon Smith | 8bef5cd | 2019-03-09 17:33:56 +0000 | [diff] [blame] | 11647 | ContextObj(Context), ModuleMgr(PP.getFileManager(), ModuleCache, |
| 11648 | PCHContainerRdr, PP.getHeaderSearchInfo()), |
| 11649 | DummyIdResolver(PP), ReadTimer(std::move(ReadTimer)), isysroot(isysroot), |
| David Blaikie | 61137e1 | 2017-01-05 18:23:18 +0000 | [diff] [blame] | 11650 | DisableValidation(DisableValidation), |
| Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 11651 | AllowASTWithCompilerErrors(AllowASTWithCompilerErrors), |
| 11652 | AllowConfigurationMismatch(AllowConfigurationMismatch), |
| 11653 | ValidateSystemInputs(ValidateSystemInputs), |
| David Blaikie | 9d7c1ba | 2017-01-05 18:45:43 +0000 | [diff] [blame] | 11654 | UseGlobalIndex(UseGlobalIndex), CurrSwitchCaseStmts(&SwitchCaseStmts) { |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 11655 | SourceMgr.setExternalSLocEntrySource(this); |
| Douglas Gregor | 6623e1f | 2015-11-03 18:33:07 +0000 | [diff] [blame] | 11656 | |
| 11657 | for (const auto &Ext : Extensions) { |
| 11658 | auto BlockName = Ext->getExtensionMetadata().BlockName; |
| 11659 | auto Known = ModuleFileExtensions.find(BlockName); |
| 11660 | if (Known != ModuleFileExtensions.end()) { |
| 11661 | Diags.Report(diag::warn_duplicate_module_file_extension) |
| 11662 | << BlockName; |
| 11663 | continue; |
| 11664 | } |
| 11665 | |
| 11666 | ModuleFileExtensions.insert({BlockName, Ext}); |
| 11667 | } |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 11668 | } |
| 11669 | |
| 11670 | ASTReader::~ASTReader() { |
| Nico Weber | 824285e | 2014-05-08 04:26:47 +0000 | [diff] [blame] | 11671 | if (OwnsDeserializationListener) |
| 11672 | delete DeserializationListener; |
| Guy Benyei | 11169dd | 2012-12-18 14:30:41 +0000 | [diff] [blame] | 11673 | } |
| Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 11674 | |
| 11675 | IdentifierResolver &ASTReader::getIdResolver() { |
| 11676 | return SemaObj ? SemaObj->IdResolver : DummyIdResolver; |
| 11677 | } |
| David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 11678 | |
| 11679 | unsigned ASTRecordReader::readRecord(llvm::BitstreamCursor &Cursor, |
| 11680 | unsigned AbbrevID) { |
| 11681 | Idx = 0; |
| 11682 | Record.clear(); |
| 11683 | return Cursor.readRecord(AbbrevID, Record); |
| 11684 | } |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 11685 | //===----------------------------------------------------------------------===// |
| 11686 | //// OMPClauseReader implementation |
| 11687 | ////===----------------------------------------------------------------------===// |
| 11688 | |
| 11689 | OMPClause *OMPClauseReader::readClause() { |
| 11690 | OMPClause *C; |
| 11691 | switch (Record.readInt()) { |
| 11692 | case OMPC_if: |
| 11693 | C = new (Context) OMPIfClause(); |
| 11694 | break; |
| 11695 | case OMPC_final: |
| 11696 | C = new (Context) OMPFinalClause(); |
| 11697 | break; |
| 11698 | case OMPC_num_threads: |
| 11699 | C = new (Context) OMPNumThreadsClause(); |
| 11700 | break; |
| 11701 | case OMPC_safelen: |
| 11702 | C = new (Context) OMPSafelenClause(); |
| 11703 | break; |
| 11704 | case OMPC_simdlen: |
| 11705 | C = new (Context) OMPSimdlenClause(); |
| 11706 | break; |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 11707 | case OMPC_allocator: |
| 11708 | C = new (Context) OMPAllocatorClause(); |
| 11709 | break; |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 11710 | case OMPC_collapse: |
| 11711 | C = new (Context) OMPCollapseClause(); |
| 11712 | break; |
| 11713 | case OMPC_default: |
| 11714 | C = new (Context) OMPDefaultClause(); |
| 11715 | break; |
| 11716 | case OMPC_proc_bind: |
| 11717 | C = new (Context) OMPProcBindClause(); |
| 11718 | break; |
| 11719 | case OMPC_schedule: |
| 11720 | C = new (Context) OMPScheduleClause(); |
| 11721 | break; |
| 11722 | case OMPC_ordered: |
| 11723 | C = OMPOrderedClause::CreateEmpty(Context, Record.readInt()); |
| 11724 | break; |
| 11725 | case OMPC_nowait: |
| 11726 | C = new (Context) OMPNowaitClause(); |
| 11727 | break; |
| 11728 | case OMPC_untied: |
| 11729 | C = new (Context) OMPUntiedClause(); |
| 11730 | break; |
| 11731 | case OMPC_mergeable: |
| 11732 | C = new (Context) OMPMergeableClause(); |
| 11733 | break; |
| 11734 | case OMPC_read: |
| 11735 | C = new (Context) OMPReadClause(); |
| 11736 | break; |
| 11737 | case OMPC_write: |
| 11738 | C = new (Context) OMPWriteClause(); |
| 11739 | break; |
| 11740 | case OMPC_update: |
| 11741 | C = new (Context) OMPUpdateClause(); |
| 11742 | break; |
| 11743 | case OMPC_capture: |
| 11744 | C = new (Context) OMPCaptureClause(); |
| 11745 | break; |
| 11746 | case OMPC_seq_cst: |
| 11747 | C = new (Context) OMPSeqCstClause(); |
| 11748 | break; |
| 11749 | case OMPC_threads: |
| 11750 | C = new (Context) OMPThreadsClause(); |
| 11751 | break; |
| 11752 | case OMPC_simd: |
| 11753 | C = new (Context) OMPSIMDClause(); |
| 11754 | break; |
| 11755 | case OMPC_nogroup: |
| 11756 | C = new (Context) OMPNogroupClause(); |
| 11757 | break; |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 11758 | case OMPC_unified_address: |
| 11759 | C = new (Context) OMPUnifiedAddressClause(); |
| 11760 | break; |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 11761 | case OMPC_unified_shared_memory: |
| 11762 | C = new (Context) OMPUnifiedSharedMemoryClause(); |
| 11763 | break; |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 11764 | case OMPC_reverse_offload: |
| 11765 | C = new (Context) OMPReverseOffloadClause(); |
| 11766 | break; |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 11767 | case OMPC_dynamic_allocators: |
| 11768 | C = new (Context) OMPDynamicAllocatorsClause(); |
| 11769 | break; |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 11770 | case OMPC_atomic_default_mem_order: |
| 11771 | C = new (Context) OMPAtomicDefaultMemOrderClause(); |
| 11772 | break; |
| 11773 | case OMPC_private: |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 11774 | C = OMPPrivateClause::CreateEmpty(Context, Record.readInt()); |
| 11775 | break; |
| 11776 | case OMPC_firstprivate: |
| 11777 | C = OMPFirstprivateClause::CreateEmpty(Context, Record.readInt()); |
| 11778 | break; |
| 11779 | case OMPC_lastprivate: |
| 11780 | C = OMPLastprivateClause::CreateEmpty(Context, Record.readInt()); |
| 11781 | break; |
| 11782 | case OMPC_shared: |
| 11783 | C = OMPSharedClause::CreateEmpty(Context, Record.readInt()); |
| 11784 | break; |
| 11785 | case OMPC_reduction: |
| 11786 | C = OMPReductionClause::CreateEmpty(Context, Record.readInt()); |
| 11787 | break; |
| 11788 | case OMPC_task_reduction: |
| 11789 | C = OMPTaskReductionClause::CreateEmpty(Context, Record.readInt()); |
| 11790 | break; |
| 11791 | case OMPC_in_reduction: |
| 11792 | C = OMPInReductionClause::CreateEmpty(Context, Record.readInt()); |
| 11793 | break; |
| 11794 | case OMPC_linear: |
| 11795 | C = OMPLinearClause::CreateEmpty(Context, Record.readInt()); |
| 11796 | break; |
| 11797 | case OMPC_aligned: |
| 11798 | C = OMPAlignedClause::CreateEmpty(Context, Record.readInt()); |
| 11799 | break; |
| 11800 | case OMPC_copyin: |
| 11801 | C = OMPCopyinClause::CreateEmpty(Context, Record.readInt()); |
| 11802 | break; |
| 11803 | case OMPC_copyprivate: |
| 11804 | C = OMPCopyprivateClause::CreateEmpty(Context, Record.readInt()); |
| 11805 | break; |
| 11806 | case OMPC_flush: |
| 11807 | C = OMPFlushClause::CreateEmpty(Context, Record.readInt()); |
| 11808 | break; |
| 11809 | case OMPC_depend: { |
| 11810 | unsigned NumVars = Record.readInt(); |
| 11811 | unsigned NumLoops = Record.readInt(); |
| 11812 | C = OMPDependClause::CreateEmpty(Context, NumVars, NumLoops); |
| 11813 | break; |
| 11814 | } |
| 11815 | case OMPC_device: |
| 11816 | C = new (Context) OMPDeviceClause(); |
| 11817 | break; |
| 11818 | case OMPC_map: { |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 11819 | OMPMappableExprListSizeTy Sizes; |
| 11820 | Sizes.NumVars = Record.readInt(); |
| 11821 | Sizes.NumUniqueDeclarations = Record.readInt(); |
| 11822 | Sizes.NumComponentLists = Record.readInt(); |
| 11823 | Sizes.NumComponents = Record.readInt(); |
| 11824 | C = OMPMapClause::CreateEmpty(Context, Sizes); |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 11825 | break; |
| 11826 | } |
| 11827 | case OMPC_num_teams: |
| 11828 | C = new (Context) OMPNumTeamsClause(); |
| 11829 | break; |
| 11830 | case OMPC_thread_limit: |
| 11831 | C = new (Context) OMPThreadLimitClause(); |
| 11832 | break; |
| 11833 | case OMPC_priority: |
| 11834 | C = new (Context) OMPPriorityClause(); |
| 11835 | break; |
| 11836 | case OMPC_grainsize: |
| 11837 | C = new (Context) OMPGrainsizeClause(); |
| 11838 | break; |
| 11839 | case OMPC_num_tasks: |
| 11840 | C = new (Context) OMPNumTasksClause(); |
| 11841 | break; |
| 11842 | case OMPC_hint: |
| 11843 | C = new (Context) OMPHintClause(); |
| 11844 | break; |
| 11845 | case OMPC_dist_schedule: |
| 11846 | C = new (Context) OMPDistScheduleClause(); |
| 11847 | break; |
| 11848 | case OMPC_defaultmap: |
| 11849 | C = new (Context) OMPDefaultmapClause(); |
| 11850 | break; |
| 11851 | case OMPC_to: { |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 11852 | OMPMappableExprListSizeTy Sizes; |
| 11853 | Sizes.NumVars = Record.readInt(); |
| 11854 | Sizes.NumUniqueDeclarations = Record.readInt(); |
| 11855 | Sizes.NumComponentLists = Record.readInt(); |
| 11856 | Sizes.NumComponents = Record.readInt(); |
| 11857 | C = OMPToClause::CreateEmpty(Context, Sizes); |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 11858 | break; |
| 11859 | } |
| 11860 | case OMPC_from: { |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 11861 | OMPMappableExprListSizeTy Sizes; |
| 11862 | Sizes.NumVars = Record.readInt(); |
| 11863 | Sizes.NumUniqueDeclarations = Record.readInt(); |
| 11864 | Sizes.NumComponentLists = Record.readInt(); |
| 11865 | Sizes.NumComponents = Record.readInt(); |
| 11866 | C = OMPFromClause::CreateEmpty(Context, Sizes); |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 11867 | break; |
| 11868 | } |
| 11869 | case OMPC_use_device_ptr: { |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 11870 | OMPMappableExprListSizeTy Sizes; |
| 11871 | Sizes.NumVars = Record.readInt(); |
| 11872 | Sizes.NumUniqueDeclarations = Record.readInt(); |
| 11873 | Sizes.NumComponentLists = Record.readInt(); |
| 11874 | Sizes.NumComponents = Record.readInt(); |
| 11875 | C = OMPUseDevicePtrClause::CreateEmpty(Context, Sizes); |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 11876 | break; |
| 11877 | } |
| 11878 | case OMPC_is_device_ptr: { |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 11879 | OMPMappableExprListSizeTy Sizes; |
| 11880 | Sizes.NumVars = Record.readInt(); |
| 11881 | Sizes.NumUniqueDeclarations = Record.readInt(); |
| 11882 | Sizes.NumComponentLists = Record.readInt(); |
| 11883 | Sizes.NumComponents = Record.readInt(); |
| 11884 | C = OMPIsDevicePtrClause::CreateEmpty(Context, Sizes); |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 11885 | break; |
| 11886 | } |
| 11887 | } |
| 11888 | Visit(C); |
| 11889 | C->setLocStart(Record.readSourceLocation()); |
| 11890 | C->setLocEnd(Record.readSourceLocation()); |
| 11891 | |
| 11892 | return C; |
| 11893 | } |
| 11894 | |
| 11895 | void OMPClauseReader::VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C) { |
| 11896 | C->setPreInitStmt(Record.readSubStmt(), |
| 11897 | static_cast<OpenMPDirectiveKind>(Record.readInt())); |
| 11898 | } |
| 11899 | |
| 11900 | void OMPClauseReader::VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C) { |
| 11901 | VisitOMPClauseWithPreInit(C); |
| 11902 | C->setPostUpdateExpr(Record.readSubExpr()); |
| 11903 | } |
| 11904 | |
| 11905 | void OMPClauseReader::VisitOMPIfClause(OMPIfClause *C) { |
| 11906 | VisitOMPClauseWithPreInit(C); |
| 11907 | C->setNameModifier(static_cast<OpenMPDirectiveKind>(Record.readInt())); |
| 11908 | C->setNameModifierLoc(Record.readSourceLocation()); |
| 11909 | C->setColonLoc(Record.readSourceLocation()); |
| 11910 | C->setCondition(Record.readSubExpr()); |
| 11911 | C->setLParenLoc(Record.readSourceLocation()); |
| 11912 | } |
| 11913 | |
| 11914 | void OMPClauseReader::VisitOMPFinalClause(OMPFinalClause *C) { |
| 11915 | C->setCondition(Record.readSubExpr()); |
| 11916 | C->setLParenLoc(Record.readSourceLocation()); |
| 11917 | } |
| 11918 | |
| 11919 | void OMPClauseReader::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) { |
| 11920 | VisitOMPClauseWithPreInit(C); |
| 11921 | C->setNumThreads(Record.readSubExpr()); |
| 11922 | C->setLParenLoc(Record.readSourceLocation()); |
| 11923 | } |
| 11924 | |
| 11925 | void OMPClauseReader::VisitOMPSafelenClause(OMPSafelenClause *C) { |
| 11926 | C->setSafelen(Record.readSubExpr()); |
| 11927 | C->setLParenLoc(Record.readSourceLocation()); |
| 11928 | } |
| 11929 | |
| 11930 | void OMPClauseReader::VisitOMPSimdlenClause(OMPSimdlenClause *C) { |
| 11931 | C->setSimdlen(Record.readSubExpr()); |
| 11932 | C->setLParenLoc(Record.readSourceLocation()); |
| 11933 | } |
| 11934 | |
| Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 11935 | void OMPClauseReader::VisitOMPAllocatorClause(OMPAllocatorClause *C) { |
| 11936 | C->setAllocator(Record.readExpr()); |
| 11937 | C->setLParenLoc(Record.readSourceLocation()); |
| 11938 | } |
| 11939 | |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 11940 | void OMPClauseReader::VisitOMPCollapseClause(OMPCollapseClause *C) { |
| 11941 | C->setNumForLoops(Record.readSubExpr()); |
| 11942 | C->setLParenLoc(Record.readSourceLocation()); |
| 11943 | } |
| 11944 | |
| 11945 | void OMPClauseReader::VisitOMPDefaultClause(OMPDefaultClause *C) { |
| 11946 | C->setDefaultKind( |
| 11947 | static_cast<OpenMPDefaultClauseKind>(Record.readInt())); |
| 11948 | C->setLParenLoc(Record.readSourceLocation()); |
| 11949 | C->setDefaultKindKwLoc(Record.readSourceLocation()); |
| 11950 | } |
| 11951 | |
| 11952 | void OMPClauseReader::VisitOMPProcBindClause(OMPProcBindClause *C) { |
| 11953 | C->setProcBindKind( |
| 11954 | static_cast<OpenMPProcBindClauseKind>(Record.readInt())); |
| 11955 | C->setLParenLoc(Record.readSourceLocation()); |
| 11956 | C->setProcBindKindKwLoc(Record.readSourceLocation()); |
| 11957 | } |
| 11958 | |
| 11959 | void OMPClauseReader::VisitOMPScheduleClause(OMPScheduleClause *C) { |
| 11960 | VisitOMPClauseWithPreInit(C); |
| 11961 | C->setScheduleKind( |
| 11962 | static_cast<OpenMPScheduleClauseKind>(Record.readInt())); |
| 11963 | C->setFirstScheduleModifier( |
| 11964 | static_cast<OpenMPScheduleClauseModifier>(Record.readInt())); |
| 11965 | C->setSecondScheduleModifier( |
| 11966 | static_cast<OpenMPScheduleClauseModifier>(Record.readInt())); |
| 11967 | C->setChunkSize(Record.readSubExpr()); |
| 11968 | C->setLParenLoc(Record.readSourceLocation()); |
| 11969 | C->setFirstScheduleModifierLoc(Record.readSourceLocation()); |
| 11970 | C->setSecondScheduleModifierLoc(Record.readSourceLocation()); |
| 11971 | C->setScheduleKindLoc(Record.readSourceLocation()); |
| 11972 | C->setCommaLoc(Record.readSourceLocation()); |
| 11973 | } |
| 11974 | |
| 11975 | void OMPClauseReader::VisitOMPOrderedClause(OMPOrderedClause *C) { |
| 11976 | C->setNumForLoops(Record.readSubExpr()); |
| 11977 | for (unsigned I = 0, E = C->NumberOfLoops; I < E; ++I) |
| 11978 | C->setLoopNumIterations(I, Record.readSubExpr()); |
| 11979 | for (unsigned I = 0, E = C->NumberOfLoops; I < E; ++I) |
| 11980 | C->setLoopCounter(I, Record.readSubExpr()); |
| 11981 | C->setLParenLoc(Record.readSourceLocation()); |
| 11982 | } |
| 11983 | |
| 11984 | void OMPClauseReader::VisitOMPNowaitClause(OMPNowaitClause *) {} |
| 11985 | |
| 11986 | void OMPClauseReader::VisitOMPUntiedClause(OMPUntiedClause *) {} |
| 11987 | |
| 11988 | void OMPClauseReader::VisitOMPMergeableClause(OMPMergeableClause *) {} |
| 11989 | |
| 11990 | void OMPClauseReader::VisitOMPReadClause(OMPReadClause *) {} |
| 11991 | |
| 11992 | void OMPClauseReader::VisitOMPWriteClause(OMPWriteClause *) {} |
| 11993 | |
| 11994 | void OMPClauseReader::VisitOMPUpdateClause(OMPUpdateClause *) {} |
| 11995 | |
| 11996 | void OMPClauseReader::VisitOMPCaptureClause(OMPCaptureClause *) {} |
| 11997 | |
| 11998 | void OMPClauseReader::VisitOMPSeqCstClause(OMPSeqCstClause *) {} |
| 11999 | |
| 12000 | void OMPClauseReader::VisitOMPThreadsClause(OMPThreadsClause *) {} |
| 12001 | |
| 12002 | void OMPClauseReader::VisitOMPSIMDClause(OMPSIMDClause *) {} |
| 12003 | |
| 12004 | void OMPClauseReader::VisitOMPNogroupClause(OMPNogroupClause *) {} |
| 12005 | |
| Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 12006 | void OMPClauseReader::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {} |
| 12007 | |
| Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 12008 | void OMPClauseReader::VisitOMPUnifiedSharedMemoryClause( |
| 12009 | OMPUnifiedSharedMemoryClause *) {} |
| 12010 | |
| Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 12011 | void OMPClauseReader::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {} |
| 12012 | |
| Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 12013 | void |
| 12014 | OMPClauseReader::VisitOMPDynamicAllocatorsClause(OMPDynamicAllocatorsClause *) { |
| 12015 | } |
| 12016 | |
| Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 12017 | void OMPClauseReader::VisitOMPAtomicDefaultMemOrderClause( |
| 12018 | OMPAtomicDefaultMemOrderClause *C) { |
| 12019 | C->setAtomicDefaultMemOrderKind( |
| 12020 | static_cast<OpenMPAtomicDefaultMemOrderClauseKind>(Record.readInt())); |
| 12021 | C->setLParenLoc(Record.readSourceLocation()); |
| 12022 | C->setAtomicDefaultMemOrderKindKwLoc(Record.readSourceLocation()); |
| 12023 | } |
| 12024 | |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 12025 | void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) { |
| 12026 | C->setLParenLoc(Record.readSourceLocation()); |
| 12027 | unsigned NumVars = C->varlist_size(); |
| 12028 | SmallVector<Expr *, 16> Vars; |
| 12029 | Vars.reserve(NumVars); |
| 12030 | for (unsigned i = 0; i != NumVars; ++i) |
| 12031 | Vars.push_back(Record.readSubExpr()); |
| 12032 | C->setVarRefs(Vars); |
| 12033 | Vars.clear(); |
| 12034 | for (unsigned i = 0; i != NumVars; ++i) |
| 12035 | Vars.push_back(Record.readSubExpr()); |
| 12036 | C->setPrivateCopies(Vars); |
| 12037 | } |
| 12038 | |
| 12039 | void OMPClauseReader::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) { |
| 12040 | VisitOMPClauseWithPreInit(C); |
| 12041 | C->setLParenLoc(Record.readSourceLocation()); |
| 12042 | unsigned NumVars = C->varlist_size(); |
| 12043 | SmallVector<Expr *, 16> Vars; |
| 12044 | Vars.reserve(NumVars); |
| 12045 | for (unsigned i = 0; i != NumVars; ++i) |
| 12046 | Vars.push_back(Record.readSubExpr()); |
| 12047 | C->setVarRefs(Vars); |
| 12048 | Vars.clear(); |
| 12049 | for (unsigned i = 0; i != NumVars; ++i) |
| 12050 | Vars.push_back(Record.readSubExpr()); |
| 12051 | C->setPrivateCopies(Vars); |
| 12052 | Vars.clear(); |
| 12053 | for (unsigned i = 0; i != NumVars; ++i) |
| 12054 | Vars.push_back(Record.readSubExpr()); |
| 12055 | C->setInits(Vars); |
| 12056 | } |
| 12057 | |
| 12058 | void OMPClauseReader::VisitOMPLastprivateClause(OMPLastprivateClause *C) { |
| 12059 | VisitOMPClauseWithPostUpdate(C); |
| 12060 | C->setLParenLoc(Record.readSourceLocation()); |
| 12061 | unsigned NumVars = C->varlist_size(); |
| 12062 | SmallVector<Expr *, 16> Vars; |
| 12063 | Vars.reserve(NumVars); |
| 12064 | for (unsigned i = 0; i != NumVars; ++i) |
| 12065 | Vars.push_back(Record.readSubExpr()); |
| 12066 | C->setVarRefs(Vars); |
| 12067 | Vars.clear(); |
| 12068 | for (unsigned i = 0; i != NumVars; ++i) |
| 12069 | Vars.push_back(Record.readSubExpr()); |
| 12070 | C->setPrivateCopies(Vars); |
| 12071 | Vars.clear(); |
| 12072 | for (unsigned i = 0; i != NumVars; ++i) |
| 12073 | Vars.push_back(Record.readSubExpr()); |
| 12074 | C->setSourceExprs(Vars); |
| 12075 | Vars.clear(); |
| 12076 | for (unsigned i = 0; i != NumVars; ++i) |
| 12077 | Vars.push_back(Record.readSubExpr()); |
| 12078 | C->setDestinationExprs(Vars); |
| 12079 | Vars.clear(); |
| 12080 | for (unsigned i = 0; i != NumVars; ++i) |
| 12081 | Vars.push_back(Record.readSubExpr()); |
| 12082 | C->setAssignmentOps(Vars); |
| 12083 | } |
| 12084 | |
| 12085 | void OMPClauseReader::VisitOMPSharedClause(OMPSharedClause *C) { |
| 12086 | C->setLParenLoc(Record.readSourceLocation()); |
| 12087 | unsigned NumVars = C->varlist_size(); |
| 12088 | SmallVector<Expr *, 16> Vars; |
| 12089 | Vars.reserve(NumVars); |
| 12090 | for (unsigned i = 0; i != NumVars; ++i) |
| 12091 | Vars.push_back(Record.readSubExpr()); |
| 12092 | C->setVarRefs(Vars); |
| 12093 | } |
| 12094 | |
| 12095 | void OMPClauseReader::VisitOMPReductionClause(OMPReductionClause *C) { |
| 12096 | VisitOMPClauseWithPostUpdate(C); |
| 12097 | C->setLParenLoc(Record.readSourceLocation()); |
| 12098 | C->setColonLoc(Record.readSourceLocation()); |
| 12099 | NestedNameSpecifierLoc NNSL = Record.readNestedNameSpecifierLoc(); |
| 12100 | DeclarationNameInfo DNI; |
| 12101 | Record.readDeclarationNameInfo(DNI); |
| 12102 | C->setQualifierLoc(NNSL); |
| 12103 | C->setNameInfo(DNI); |
| 12104 | |
| 12105 | unsigned NumVars = C->varlist_size(); |
| 12106 | SmallVector<Expr *, 16> Vars; |
| 12107 | Vars.reserve(NumVars); |
| 12108 | for (unsigned i = 0; i != NumVars; ++i) |
| 12109 | Vars.push_back(Record.readSubExpr()); |
| 12110 | C->setVarRefs(Vars); |
| 12111 | Vars.clear(); |
| 12112 | for (unsigned i = 0; i != NumVars; ++i) |
| 12113 | Vars.push_back(Record.readSubExpr()); |
| 12114 | C->setPrivates(Vars); |
| 12115 | Vars.clear(); |
| 12116 | for (unsigned i = 0; i != NumVars; ++i) |
| 12117 | Vars.push_back(Record.readSubExpr()); |
| 12118 | C->setLHSExprs(Vars); |
| 12119 | Vars.clear(); |
| 12120 | for (unsigned i = 0; i != NumVars; ++i) |
| 12121 | Vars.push_back(Record.readSubExpr()); |
| 12122 | C->setRHSExprs(Vars); |
| 12123 | Vars.clear(); |
| 12124 | for (unsigned i = 0; i != NumVars; ++i) |
| 12125 | Vars.push_back(Record.readSubExpr()); |
| 12126 | C->setReductionOps(Vars); |
| 12127 | } |
| 12128 | |
| 12129 | void OMPClauseReader::VisitOMPTaskReductionClause(OMPTaskReductionClause *C) { |
| 12130 | VisitOMPClauseWithPostUpdate(C); |
| 12131 | C->setLParenLoc(Record.readSourceLocation()); |
| 12132 | C->setColonLoc(Record.readSourceLocation()); |
| 12133 | NestedNameSpecifierLoc NNSL = Record.readNestedNameSpecifierLoc(); |
| 12134 | DeclarationNameInfo DNI; |
| 12135 | Record.readDeclarationNameInfo(DNI); |
| 12136 | C->setQualifierLoc(NNSL); |
| 12137 | C->setNameInfo(DNI); |
| 12138 | |
| 12139 | unsigned NumVars = C->varlist_size(); |
| 12140 | SmallVector<Expr *, 16> Vars; |
| 12141 | Vars.reserve(NumVars); |
| 12142 | for (unsigned I = 0; I != NumVars; ++I) |
| 12143 | Vars.push_back(Record.readSubExpr()); |
| 12144 | C->setVarRefs(Vars); |
| 12145 | Vars.clear(); |
| 12146 | for (unsigned I = 0; I != NumVars; ++I) |
| 12147 | Vars.push_back(Record.readSubExpr()); |
| 12148 | C->setPrivates(Vars); |
| 12149 | Vars.clear(); |
| 12150 | for (unsigned I = 0; I != NumVars; ++I) |
| 12151 | Vars.push_back(Record.readSubExpr()); |
| 12152 | C->setLHSExprs(Vars); |
| 12153 | Vars.clear(); |
| 12154 | for (unsigned I = 0; I != NumVars; ++I) |
| 12155 | Vars.push_back(Record.readSubExpr()); |
| 12156 | C->setRHSExprs(Vars); |
| 12157 | Vars.clear(); |
| 12158 | for (unsigned I = 0; I != NumVars; ++I) |
| 12159 | Vars.push_back(Record.readSubExpr()); |
| 12160 | C->setReductionOps(Vars); |
| 12161 | } |
| 12162 | |
| 12163 | void OMPClauseReader::VisitOMPInReductionClause(OMPInReductionClause *C) { |
| 12164 | VisitOMPClauseWithPostUpdate(C); |
| 12165 | C->setLParenLoc(Record.readSourceLocation()); |
| 12166 | C->setColonLoc(Record.readSourceLocation()); |
| 12167 | NestedNameSpecifierLoc NNSL = Record.readNestedNameSpecifierLoc(); |
| 12168 | DeclarationNameInfo DNI; |
| 12169 | Record.readDeclarationNameInfo(DNI); |
| 12170 | C->setQualifierLoc(NNSL); |
| 12171 | C->setNameInfo(DNI); |
| 12172 | |
| 12173 | unsigned NumVars = C->varlist_size(); |
| 12174 | SmallVector<Expr *, 16> Vars; |
| 12175 | Vars.reserve(NumVars); |
| 12176 | for (unsigned I = 0; I != NumVars; ++I) |
| 12177 | Vars.push_back(Record.readSubExpr()); |
| 12178 | C->setVarRefs(Vars); |
| 12179 | Vars.clear(); |
| 12180 | for (unsigned I = 0; I != NumVars; ++I) |
| 12181 | Vars.push_back(Record.readSubExpr()); |
| 12182 | C->setPrivates(Vars); |
| 12183 | Vars.clear(); |
| 12184 | for (unsigned I = 0; I != NumVars; ++I) |
| 12185 | Vars.push_back(Record.readSubExpr()); |
| 12186 | C->setLHSExprs(Vars); |
| 12187 | Vars.clear(); |
| 12188 | for (unsigned I = 0; I != NumVars; ++I) |
| 12189 | Vars.push_back(Record.readSubExpr()); |
| 12190 | C->setRHSExprs(Vars); |
| 12191 | Vars.clear(); |
| 12192 | for (unsigned I = 0; I != NumVars; ++I) |
| 12193 | Vars.push_back(Record.readSubExpr()); |
| 12194 | C->setReductionOps(Vars); |
| 12195 | Vars.clear(); |
| 12196 | for (unsigned I = 0; I != NumVars; ++I) |
| 12197 | Vars.push_back(Record.readSubExpr()); |
| 12198 | C->setTaskgroupDescriptors(Vars); |
| 12199 | } |
| 12200 | |
| 12201 | void OMPClauseReader::VisitOMPLinearClause(OMPLinearClause *C) { |
| 12202 | VisitOMPClauseWithPostUpdate(C); |
| 12203 | C->setLParenLoc(Record.readSourceLocation()); |
| 12204 | C->setColonLoc(Record.readSourceLocation()); |
| 12205 | C->setModifier(static_cast<OpenMPLinearClauseKind>(Record.readInt())); |
| 12206 | C->setModifierLoc(Record.readSourceLocation()); |
| 12207 | unsigned NumVars = C->varlist_size(); |
| 12208 | SmallVector<Expr *, 16> Vars; |
| 12209 | Vars.reserve(NumVars); |
| 12210 | for (unsigned i = 0; i != NumVars; ++i) |
| 12211 | Vars.push_back(Record.readSubExpr()); |
| 12212 | C->setVarRefs(Vars); |
| 12213 | Vars.clear(); |
| 12214 | for (unsigned i = 0; i != NumVars; ++i) |
| 12215 | Vars.push_back(Record.readSubExpr()); |
| 12216 | C->setPrivates(Vars); |
| 12217 | Vars.clear(); |
| 12218 | for (unsigned i = 0; i != NumVars; ++i) |
| 12219 | Vars.push_back(Record.readSubExpr()); |
| 12220 | C->setInits(Vars); |
| 12221 | Vars.clear(); |
| 12222 | for (unsigned i = 0; i != NumVars; ++i) |
| 12223 | Vars.push_back(Record.readSubExpr()); |
| 12224 | C->setUpdates(Vars); |
| 12225 | Vars.clear(); |
| 12226 | for (unsigned i = 0; i != NumVars; ++i) |
| 12227 | Vars.push_back(Record.readSubExpr()); |
| 12228 | C->setFinals(Vars); |
| 12229 | C->setStep(Record.readSubExpr()); |
| 12230 | C->setCalcStep(Record.readSubExpr()); |
| 12231 | } |
| 12232 | |
| 12233 | void OMPClauseReader::VisitOMPAlignedClause(OMPAlignedClause *C) { |
| 12234 | C->setLParenLoc(Record.readSourceLocation()); |
| 12235 | C->setColonLoc(Record.readSourceLocation()); |
| 12236 | unsigned NumVars = C->varlist_size(); |
| 12237 | SmallVector<Expr *, 16> Vars; |
| 12238 | Vars.reserve(NumVars); |
| 12239 | for (unsigned i = 0; i != NumVars; ++i) |
| 12240 | Vars.push_back(Record.readSubExpr()); |
| 12241 | C->setVarRefs(Vars); |
| 12242 | C->setAlignment(Record.readSubExpr()); |
| 12243 | } |
| 12244 | |
| 12245 | void OMPClauseReader::VisitOMPCopyinClause(OMPCopyinClause *C) { |
| 12246 | C->setLParenLoc(Record.readSourceLocation()); |
| 12247 | unsigned NumVars = C->varlist_size(); |
| 12248 | SmallVector<Expr *, 16> Exprs; |
| 12249 | Exprs.reserve(NumVars); |
| 12250 | for (unsigned i = 0; i != NumVars; ++i) |
| 12251 | Exprs.push_back(Record.readSubExpr()); |
| 12252 | C->setVarRefs(Exprs); |
| 12253 | Exprs.clear(); |
| 12254 | for (unsigned i = 0; i != NumVars; ++i) |
| 12255 | Exprs.push_back(Record.readSubExpr()); |
| 12256 | C->setSourceExprs(Exprs); |
| 12257 | Exprs.clear(); |
| 12258 | for (unsigned i = 0; i != NumVars; ++i) |
| 12259 | Exprs.push_back(Record.readSubExpr()); |
| 12260 | C->setDestinationExprs(Exprs); |
| 12261 | Exprs.clear(); |
| 12262 | for (unsigned i = 0; i != NumVars; ++i) |
| 12263 | Exprs.push_back(Record.readSubExpr()); |
| 12264 | C->setAssignmentOps(Exprs); |
| 12265 | } |
| 12266 | |
| 12267 | void OMPClauseReader::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) { |
| 12268 | C->setLParenLoc(Record.readSourceLocation()); |
| 12269 | unsigned NumVars = C->varlist_size(); |
| 12270 | SmallVector<Expr *, 16> Exprs; |
| 12271 | Exprs.reserve(NumVars); |
| 12272 | for (unsigned i = 0; i != NumVars; ++i) |
| 12273 | Exprs.push_back(Record.readSubExpr()); |
| 12274 | C->setVarRefs(Exprs); |
| 12275 | Exprs.clear(); |
| 12276 | for (unsigned i = 0; i != NumVars; ++i) |
| 12277 | Exprs.push_back(Record.readSubExpr()); |
| 12278 | C->setSourceExprs(Exprs); |
| 12279 | Exprs.clear(); |
| 12280 | for (unsigned i = 0; i != NumVars; ++i) |
| 12281 | Exprs.push_back(Record.readSubExpr()); |
| 12282 | C->setDestinationExprs(Exprs); |
| 12283 | Exprs.clear(); |
| 12284 | for (unsigned i = 0; i != NumVars; ++i) |
| 12285 | Exprs.push_back(Record.readSubExpr()); |
| 12286 | C->setAssignmentOps(Exprs); |
| 12287 | } |
| 12288 | |
| 12289 | void OMPClauseReader::VisitOMPFlushClause(OMPFlushClause *C) { |
| 12290 | C->setLParenLoc(Record.readSourceLocation()); |
| 12291 | unsigned NumVars = C->varlist_size(); |
| 12292 | SmallVector<Expr *, 16> Vars; |
| 12293 | Vars.reserve(NumVars); |
| 12294 | for (unsigned i = 0; i != NumVars; ++i) |
| 12295 | Vars.push_back(Record.readSubExpr()); |
| 12296 | C->setVarRefs(Vars); |
| 12297 | } |
| 12298 | |
| 12299 | void OMPClauseReader::VisitOMPDependClause(OMPDependClause *C) { |
| 12300 | C->setLParenLoc(Record.readSourceLocation()); |
| 12301 | C->setDependencyKind( |
| 12302 | static_cast<OpenMPDependClauseKind>(Record.readInt())); |
| 12303 | C->setDependencyLoc(Record.readSourceLocation()); |
| 12304 | C->setColonLoc(Record.readSourceLocation()); |
| 12305 | unsigned NumVars = C->varlist_size(); |
| 12306 | SmallVector<Expr *, 16> Vars; |
| 12307 | Vars.reserve(NumVars); |
| 12308 | for (unsigned I = 0; I != NumVars; ++I) |
| 12309 | Vars.push_back(Record.readSubExpr()); |
| 12310 | C->setVarRefs(Vars); |
| 12311 | for (unsigned I = 0, E = C->getNumLoops(); I < E; ++I) |
| 12312 | C->setLoopData(I, Record.readSubExpr()); |
| 12313 | } |
| 12314 | |
| 12315 | void OMPClauseReader::VisitOMPDeviceClause(OMPDeviceClause *C) { |
| 12316 | VisitOMPClauseWithPreInit(C); |
| 12317 | C->setDevice(Record.readSubExpr()); |
| 12318 | C->setLParenLoc(Record.readSourceLocation()); |
| 12319 | } |
| 12320 | |
| 12321 | void OMPClauseReader::VisitOMPMapClause(OMPMapClause *C) { |
| 12322 | C->setLParenLoc(Record.readSourceLocation()); |
| Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 12323 | for (unsigned I = 0; I < OMPMapClause::NumberOfModifiers; ++I) { |
| 12324 | C->setMapTypeModifier( |
| 12325 | I, static_cast<OpenMPMapModifierKind>(Record.readInt())); |
| 12326 | C->setMapTypeModifierLoc(I, Record.readSourceLocation()); |
| 12327 | } |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 12328 | C->setMapperQualifierLoc(Record.readNestedNameSpecifierLoc()); |
| 12329 | DeclarationNameInfo DNI; |
| 12330 | Record.readDeclarationNameInfo(DNI); |
| 12331 | C->setMapperIdInfo(DNI); |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 12332 | C->setMapType( |
| 12333 | static_cast<OpenMPMapClauseKind>(Record.readInt())); |
| 12334 | C->setMapLoc(Record.readSourceLocation()); |
| 12335 | C->setColonLoc(Record.readSourceLocation()); |
| 12336 | auto NumVars = C->varlist_size(); |
| 12337 | auto UniqueDecls = C->getUniqueDeclarationsNum(); |
| 12338 | auto TotalLists = C->getTotalComponentListNum(); |
| 12339 | auto TotalComponents = C->getTotalComponentsNum(); |
| 12340 | |
| 12341 | SmallVector<Expr *, 16> Vars; |
| 12342 | Vars.reserve(NumVars); |
| 12343 | for (unsigned i = 0; i != NumVars; ++i) |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 12344 | Vars.push_back(Record.readExpr()); |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 12345 | C->setVarRefs(Vars); |
| 12346 | |
| Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 12347 | SmallVector<Expr *, 16> UDMappers; |
| 12348 | UDMappers.reserve(NumVars); |
| 12349 | for (unsigned I = 0; I < NumVars; ++I) |
| 12350 | UDMappers.push_back(Record.readExpr()); |
| 12351 | C->setUDMapperRefs(UDMappers); |
| 12352 | |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 12353 | SmallVector<ValueDecl *, 16> Decls; |
| 12354 | Decls.reserve(UniqueDecls); |
| 12355 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12356 | Decls.push_back(Record.readDeclAs<ValueDecl>()); |
| 12357 | C->setUniqueDecls(Decls); |
| 12358 | |
| 12359 | SmallVector<unsigned, 16> ListsPerDecl; |
| 12360 | ListsPerDecl.reserve(UniqueDecls); |
| 12361 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12362 | ListsPerDecl.push_back(Record.readInt()); |
| 12363 | C->setDeclNumLists(ListsPerDecl); |
| 12364 | |
| 12365 | SmallVector<unsigned, 32> ListSizes; |
| 12366 | ListSizes.reserve(TotalLists); |
| 12367 | for (unsigned i = 0; i < TotalLists; ++i) |
| 12368 | ListSizes.push_back(Record.readInt()); |
| 12369 | C->setComponentListSizes(ListSizes); |
| 12370 | |
| 12371 | SmallVector<OMPClauseMappableExprCommon::MappableComponent, 32> Components; |
| 12372 | Components.reserve(TotalComponents); |
| 12373 | for (unsigned i = 0; i < TotalComponents; ++i) { |
| Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 12374 | Expr *AssociatedExpr = Record.readExpr(); |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 12375 | auto *AssociatedDecl = Record.readDeclAs<ValueDecl>(); |
| 12376 | Components.push_back(OMPClauseMappableExprCommon::MappableComponent( |
| 12377 | AssociatedExpr, AssociatedDecl)); |
| 12378 | } |
| 12379 | C->setComponents(Components, ListSizes); |
| 12380 | } |
| 12381 | |
| 12382 | void OMPClauseReader::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) { |
| 12383 | VisitOMPClauseWithPreInit(C); |
| 12384 | C->setNumTeams(Record.readSubExpr()); |
| 12385 | C->setLParenLoc(Record.readSourceLocation()); |
| 12386 | } |
| 12387 | |
| 12388 | void OMPClauseReader::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) { |
| 12389 | VisitOMPClauseWithPreInit(C); |
| 12390 | C->setThreadLimit(Record.readSubExpr()); |
| 12391 | C->setLParenLoc(Record.readSourceLocation()); |
| 12392 | } |
| 12393 | |
| 12394 | void OMPClauseReader::VisitOMPPriorityClause(OMPPriorityClause *C) { |
| 12395 | C->setPriority(Record.readSubExpr()); |
| 12396 | C->setLParenLoc(Record.readSourceLocation()); |
| 12397 | } |
| 12398 | |
| 12399 | void OMPClauseReader::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) { |
| 12400 | C->setGrainsize(Record.readSubExpr()); |
| 12401 | C->setLParenLoc(Record.readSourceLocation()); |
| 12402 | } |
| 12403 | |
| 12404 | void OMPClauseReader::VisitOMPNumTasksClause(OMPNumTasksClause *C) { |
| 12405 | C->setNumTasks(Record.readSubExpr()); |
| 12406 | C->setLParenLoc(Record.readSourceLocation()); |
| 12407 | } |
| 12408 | |
| 12409 | void OMPClauseReader::VisitOMPHintClause(OMPHintClause *C) { |
| 12410 | C->setHint(Record.readSubExpr()); |
| 12411 | C->setLParenLoc(Record.readSourceLocation()); |
| 12412 | } |
| 12413 | |
| 12414 | void OMPClauseReader::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) { |
| 12415 | VisitOMPClauseWithPreInit(C); |
| 12416 | C->setDistScheduleKind( |
| 12417 | static_cast<OpenMPDistScheduleClauseKind>(Record.readInt())); |
| 12418 | C->setChunkSize(Record.readSubExpr()); |
| 12419 | C->setLParenLoc(Record.readSourceLocation()); |
| 12420 | C->setDistScheduleKindLoc(Record.readSourceLocation()); |
| 12421 | C->setCommaLoc(Record.readSourceLocation()); |
| 12422 | } |
| 12423 | |
| 12424 | void OMPClauseReader::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) { |
| 12425 | C->setDefaultmapKind( |
| 12426 | static_cast<OpenMPDefaultmapClauseKind>(Record.readInt())); |
| 12427 | C->setDefaultmapModifier( |
| 12428 | static_cast<OpenMPDefaultmapClauseModifier>(Record.readInt())); |
| 12429 | C->setLParenLoc(Record.readSourceLocation()); |
| 12430 | C->setDefaultmapModifierLoc(Record.readSourceLocation()); |
| 12431 | C->setDefaultmapKindLoc(Record.readSourceLocation()); |
| 12432 | } |
| 12433 | |
| 12434 | void OMPClauseReader::VisitOMPToClause(OMPToClause *C) { |
| 12435 | C->setLParenLoc(Record.readSourceLocation()); |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 12436 | C->setMapperQualifierLoc(Record.readNestedNameSpecifierLoc()); |
| 12437 | DeclarationNameInfo DNI; |
| 12438 | Record.readDeclarationNameInfo(DNI); |
| 12439 | C->setMapperIdInfo(DNI); |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 12440 | auto NumVars = C->varlist_size(); |
| 12441 | auto UniqueDecls = C->getUniqueDeclarationsNum(); |
| 12442 | auto TotalLists = C->getTotalComponentListNum(); |
| 12443 | auto TotalComponents = C->getTotalComponentsNum(); |
| 12444 | |
| 12445 | SmallVector<Expr *, 16> Vars; |
| 12446 | Vars.reserve(NumVars); |
| 12447 | for (unsigned i = 0; i != NumVars; ++i) |
| 12448 | Vars.push_back(Record.readSubExpr()); |
| 12449 | C->setVarRefs(Vars); |
| 12450 | |
| Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 12451 | SmallVector<Expr *, 16> UDMappers; |
| 12452 | UDMappers.reserve(NumVars); |
| 12453 | for (unsigned I = 0; I < NumVars; ++I) |
| 12454 | UDMappers.push_back(Record.readSubExpr()); |
| 12455 | C->setUDMapperRefs(UDMappers); |
| 12456 | |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 12457 | SmallVector<ValueDecl *, 16> Decls; |
| 12458 | Decls.reserve(UniqueDecls); |
| 12459 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12460 | Decls.push_back(Record.readDeclAs<ValueDecl>()); |
| 12461 | C->setUniqueDecls(Decls); |
| 12462 | |
| 12463 | SmallVector<unsigned, 16> ListsPerDecl; |
| 12464 | ListsPerDecl.reserve(UniqueDecls); |
| 12465 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12466 | ListsPerDecl.push_back(Record.readInt()); |
| 12467 | C->setDeclNumLists(ListsPerDecl); |
| 12468 | |
| 12469 | SmallVector<unsigned, 32> ListSizes; |
| 12470 | ListSizes.reserve(TotalLists); |
| 12471 | for (unsigned i = 0; i < TotalLists; ++i) |
| 12472 | ListSizes.push_back(Record.readInt()); |
| 12473 | C->setComponentListSizes(ListSizes); |
| 12474 | |
| 12475 | SmallVector<OMPClauseMappableExprCommon::MappableComponent, 32> Components; |
| 12476 | Components.reserve(TotalComponents); |
| 12477 | for (unsigned i = 0; i < TotalComponents; ++i) { |
| 12478 | Expr *AssociatedExpr = Record.readSubExpr(); |
| 12479 | auto *AssociatedDecl = Record.readDeclAs<ValueDecl>(); |
| 12480 | Components.push_back(OMPClauseMappableExprCommon::MappableComponent( |
| 12481 | AssociatedExpr, AssociatedDecl)); |
| 12482 | } |
| 12483 | C->setComponents(Components, ListSizes); |
| 12484 | } |
| 12485 | |
| 12486 | void OMPClauseReader::VisitOMPFromClause(OMPFromClause *C) { |
| 12487 | C->setLParenLoc(Record.readSourceLocation()); |
| Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 12488 | C->setMapperQualifierLoc(Record.readNestedNameSpecifierLoc()); |
| 12489 | DeclarationNameInfo DNI; |
| 12490 | Record.readDeclarationNameInfo(DNI); |
| 12491 | C->setMapperIdInfo(DNI); |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 12492 | auto NumVars = C->varlist_size(); |
| 12493 | auto UniqueDecls = C->getUniqueDeclarationsNum(); |
| 12494 | auto TotalLists = C->getTotalComponentListNum(); |
| 12495 | auto TotalComponents = C->getTotalComponentsNum(); |
| 12496 | |
| 12497 | SmallVector<Expr *, 16> Vars; |
| 12498 | Vars.reserve(NumVars); |
| 12499 | for (unsigned i = 0; i != NumVars; ++i) |
| 12500 | Vars.push_back(Record.readSubExpr()); |
| 12501 | C->setVarRefs(Vars); |
| 12502 | |
| Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 12503 | SmallVector<Expr *, 16> UDMappers; |
| 12504 | UDMappers.reserve(NumVars); |
| 12505 | for (unsigned I = 0; I < NumVars; ++I) |
| 12506 | UDMappers.push_back(Record.readSubExpr()); |
| 12507 | C->setUDMapperRefs(UDMappers); |
| 12508 | |
| Kelvin Li | be286f5 | 2018-09-15 13:54:15 +0000 | [diff] [blame] | 12509 | SmallVector<ValueDecl *, 16> Decls; |
| 12510 | Decls.reserve(UniqueDecls); |
| 12511 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12512 | Decls.push_back(Record.readDeclAs<ValueDecl>()); |
| 12513 | C->setUniqueDecls(Decls); |
| 12514 | |
| 12515 | SmallVector<unsigned, 16> ListsPerDecl; |
| 12516 | ListsPerDecl.reserve(UniqueDecls); |
| 12517 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12518 | ListsPerDecl.push_back(Record.readInt()); |
| 12519 | C->setDeclNumLists(ListsPerDecl); |
| 12520 | |
| 12521 | SmallVector<unsigned, 32> ListSizes; |
| 12522 | ListSizes.reserve(TotalLists); |
| 12523 | for (unsigned i = 0; i < TotalLists; ++i) |
| 12524 | ListSizes.push_back(Record.readInt()); |
| 12525 | C->setComponentListSizes(ListSizes); |
| 12526 | |
| 12527 | SmallVector<OMPClauseMappableExprCommon::MappableComponent, 32> Components; |
| 12528 | Components.reserve(TotalComponents); |
| 12529 | for (unsigned i = 0; i < TotalComponents; ++i) { |
| 12530 | Expr *AssociatedExpr = Record.readSubExpr(); |
| 12531 | auto *AssociatedDecl = Record.readDeclAs<ValueDecl>(); |
| 12532 | Components.push_back(OMPClauseMappableExprCommon::MappableComponent( |
| 12533 | AssociatedExpr, AssociatedDecl)); |
| 12534 | } |
| 12535 | C->setComponents(Components, ListSizes); |
| 12536 | } |
| 12537 | |
| 12538 | void OMPClauseReader::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) { |
| 12539 | C->setLParenLoc(Record.readSourceLocation()); |
| 12540 | auto NumVars = C->varlist_size(); |
| 12541 | auto UniqueDecls = C->getUniqueDeclarationsNum(); |
| 12542 | auto TotalLists = C->getTotalComponentListNum(); |
| 12543 | auto TotalComponents = C->getTotalComponentsNum(); |
| 12544 | |
| 12545 | SmallVector<Expr *, 16> Vars; |
| 12546 | Vars.reserve(NumVars); |
| 12547 | for (unsigned i = 0; i != NumVars; ++i) |
| 12548 | Vars.push_back(Record.readSubExpr()); |
| 12549 | C->setVarRefs(Vars); |
| 12550 | Vars.clear(); |
| 12551 | for (unsigned i = 0; i != NumVars; ++i) |
| 12552 | Vars.push_back(Record.readSubExpr()); |
| 12553 | C->setPrivateCopies(Vars); |
| 12554 | Vars.clear(); |
| 12555 | for (unsigned i = 0; i != NumVars; ++i) |
| 12556 | Vars.push_back(Record.readSubExpr()); |
| 12557 | C->setInits(Vars); |
| 12558 | |
| 12559 | SmallVector<ValueDecl *, 16> Decls; |
| 12560 | Decls.reserve(UniqueDecls); |
| 12561 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12562 | Decls.push_back(Record.readDeclAs<ValueDecl>()); |
| 12563 | C->setUniqueDecls(Decls); |
| 12564 | |
| 12565 | SmallVector<unsigned, 16> ListsPerDecl; |
| 12566 | ListsPerDecl.reserve(UniqueDecls); |
| 12567 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12568 | ListsPerDecl.push_back(Record.readInt()); |
| 12569 | C->setDeclNumLists(ListsPerDecl); |
| 12570 | |
| 12571 | SmallVector<unsigned, 32> ListSizes; |
| 12572 | ListSizes.reserve(TotalLists); |
| 12573 | for (unsigned i = 0; i < TotalLists; ++i) |
| 12574 | ListSizes.push_back(Record.readInt()); |
| 12575 | C->setComponentListSizes(ListSizes); |
| 12576 | |
| 12577 | SmallVector<OMPClauseMappableExprCommon::MappableComponent, 32> Components; |
| 12578 | Components.reserve(TotalComponents); |
| 12579 | for (unsigned i = 0; i < TotalComponents; ++i) { |
| 12580 | Expr *AssociatedExpr = Record.readSubExpr(); |
| 12581 | auto *AssociatedDecl = Record.readDeclAs<ValueDecl>(); |
| 12582 | Components.push_back(OMPClauseMappableExprCommon::MappableComponent( |
| 12583 | AssociatedExpr, AssociatedDecl)); |
| 12584 | } |
| 12585 | C->setComponents(Components, ListSizes); |
| 12586 | } |
| 12587 | |
| 12588 | void OMPClauseReader::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) { |
| 12589 | C->setLParenLoc(Record.readSourceLocation()); |
| 12590 | auto NumVars = C->varlist_size(); |
| 12591 | auto UniqueDecls = C->getUniqueDeclarationsNum(); |
| 12592 | auto TotalLists = C->getTotalComponentListNum(); |
| 12593 | auto TotalComponents = C->getTotalComponentsNum(); |
| 12594 | |
| 12595 | SmallVector<Expr *, 16> Vars; |
| 12596 | Vars.reserve(NumVars); |
| 12597 | for (unsigned i = 0; i != NumVars; ++i) |
| 12598 | Vars.push_back(Record.readSubExpr()); |
| 12599 | C->setVarRefs(Vars); |
| 12600 | Vars.clear(); |
| 12601 | |
| 12602 | SmallVector<ValueDecl *, 16> Decls; |
| 12603 | Decls.reserve(UniqueDecls); |
| 12604 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12605 | Decls.push_back(Record.readDeclAs<ValueDecl>()); |
| 12606 | C->setUniqueDecls(Decls); |
| 12607 | |
| 12608 | SmallVector<unsigned, 16> ListsPerDecl; |
| 12609 | ListsPerDecl.reserve(UniqueDecls); |
| 12610 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12611 | ListsPerDecl.push_back(Record.readInt()); |
| 12612 | C->setDeclNumLists(ListsPerDecl); |
| 12613 | |
| 12614 | SmallVector<unsigned, 32> ListSizes; |
| 12615 | ListSizes.reserve(TotalLists); |
| 12616 | for (unsigned i = 0; i < TotalLists; ++i) |
| 12617 | ListSizes.push_back(Record.readInt()); |
| 12618 | C->setComponentListSizes(ListSizes); |
| 12619 | |
| 12620 | SmallVector<OMPClauseMappableExprCommon::MappableComponent, 32> Components; |
| 12621 | Components.reserve(TotalComponents); |
| 12622 | for (unsigned i = 0; i < TotalComponents; ++i) { |
| 12623 | Expr *AssociatedExpr = Record.readSubExpr(); |
| 12624 | auto *AssociatedDecl = Record.readDeclAs<ValueDecl>(); |
| 12625 | Components.push_back(OMPClauseMappableExprCommon::MappableComponent( |
| 12626 | AssociatedExpr, AssociatedDecl)); |
| 12627 | } |
| 12628 | C->setComponents(Components, ListSizes); |
| 12629 | } |