clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ASTReader.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangSerialization/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/libclangSerialization/../../../llvm/clang/include -I /usr/src/gnu/usr.bin/clang/libclangSerialization/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/libclangSerialization/../include -I /usr/src/gnu/usr.bin/clang/libclangSerialization/obj -I /usr/src/gnu/usr.bin/clang/libclangSerialization/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/libclangSerialization/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -stack-protector 2 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c++ /usr/src/gnu/usr.bin/clang/libclangSerialization/../../../llvm/clang/lib/Serialization/ASTReader.cpp
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | #include "clang/Basic/OpenMPKinds.h" |
| 14 | #include "clang/Serialization/ASTRecordReader.h" |
| 15 | #include "ASTCommon.h" |
| 16 | #include "ASTReaderInternals.h" |
| 17 | #include "clang/AST/AbstractTypeReader.h" |
| 18 | #include "clang/AST/ASTConsumer.h" |
| 19 | #include "clang/AST/ASTContext.h" |
| 20 | #include "clang/AST/ASTMutationListener.h" |
| 21 | #include "clang/AST/ASTUnresolvedSet.h" |
| 22 | #include "clang/AST/Decl.h" |
| 23 | #include "clang/AST/DeclBase.h" |
| 24 | #include "clang/AST/DeclCXX.h" |
| 25 | #include "clang/AST/DeclFriend.h" |
| 26 | #include "clang/AST/DeclGroup.h" |
| 27 | #include "clang/AST/DeclObjC.h" |
| 28 | #include "clang/AST/DeclTemplate.h" |
| 29 | #include "clang/AST/DeclarationName.h" |
| 30 | #include "clang/AST/Expr.h" |
| 31 | #include "clang/AST/ExprCXX.h" |
| 32 | #include "clang/AST/ExternalASTSource.h" |
| 33 | #include "clang/AST/NestedNameSpecifier.h" |
| 34 | #include "clang/AST/OpenMPClause.h" |
| 35 | #include "clang/AST/ODRHash.h" |
| 36 | #include "clang/AST/RawCommentList.h" |
| 37 | #include "clang/AST/TemplateBase.h" |
| 38 | #include "clang/AST/TemplateName.h" |
| 39 | #include "clang/AST/Type.h" |
| 40 | #include "clang/AST/TypeLoc.h" |
| 41 | #include "clang/AST/TypeLocVisitor.h" |
| 42 | #include "clang/AST/UnresolvedSet.h" |
| 43 | #include "clang/Basic/CommentOptions.h" |
| 44 | #include "clang/Basic/Diagnostic.h" |
| 45 | #include "clang/Basic/DiagnosticOptions.h" |
| 46 | #include "clang/Basic/ExceptionSpecificationType.h" |
| 47 | #include "clang/Basic/FileManager.h" |
| 48 | #include "clang/Basic/FileSystemOptions.h" |
| 49 | #include "clang/Basic/IdentifierTable.h" |
| 50 | #include "clang/Basic/LLVM.h" |
| 51 | #include "clang/Basic/LangOptions.h" |
| 52 | #include "clang/Basic/Module.h" |
| 53 | #include "clang/Basic/ObjCRuntime.h" |
| 54 | #include "clang/Basic/OperatorKinds.h" |
| 55 | #include "clang/Basic/PragmaKinds.h" |
| 56 | #include "clang/Basic/Sanitizers.h" |
| 57 | #include "clang/Basic/SourceLocation.h" |
| 58 | #include "clang/Basic/SourceManager.h" |
| 59 | #include "clang/Basic/SourceManagerInternals.h" |
| 60 | #include "clang/Basic/Specifiers.h" |
| 61 | #include "clang/Basic/TargetInfo.h" |
| 62 | #include "clang/Basic/TargetOptions.h" |
| 63 | #include "clang/Basic/TokenKinds.h" |
| 64 | #include "clang/Basic/Version.h" |
| 65 | #include "clang/Lex/HeaderSearch.h" |
| 66 | #include "clang/Lex/HeaderSearchOptions.h" |
| 67 | #include "clang/Lex/MacroInfo.h" |
| 68 | #include "clang/Lex/ModuleMap.h" |
| 69 | #include "clang/Lex/PreprocessingRecord.h" |
| 70 | #include "clang/Lex/Preprocessor.h" |
| 71 | #include "clang/Lex/PreprocessorOptions.h" |
| 72 | #include "clang/Lex/Token.h" |
| 73 | #include "clang/Sema/ObjCMethodList.h" |
| 74 | #include "clang/Sema/Scope.h" |
| 75 | #include "clang/Sema/Sema.h" |
| 76 | #include "clang/Sema/Weak.h" |
| 77 | #include "clang/Serialization/ASTBitCodes.h" |
| 78 | #include "clang/Serialization/ASTDeserializationListener.h" |
| 79 | #include "clang/Serialization/ContinuousRangeMap.h" |
| 80 | #include "clang/Serialization/GlobalModuleIndex.h" |
| 81 | #include "clang/Serialization/InMemoryModuleCache.h" |
| 82 | #include "clang/Serialization/ModuleFile.h" |
| 83 | #include "clang/Serialization/ModuleFileExtension.h" |
| 84 | #include "clang/Serialization/ModuleManager.h" |
| 85 | #include "clang/Serialization/PCHContainerOperations.h" |
| 86 | #include "clang/Serialization/SerializationDiagnostic.h" |
| 87 | #include "llvm/ADT/APFloat.h" |
| 88 | #include "llvm/ADT/APInt.h" |
| 89 | #include "llvm/ADT/APSInt.h" |
| 90 | #include "llvm/ADT/ArrayRef.h" |
| 91 | #include "llvm/ADT/DenseMap.h" |
| 92 | #include "llvm/ADT/FloatingPointMode.h" |
| 93 | #include "llvm/ADT/FoldingSet.h" |
| 94 | #include "llvm/ADT/Hashing.h" |
| 95 | #include "llvm/ADT/IntrusiveRefCntPtr.h" |
| 96 | #include "llvm/ADT/None.h" |
| 97 | #include "llvm/ADT/Optional.h" |
| 98 | #include "llvm/ADT/STLExtras.h" |
| 99 | #include "llvm/ADT/ScopeExit.h" |
| 100 | #include "llvm/ADT/SmallPtrSet.h" |
| 101 | #include "llvm/ADT/SmallString.h" |
| 102 | #include "llvm/ADT/SmallVector.h" |
| 103 | #include "llvm/ADT/StringExtras.h" |
| 104 | #include "llvm/ADT/StringMap.h" |
| 105 | #include "llvm/ADT/StringRef.h" |
| 106 | #include "llvm/ADT/Triple.h" |
| 107 | #include "llvm/ADT/iterator_range.h" |
| 108 | #include "llvm/Bitstream/BitstreamReader.h" |
| 109 | #include "llvm/Support/Casting.h" |
| 110 | #include "llvm/Support/Compiler.h" |
| 111 | #include "llvm/Support/Compression.h" |
| 112 | #include "llvm/Support/DJB.h" |
| 113 | #include "llvm/Support/Endian.h" |
| 114 | #include "llvm/Support/Error.h" |
| 115 | #include "llvm/Support/ErrorHandling.h" |
| 116 | #include "llvm/Support/FileSystem.h" |
| 117 | #include "llvm/Support/LEB128.h" |
| 118 | #include "llvm/Support/MemoryBuffer.h" |
| 119 | #include "llvm/Support/Path.h" |
| 120 | #include "llvm/Support/SaveAndRestore.h" |
| 121 | #include "llvm/Support/Timer.h" |
| 122 | #include "llvm/Support/VersionTuple.h" |
| 123 | #include "llvm/Support/raw_ostream.h" |
| 124 | #include <algorithm> |
| 125 | #include <cassert> |
| 126 | #include <cstddef> |
| 127 | #include <cstdint> |
| 128 | #include <cstdio> |
| 129 | #include <ctime> |
| 130 | #include <iterator> |
| 131 | #include <limits> |
| 132 | #include <map> |
| 133 | #include <memory> |
| 134 | #include <string> |
| 135 | #include <system_error> |
| 136 | #include <tuple> |
| 137 | #include <utility> |
| 138 | #include <vector> |
| 139 | |
| 140 | using namespace clang; |
| 141 | using namespace clang::serialization; |
| 142 | using namespace clang::serialization::reader; |
| 143 | using llvm::BitstreamCursor; |
| 144 | using llvm::RoundingMode; |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | bool |
| 151 | ChainedASTReaderListener::ReadFullVersionInformation(StringRef FullVersion) { |
| 152 | return First->ReadFullVersionInformation(FullVersion) || |
| 153 | Second->ReadFullVersionInformation(FullVersion); |
| 154 | } |
| 155 | |
| 156 | void ChainedASTReaderListener::ReadModuleName(StringRef ModuleName) { |
| 157 | First->ReadModuleName(ModuleName); |
| 158 | Second->ReadModuleName(ModuleName); |
| 159 | } |
| 160 | |
| 161 | void ChainedASTReaderListener::ReadModuleMapFile(StringRef ModuleMapPath) { |
| 162 | First->ReadModuleMapFile(ModuleMapPath); |
| 163 | Second->ReadModuleMapFile(ModuleMapPath); |
| 164 | } |
| 165 | |
| 166 | bool |
| 167 | ChainedASTReaderListener::ReadLanguageOptions(const LangOptions &LangOpts, |
| 168 | bool Complain, |
| 169 | bool AllowCompatibleDifferences) { |
| 170 | return First->ReadLanguageOptions(LangOpts, Complain, |
| 171 | AllowCompatibleDifferences) || |
| 172 | Second->ReadLanguageOptions(LangOpts, Complain, |
| 173 | AllowCompatibleDifferences); |
| 174 | } |
| 175 | |
| 176 | bool ChainedASTReaderListener::ReadTargetOptions( |
| 177 | const TargetOptions &TargetOpts, bool Complain, |
| 178 | bool AllowCompatibleDifferences) { |
| 179 | return First->ReadTargetOptions(TargetOpts, Complain, |
| 180 | AllowCompatibleDifferences) || |
| 181 | Second->ReadTargetOptions(TargetOpts, Complain, |
| 182 | AllowCompatibleDifferences); |
| 183 | } |
| 184 | |
| 185 | bool ChainedASTReaderListener::ReadDiagnosticOptions( |
| 186 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) { |
| 187 | return First->ReadDiagnosticOptions(DiagOpts, Complain) || |
| 188 | Second->ReadDiagnosticOptions(DiagOpts, Complain); |
| 189 | } |
| 190 | |
| 191 | bool |
| 192 | ChainedASTReaderListener::ReadFileSystemOptions(const FileSystemOptions &FSOpts, |
| 193 | bool Complain) { |
| 194 | return First->ReadFileSystemOptions(FSOpts, Complain) || |
| 195 | Second->ReadFileSystemOptions(FSOpts, Complain); |
| 196 | } |
| 197 | |
| 198 | bool ChainedASTReaderListener::ReadHeaderSearchOptions( |
| 199 | const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, |
| 200 | bool Complain) { |
| 201 | return First->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 202 | Complain) || |
| 203 | Second->ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 204 | Complain); |
| 205 | } |
| 206 | |
| 207 | bool ChainedASTReaderListener::ReadPreprocessorOptions( |
| 208 | const PreprocessorOptions &PPOpts, bool Complain, |
| 209 | std::string &SuggestedPredefines) { |
| 210 | return First->ReadPreprocessorOptions(PPOpts, Complain, |
| 211 | SuggestedPredefines) || |
| 212 | Second->ReadPreprocessorOptions(PPOpts, Complain, SuggestedPredefines); |
| 213 | } |
| 214 | |
| 215 | void ChainedASTReaderListener::ReadCounter(const serialization::ModuleFile &M, |
| 216 | unsigned Value) { |
| 217 | First->ReadCounter(M, Value); |
| 218 | Second->ReadCounter(M, Value); |
| 219 | } |
| 220 | |
| 221 | bool ChainedASTReaderListener::needsInputFileVisitation() { |
| 222 | return First->needsInputFileVisitation() || |
| 223 | Second->needsInputFileVisitation(); |
| 224 | } |
| 225 | |
| 226 | bool ChainedASTReaderListener::needsSystemInputFileVisitation() { |
| 227 | return First->needsSystemInputFileVisitation() || |
| 228 | Second->needsSystemInputFileVisitation(); |
| 229 | } |
| 230 | |
| 231 | void ChainedASTReaderListener::visitModuleFile(StringRef Filename, |
| 232 | ModuleKind Kind) { |
| 233 | First->visitModuleFile(Filename, Kind); |
| 234 | Second->visitModuleFile(Filename, Kind); |
| 235 | } |
| 236 | |
| 237 | bool ChainedASTReaderListener::visitInputFile(StringRef Filename, |
| 238 | bool isSystem, |
| 239 | bool isOverridden, |
| 240 | bool isExplicitModule) { |
| 241 | bool Continue = false; |
| 242 | if (First->needsInputFileVisitation() && |
| 243 | (!isSystem || First->needsSystemInputFileVisitation())) |
| 244 | Continue |= First->visitInputFile(Filename, isSystem, isOverridden, |
| 245 | isExplicitModule); |
| 246 | if (Second->needsInputFileVisitation() && |
| 247 | (!isSystem || Second->needsSystemInputFileVisitation())) |
| 248 | Continue |= Second->visitInputFile(Filename, isSystem, isOverridden, |
| 249 | isExplicitModule); |
| 250 | return Continue; |
| 251 | } |
| 252 | |
| 253 | void ChainedASTReaderListener::readModuleFileExtension( |
| 254 | const ModuleFileExtensionMetadata &Metadata) { |
| 255 | First->readModuleFileExtension(Metadata); |
| 256 | Second->readModuleFileExtension(Metadata); |
| 257 | } |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | ASTReaderListener::~ASTReaderListener() = default; |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | static bool checkLanguageOptions(const LangOptions &LangOpts, |
| 274 | const LangOptions &ExistingLangOpts, |
| 275 | DiagnosticsEngine *Diags, |
| 276 | bool AllowCompatibleDifferences = true) { |
| 277 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 278 | if (ExistingLangOpts.Name != LangOpts.Name) { \ |
| 279 | if (Diags) \ |
| 280 | Diags->Report(diag::err_pch_langopt_mismatch) \ |
| 281 | << Description << LangOpts.Name << ExistingLangOpts.Name; \ |
| 282 | return true; \ |
| 283 | } |
| 284 | |
| 285 | #define VALUE_LANGOPT(Name, Bits, Default, Description) \ |
| 286 | if (ExistingLangOpts.Name != LangOpts.Name) { \ |
| 287 | if (Diags) \ |
| 288 | Diags->Report(diag::err_pch_langopt_value_mismatch) \ |
| 289 | << Description; \ |
| 290 | return true; \ |
| 291 | } |
| 292 | |
| 293 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 294 | if (ExistingLangOpts.get##Name() != LangOpts.get##Name()) { \ |
| 295 | if (Diags) \ |
| 296 | Diags->Report(diag::err_pch_langopt_value_mismatch) \ |
| 297 | << Description; \ |
| 298 | return true; \ |
| 299 | } |
| 300 | |
| 301 | #define COMPATIBLE_LANGOPT(Name, Bits, Default, Description) \ |
| 302 | if (!AllowCompatibleDifferences) \ |
| 303 | LANGOPT(Name, Bits, Default, Description) |
| 304 | |
| 305 | #define COMPATIBLE_ENUM_LANGOPT(Name, Bits, Default, Description) \ |
| 306 | if (!AllowCompatibleDifferences) \ |
| 307 | ENUM_LANGOPT(Name, Bits, Default, Description) |
| 308 | |
| 309 | #define COMPATIBLE_VALUE_LANGOPT(Name, Bits, Default, Description) \ |
| 310 | if (!AllowCompatibleDifferences) \ |
| 311 | VALUE_LANGOPT(Name, Bits, Default, Description) |
| 312 | |
| 313 | #define BENIGN_LANGOPT(Name, Bits, Default, Description) |
| 314 | #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) |
| 315 | #define BENIGN_VALUE_LANGOPT(Name, Type, Bits, Default, Description) |
| 316 | #include "clang/Basic/LangOptions.def" |
| 317 | |
| 318 | if (ExistingLangOpts.ModuleFeatures != LangOpts.ModuleFeatures) { |
| 319 | if (Diags) |
| 320 | Diags->Report(diag::err_pch_langopt_value_mismatch) << "module features"; |
| 321 | return true; |
| 322 | } |
| 323 | |
| 324 | if (ExistingLangOpts.ObjCRuntime != LangOpts.ObjCRuntime) { |
| 325 | if (Diags) |
| 326 | Diags->Report(diag::err_pch_langopt_value_mismatch) |
| 327 | << "target Objective-C runtime"; |
| 328 | return true; |
| 329 | } |
| 330 | |
| 331 | if (ExistingLangOpts.CommentOpts.BlockCommandNames != |
| 332 | LangOpts.CommentOpts.BlockCommandNames) { |
| 333 | if (Diags) |
| 334 | Diags->Report(diag::err_pch_langopt_value_mismatch) |
| 335 | << "block command names"; |
| 336 | return true; |
| 337 | } |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | if (!AllowCompatibleDifferences) { |
| 344 | SanitizerMask ModularSanitizers = getPPTransparentSanitizers(); |
| 345 | SanitizerSet ExistingSanitizers = ExistingLangOpts.Sanitize; |
| 346 | SanitizerSet ImportedSanitizers = LangOpts.Sanitize; |
| 347 | ExistingSanitizers.clear(ModularSanitizers); |
| 348 | ImportedSanitizers.clear(ModularSanitizers); |
| 349 | if (ExistingSanitizers.Mask != ImportedSanitizers.Mask) { |
| 350 | const std::string Flag = "-fsanitize="; |
| 351 | if (Diags) { |
| 352 | #define SANITIZER(NAME, ID) \ |
| 353 | { \ |
| 354 | bool InExistingModule = ExistingSanitizers.has(SanitizerKind::ID); \ |
| 355 | bool InImportedModule = ImportedSanitizers.has(SanitizerKind::ID); \ |
| 356 | if (InExistingModule != InImportedModule) \ |
| 357 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) \ |
| 358 | << InExistingModule << (Flag + NAME); \ |
| 359 | } |
| 360 | #include "clang/Basic/Sanitizers.def" |
| 361 | } |
| 362 | return true; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | return false; |
| 367 | } |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | static bool checkTargetOptions(const TargetOptions &TargetOpts, |
| 376 | const TargetOptions &ExistingTargetOpts, |
| 377 | DiagnosticsEngine *Diags, |
| 378 | bool AllowCompatibleDifferences = true) { |
| 379 | #define CHECK_TARGET_OPT(Field, Name) \ |
| 380 | if (TargetOpts.Field != ExistingTargetOpts.Field) { \ |
| 381 | if (Diags) \ |
| 382 | Diags->Report(diag::err_pch_targetopt_mismatch) \ |
| 383 | << Name << TargetOpts.Field << ExistingTargetOpts.Field; \ |
| 384 | return true; \ |
| 385 | } |
| 386 | |
| 387 | |
| 388 | CHECK_TARGET_OPT(Triple, "target"); |
| 389 | CHECK_TARGET_OPT(ABI, "target ABI"); |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | if (!AllowCompatibleDifferences) { |
| 395 | CHECK_TARGET_OPT(CPU, "target CPU"); |
| 396 | CHECK_TARGET_OPT(TuneCPU, "tune CPU"); |
| 397 | } |
| 398 | |
| 399 | #undef CHECK_TARGET_OPT |
| 400 | |
| 401 | |
| 402 | SmallVector<StringRef, 4> ExistingFeatures( |
| 403 | ExistingTargetOpts.FeaturesAsWritten.begin(), |
| 404 | ExistingTargetOpts.FeaturesAsWritten.end()); |
| 405 | SmallVector<StringRef, 4> ReadFeatures(TargetOpts.FeaturesAsWritten.begin(), |
| 406 | TargetOpts.FeaturesAsWritten.end()); |
| 407 | llvm::sort(ExistingFeatures); |
| 408 | llvm::sort(ReadFeatures); |
| 409 | |
| 410 | |
| 411 | |
| 412 | SmallVector<StringRef, 4> UnmatchedExistingFeatures, UnmatchedReadFeatures; |
| 413 | std::set_difference( |
| 414 | ExistingFeatures.begin(), ExistingFeatures.end(), ReadFeatures.begin(), |
| 415 | ReadFeatures.end(), std::back_inserter(UnmatchedExistingFeatures)); |
| 416 | std::set_difference(ReadFeatures.begin(), ReadFeatures.end(), |
| 417 | ExistingFeatures.begin(), ExistingFeatures.end(), |
| 418 | std::back_inserter(UnmatchedReadFeatures)); |
| 419 | |
| 420 | |
| 421 | |
| 422 | if (AllowCompatibleDifferences && UnmatchedReadFeatures.empty()) |
| 423 | return false; |
| 424 | |
| 425 | if (Diags) { |
| 426 | for (StringRef Feature : UnmatchedReadFeatures) |
| 427 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
| 428 | << false << Feature; |
| 429 | for (StringRef Feature : UnmatchedExistingFeatures) |
| 430 | Diags->Report(diag::err_pch_targetopt_feature_mismatch) |
| 431 | << true << Feature; |
| 432 | } |
| 433 | |
| 434 | return !UnmatchedReadFeatures.empty() || !UnmatchedExistingFeatures.empty(); |
| 435 | } |
| 436 | |
| 437 | bool |
| 438 | PCHValidator::ReadLanguageOptions(const LangOptions &LangOpts, |
| 439 | bool Complain, |
| 440 | bool AllowCompatibleDifferences) { |
| 441 | const LangOptions &ExistingLangOpts = PP.getLangOpts(); |
| 442 | return checkLanguageOptions(LangOpts, ExistingLangOpts, |
| 443 | Complain ? &Reader.Diags : nullptr, |
| 444 | AllowCompatibleDifferences); |
| 445 | } |
| 446 | |
| 447 | bool PCHValidator::ReadTargetOptions(const TargetOptions &TargetOpts, |
| 448 | bool Complain, |
| 449 | bool AllowCompatibleDifferences) { |
| 450 | const TargetOptions &ExistingTargetOpts = PP.getTargetInfo().getTargetOpts(); |
| 451 | return checkTargetOptions(TargetOpts, ExistingTargetOpts, |
| 452 | Complain ? &Reader.Diags : nullptr, |
| 453 | AllowCompatibleDifferences); |
| 454 | } |
| 455 | |
| 456 | namespace { |
| 457 | |
| 458 | using MacroDefinitionsMap = |
| 459 | llvm::StringMap<std::pair<StringRef, bool >>; |
| 460 | using DeclsMap = llvm::DenseMap<DeclarationName, SmallVector<NamedDecl *, 8>>; |
| 461 | |
| 462 | } |
| 463 | |
| 464 | static bool checkDiagnosticGroupMappings(DiagnosticsEngine &StoredDiags, |
| 465 | DiagnosticsEngine &Diags, |
| 466 | bool Complain) { |
| 467 | using Level = DiagnosticsEngine::Level; |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | DiagnosticsEngine *MappingSources[] = { &Diags, &StoredDiags }; |
| 473 | |
| 474 | for (DiagnosticsEngine *MappingSource : MappingSources) { |
| 475 | for (auto DiagIDMappingPair : MappingSource->getDiagnosticMappings()) { |
| 476 | diag::kind DiagID = DiagIDMappingPair.first; |
| 477 | Level CurLevel = Diags.getDiagnosticLevel(DiagID, SourceLocation()); |
| 478 | if (CurLevel < DiagnosticsEngine::Error) |
| 479 | continue; |
| 480 | Level StoredLevel = |
| 481 | StoredDiags.getDiagnosticLevel(DiagID, SourceLocation()); |
| 482 | if (StoredLevel < DiagnosticsEngine::Error) { |
| 483 | if (Complain) |
| 484 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror=" + |
| 485 | Diags.getDiagnosticIDs()->getWarningOptionForDiag(DiagID).str(); |
| 486 | return true; |
| 487 | } |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | return false; |
| 492 | } |
| 493 | |
| 494 | static bool isExtHandlingFromDiagsError(DiagnosticsEngine &Diags) { |
| 495 | diag::Severity Ext = Diags.getExtensionHandlingBehavior(); |
| 496 | if (Ext == diag::Severity::Warning && Diags.getWarningsAsErrors()) |
| 497 | return true; |
| 498 | return Ext >= diag::Severity::Error; |
| 499 | } |
| 500 | |
| 501 | static bool checkDiagnosticMappings(DiagnosticsEngine &StoredDiags, |
| 502 | DiagnosticsEngine &Diags, |
| 503 | bool IsSystem, bool Complain) { |
| 504 | |
| 505 | if (IsSystem) { |
| 506 | if (Diags.getSuppressSystemWarnings()) |
| 507 | return false; |
| 508 | |
| 509 | if (StoredDiags.getSuppressSystemWarnings()) { |
| 510 | if (Complain) |
| 511 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Wsystem-headers"; |
| 512 | return true; |
| 513 | } |
| 514 | } |
| 515 | |
| 516 | if (Diags.getWarningsAsErrors() && !StoredDiags.getWarningsAsErrors()) { |
| 517 | if (Complain) |
| 518 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Werror"; |
| 519 | return true; |
| 520 | } |
| 521 | |
| 522 | if (Diags.getWarningsAsErrors() && Diags.getEnableAllWarnings() && |
| 523 | !StoredDiags.getEnableAllWarnings()) { |
| 524 | if (Complain) |
| 525 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-Weverything -Werror"; |
| 526 | return true; |
| 527 | } |
| 528 | |
| 529 | if (isExtHandlingFromDiagsError(Diags) && |
| 530 | !isExtHandlingFromDiagsError(StoredDiags)) { |
| 531 | if (Complain) |
| 532 | Diags.Report(diag::err_pch_diagopt_mismatch) << "-pedantic-errors"; |
| 533 | return true; |
| 534 | } |
| 535 | |
| 536 | return checkDiagnosticGroupMappings(StoredDiags, Diags, Complain); |
| 537 | } |
| 538 | |
| 539 | |
| 540 | static Module *getTopImportImplicitModule(ModuleManager &ModuleMgr, |
| 541 | Preprocessor &PP) { |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | |
| 549 | ModuleFile *TopImport = &*ModuleMgr.rbegin(); |
| 550 | while (!TopImport->ImportedBy.empty()) |
| 551 | TopImport = TopImport->ImportedBy[0]; |
| 552 | if (TopImport->Kind != MK_ImplicitModule) |
| 553 | return nullptr; |
| 554 | |
| 555 | StringRef ModuleName = TopImport->ModuleName; |
| 556 | assert(!ModuleName.empty() && "diagnostic options read before module name"); |
| 557 | |
| 558 | Module *M = PP.getHeaderSearchInfo().lookupModule(ModuleName); |
| 559 | assert(M && "missing module"); |
| 560 | return M; |
| 561 | } |
| 562 | |
| 563 | bool PCHValidator::ReadDiagnosticOptions( |
| 564 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts, bool Complain) { |
| 565 | DiagnosticsEngine &ExistingDiags = PP.getDiagnostics(); |
| 566 | IntrusiveRefCntPtr<DiagnosticIDs> DiagIDs(ExistingDiags.getDiagnosticIDs()); |
| 567 | IntrusiveRefCntPtr<DiagnosticsEngine> Diags( |
| 568 | new DiagnosticsEngine(DiagIDs, DiagOpts.get())); |
| 569 | |
| 570 | |
| 571 | ProcessWarningOptions(*Diags, *DiagOpts, false); |
| 572 | |
| 573 | ModuleManager &ModuleMgr = Reader.getModuleManager(); |
| 574 | assert(ModuleMgr.size() >= 1 && "what ASTFile is this then"); |
| 575 | |
| 576 | Module *TopM = getTopImportImplicitModule(ModuleMgr, PP); |
| 577 | if (!TopM) |
| 578 | return false; |
| 579 | |
| 580 | |
| 581 | |
| 582 | return checkDiagnosticMappings(*Diags, ExistingDiags, TopM->IsSystem, |
| 583 | Complain); |
| 584 | } |
| 585 | |
| 586 | |
| 587 | |
| 588 | static void |
| 589 | collectMacroDefinitions(const PreprocessorOptions &PPOpts, |
| 590 | MacroDefinitionsMap &Macros, |
| 591 | SmallVectorImpl<StringRef> *MacroNames = nullptr) { |
| 592 | for (unsigned I = 0, N = PPOpts.Macros.size(); I != N; ++I) { |
| 593 | StringRef Macro = PPOpts.Macros[I].first; |
| 594 | bool IsUndef = PPOpts.Macros[I].second; |
| 595 | |
| 596 | std::pair<StringRef, StringRef> MacroPair = Macro.split('='); |
| 597 | StringRef MacroName = MacroPair.first; |
| 598 | StringRef MacroBody = MacroPair.second; |
| 599 | |
| 600 | |
| 601 | if (IsUndef) { |
| 602 | if (MacroNames && !Macros.count(MacroName)) |
| 603 | MacroNames->push_back(MacroName); |
| 604 | |
| 605 | Macros[MacroName] = std::make_pair("", true); |
| 606 | continue; |
| 607 | } |
| 608 | |
| 609 | |
| 610 | if (MacroName.size() == Macro.size()) |
| 611 | MacroBody = "1"; |
| 612 | else { |
| 613 | |
| 614 | StringRef::size_type End = MacroBody.find_first_of("\n\r"); |
| 615 | MacroBody = MacroBody.substr(0, End); |
| 616 | } |
| 617 | |
| 618 | if (MacroNames && !Macros.count(MacroName)) |
| 619 | MacroNames->push_back(MacroName); |
| 620 | Macros[MacroName] = std::make_pair(MacroBody, false); |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | |
| 628 | |
| 629 | |
| 630 | |
| 631 | static bool checkPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 632 | const PreprocessorOptions &ExistingPPOpts, |
| 633 | DiagnosticsEngine *Diags, |
| 634 | FileManager &FileMgr, |
| 635 | std::string &SuggestedPredefines, |
| 636 | const LangOptions &LangOpts, |
| 637 | bool Validate = true) { |
| 638 | |
| 639 | MacroDefinitionsMap ASTFileMacros; |
| 640 | collectMacroDefinitions(PPOpts, ASTFileMacros); |
| 641 | MacroDefinitionsMap ExistingMacros; |
| 642 | SmallVector<StringRef, 4> ExistingMacroNames; |
| 643 | collectMacroDefinitions(ExistingPPOpts, ExistingMacros, &ExistingMacroNames); |
| 644 | |
| 645 | for (unsigned I = 0, N = ExistingMacroNames.size(); I != N; ++I) { |
| 646 | |
| 647 | StringRef MacroName = ExistingMacroNames[I]; |
| 648 | std::pair<StringRef, bool> Existing = ExistingMacros[MacroName]; |
| 649 | |
| 650 | |
| 651 | llvm::StringMap<std::pair<StringRef, bool >>::iterator Known = |
| 652 | ASTFileMacros.find(MacroName); |
| 653 | if (!Validate || Known == ASTFileMacros.end()) { |
| 654 | |
| 655 | |
| 656 | |
| 657 | |
| 658 | if (Existing.second) { |
| 659 | SuggestedPredefines += "#undef "; |
| 660 | SuggestedPredefines += MacroName.str(); |
| 661 | SuggestedPredefines += '\n'; |
| 662 | } else { |
| 663 | SuggestedPredefines += "#define "; |
| 664 | SuggestedPredefines += MacroName.str(); |
| 665 | SuggestedPredefines += ' '; |
| 666 | SuggestedPredefines += Existing.first.str(); |
| 667 | SuggestedPredefines += '\n'; |
| 668 | } |
| 669 | continue; |
| 670 | } |
| 671 | |
| 672 | |
| 673 | |
| 674 | if (Existing.second != Known->second.second) { |
| 675 | if (Diags) { |
| 676 | Diags->Report(diag::err_pch_macro_def_undef) |
| 677 | << MacroName << Known->second.second; |
| 678 | } |
| 679 | return true; |
| 680 | } |
| 681 | |
| 682 | |
| 683 | |
| 684 | if (Existing.second || Existing.first == Known->second.first) |
| 685 | continue; |
| 686 | |
| 687 | |
| 688 | if (Diags) { |
| 689 | Diags->Report(diag::err_pch_macro_def_conflict) |
| 690 | << MacroName << Known->second.first << Existing.first; |
| 691 | } |
| 692 | return true; |
| 693 | } |
| 694 | |
| 695 | |
| 696 | if (PPOpts.UsePredefines != ExistingPPOpts.UsePredefines && Validate) { |
| 697 | if (Diags) { |
| 698 | Diags->Report(diag::err_pch_undef) << ExistingPPOpts.UsePredefines; |
| 699 | } |
| 700 | return true; |
| 701 | } |
| 702 | |
| 703 | |
| 704 | if (LangOpts.Modules && |
| 705 | PPOpts.DetailedRecord != ExistingPPOpts.DetailedRecord && Validate) { |
| 706 | if (Diags) { |
| 707 | Diags->Report(diag::err_pch_pp_detailed_record) << PPOpts.DetailedRecord; |
| 708 | } |
| 709 | return true; |
| 710 | } |
| 711 | |
| 712 | |
| 713 | for (unsigned I = 0, N = ExistingPPOpts.Includes.size(); I != N; ++I) { |
| 714 | StringRef File = ExistingPPOpts.Includes[I]; |
| 715 | |
| 716 | if (!ExistingPPOpts.ImplicitPCHInclude.empty() && |
| 717 | !ExistingPPOpts.PCHThroughHeader.empty()) { |
| 718 | |
| 719 | |
| 720 | SuggestedPredefines += "#include \""; |
| 721 | SuggestedPredefines += File; |
| 722 | SuggestedPredefines += "\"\n"; |
| 723 | continue; |
| 724 | } |
| 725 | |
| 726 | if (File == ExistingPPOpts.ImplicitPCHInclude) |
| 727 | continue; |
| 728 | |
| 729 | if (std::find(PPOpts.Includes.begin(), PPOpts.Includes.end(), File) |
| 730 | != PPOpts.Includes.end()) |
| 731 | continue; |
| 732 | |
| 733 | SuggestedPredefines += "#include \""; |
| 734 | SuggestedPredefines += File; |
| 735 | SuggestedPredefines += "\"\n"; |
| 736 | } |
| 737 | |
| 738 | for (unsigned I = 0, N = ExistingPPOpts.MacroIncludes.size(); I != N; ++I) { |
| 739 | StringRef File = ExistingPPOpts.MacroIncludes[I]; |
| 740 | if (std::find(PPOpts.MacroIncludes.begin(), PPOpts.MacroIncludes.end(), |
| 741 | File) |
| 742 | != PPOpts.MacroIncludes.end()) |
| 743 | continue; |
| 744 | |
| 745 | SuggestedPredefines += "#__include_macros \""; |
| 746 | SuggestedPredefines += File; |
| 747 | SuggestedPredefines += "\"\n##\n"; |
| 748 | } |
| 749 | |
| 750 | return false; |
| 751 | } |
| 752 | |
| 753 | bool PCHValidator::ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 754 | bool Complain, |
| 755 | std::string &SuggestedPredefines) { |
| 756 | const PreprocessorOptions &ExistingPPOpts = PP.getPreprocessorOpts(); |
| 757 | |
| 758 | return checkPreprocessorOptions(PPOpts, ExistingPPOpts, |
| 759 | Complain? &Reader.Diags : nullptr, |
| 760 | PP.getFileManager(), |
| 761 | SuggestedPredefines, |
| 762 | PP.getLangOpts()); |
| 763 | } |
| 764 | |
| 765 | bool SimpleASTReaderListener::ReadPreprocessorOptions( |
| 766 | const PreprocessorOptions &PPOpts, |
| 767 | bool Complain, |
| 768 | std::string &SuggestedPredefines) { |
| 769 | return checkPreprocessorOptions(PPOpts, |
| 770 | PP.getPreprocessorOpts(), |
| 771 | nullptr, |
| 772 | PP.getFileManager(), |
| 773 | SuggestedPredefines, |
| 774 | PP.getLangOpts(), |
| 775 | false); |
| 776 | } |
| 777 | |
| 778 | |
| 779 | |
| 780 | |
| 781 | |
| 782 | static bool checkHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 783 | StringRef SpecificModuleCachePath, |
| 784 | StringRef ExistingModuleCachePath, |
| 785 | DiagnosticsEngine *Diags, |
| 786 | const LangOptions &LangOpts, |
| 787 | const PreprocessorOptions &PPOpts) { |
| 788 | if (LangOpts.Modules) { |
| 789 | if (SpecificModuleCachePath != ExistingModuleCachePath && |
| 790 | !PPOpts.AllowPCHWithDifferentModulesCachePath) { |
| 791 | if (Diags) |
| 792 | Diags->Report(diag::err_pch_modulecache_mismatch) |
| 793 | << SpecificModuleCachePath << ExistingModuleCachePath; |
| 794 | return true; |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | return false; |
| 799 | } |
| 800 | |
| 801 | bool PCHValidator::ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 802 | StringRef SpecificModuleCachePath, |
| 803 | bool Complain) { |
| 804 | return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 805 | PP.getHeaderSearchInfo().getModuleCachePath(), |
| 806 | Complain ? &Reader.Diags : nullptr, |
| 807 | PP.getLangOpts(), PP.getPreprocessorOpts()); |
| 808 | } |
| 809 | |
| 810 | void PCHValidator::ReadCounter(const ModuleFile &M, unsigned Value) { |
| 811 | PP.setCounterValue(Value); |
| 812 | } |
| 813 | |
| 814 | |
| 815 | |
| 816 | |
| 817 | |
| 818 | static uint64_t readULEB(const unsigned char *&P) { |
| 819 | unsigned Length = 0; |
| 820 | const char *Error = nullptr; |
| 821 | |
| 822 | uint64_t Val = llvm::decodeULEB128(P, &Length, nullptr, &Error); |
| 823 | if (Error) |
| 824 | llvm::report_fatal_error(Error); |
| 825 | P += Length; |
| 826 | return Val; |
| 827 | } |
| 828 | |
| 829 | |
| 830 | static std::pair<unsigned, unsigned> |
| 831 | readULEBKeyDataLength(const unsigned char *&P) { |
| 832 | unsigned KeyLen = readULEB(P); |
| 833 | if ((unsigned)KeyLen != KeyLen) |
| 834 | llvm::report_fatal_error("key too large"); |
| 835 | |
| 836 | unsigned DataLen = readULEB(P); |
| 837 | if ((unsigned)DataLen != DataLen) |
| 838 | llvm::report_fatal_error("data too large"); |
| 839 | |
| 840 | return std::make_pair(KeyLen, DataLen); |
| 841 | } |
| 842 | |
| 843 | void ASTReader::setDeserializationListener(ASTDeserializationListener *Listener, |
| 844 | bool TakeOwnership) { |
| 845 | DeserializationListener = Listener; |
| 846 | OwnsDeserializationListener = TakeOwnership; |
| 847 | } |
| 848 | |
| 849 | unsigned ASTSelectorLookupTrait::ComputeHash(Selector Sel) { |
| 850 | return serialization::ComputeHash(Sel); |
| 851 | } |
| 852 | |
| 853 | std::pair<unsigned, unsigned> |
| 854 | ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 855 | return readULEBKeyDataLength(d); |
| 856 | } |
| 857 | |
| 858 | ASTSelectorLookupTrait::internal_key_type |
| 859 | ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { |
| 860 | using namespace llvm::support; |
| 861 | |
| 862 | SelectorTable &SelTable = Reader.getContext().Selectors; |
| 863 | unsigned N = endian::readNext<uint16_t, little, unaligned>(d); |
| 864 | IdentifierInfo *FirstII = Reader.getLocalIdentifier( |
| 865 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
| 866 | if (N == 0) |
| 867 | return SelTable.getNullarySelector(FirstII); |
| 868 | else if (N == 1) |
| 869 | return SelTable.getUnarySelector(FirstII); |
| 870 | |
| 871 | SmallVector<IdentifierInfo *, 16> Args; |
| 872 | Args.push_back(FirstII); |
| 873 | for (unsigned I = 1; I != N; ++I) |
| 874 | Args.push_back(Reader.getLocalIdentifier( |
| 875 | F, endian::readNext<uint32_t, little, unaligned>(d))); |
| 876 | |
| 877 | return SelTable.getSelector(N, Args.data()); |
| 878 | } |
| 879 | |
| 880 | ASTSelectorLookupTrait::data_type |
| 881 | ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, |
| 882 | unsigned DataLen) { |
| 883 | using namespace llvm::support; |
| 884 | |
| 885 | data_type Result; |
| 886 | |
| 887 | Result.ID = Reader.getGlobalSelectorID( |
| 888 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
| 889 | unsigned FullInstanceBits = endian::readNext<uint16_t, little, unaligned>(d); |
| 890 | unsigned FullFactoryBits = endian::readNext<uint16_t, little, unaligned>(d); |
| 891 | Result.InstanceBits = FullInstanceBits & 0x3; |
| 892 | Result.InstanceHasMoreThanOneDecl = (FullInstanceBits >> 2) & 0x1; |
| 893 | Result.FactoryBits = FullFactoryBits & 0x3; |
| 894 | Result.FactoryHasMoreThanOneDecl = (FullFactoryBits >> 2) & 0x1; |
| 895 | unsigned NumInstanceMethods = FullInstanceBits >> 3; |
| 896 | unsigned NumFactoryMethods = FullFactoryBits >> 3; |
| 897 | |
| 898 | |
| 899 | for (unsigned I = 0; I != NumInstanceMethods; ++I) { |
| 900 | if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>( |
| 901 | F, endian::readNext<uint32_t, little, unaligned>(d))) |
| 902 | Result.Instance.push_back(Method); |
| 903 | } |
| 904 | |
| 905 | |
| 906 | for (unsigned I = 0; I != NumFactoryMethods; ++I) { |
| 907 | if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>( |
| 908 | F, endian::readNext<uint32_t, little, unaligned>(d))) |
| 909 | Result.Factory.push_back(Method); |
| 910 | } |
| 911 | |
| 912 | return Result; |
| 913 | } |
| 914 | |
| 915 | unsigned ASTIdentifierLookupTraitBase::ComputeHash(const internal_key_type& a) { |
| 916 | return llvm::djbHash(a); |
| 917 | } |
| 918 | |
| 919 | std::pair<unsigned, unsigned> |
| 920 | ASTIdentifierLookupTraitBase::ReadKeyDataLength(const unsigned char*& d) { |
| 921 | return readULEBKeyDataLength(d); |
| 922 | } |
| 923 | |
| 924 | ASTIdentifierLookupTraitBase::internal_key_type |
| 925 | ASTIdentifierLookupTraitBase::ReadKey(const unsigned char* d, unsigned n) { |
| 926 | assert(n >= 2 && d[n-1] == '\0'); |
| 927 | return StringRef((const char*) d, n-1); |
| 928 | } |
| 929 | |
| 930 | |
| 931 | static bool isInterestingIdentifier(ASTReader &Reader, IdentifierInfo &II, |
| 932 | bool IsModule) { |
| 933 | return II.hadMacroDefinition() || II.isPoisoned() || |
| 934 | (!IsModule && II.getObjCOrBuiltinID()) || |
| 935 | II.hasRevertedTokenIDToIdentifier() || |
| 936 | (!(IsModule && Reader.getPreprocessor().getLangOpts().CPlusPlus) && |
| 937 | II.getFETokenInfo()); |
| 938 | } |
| 939 | |
| 940 | static bool readBit(unsigned &Bits) { |
| 941 | bool Value = Bits & 0x1; |
| 942 | Bits >>= 1; |
| 943 | return Value; |
| 944 | } |
| 945 | |
| 946 | IdentID ASTIdentifierLookupTrait::ReadIdentifierID(const unsigned char *d) { |
| 947 | using namespace llvm::support; |
| 948 | |
| 949 | unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d); |
| 950 | return Reader.getGlobalIdentifierID(F, RawID >> 1); |
| 951 | } |
| 952 | |
| 953 | static void markIdentifierFromAST(ASTReader &Reader, IdentifierInfo &II) { |
| 954 | if (!II.isFromAST()) { |
| 955 | II.setIsFromAST(); |
| 956 | bool IsModule = Reader.getPreprocessor().getCurrentModule() != nullptr; |
| 957 | if (isInterestingIdentifier(Reader, II, IsModule)) |
| 958 | II.setChangedSinceDeserialization(); |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, |
| 963 | const unsigned char* d, |
| 964 | unsigned DataLen) { |
| 965 | using namespace llvm::support; |
| 966 | |
| 967 | unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d); |
| 968 | bool IsInteresting = RawID & 0x01; |
| 969 | |
| 970 | |
| 971 | RawID = RawID >> 1; |
| 972 | |
| 973 | |
| 974 | IdentifierInfo *II = KnownII; |
| 975 | if (!II) { |
| 976 | II = &Reader.getIdentifierTable().getOwn(k); |
| 977 | KnownII = II; |
| 978 | } |
| 979 | markIdentifierFromAST(Reader, *II); |
| 980 | Reader.markIdentifierUpToDate(II); |
| 981 | |
| 982 | IdentID ID = Reader.getGlobalIdentifierID(F, RawID); |
| 983 | if (!IsInteresting) { |
| 984 | |
| 985 | |
| 986 | Reader.SetIdentifierInfo(ID, II); |
| 987 | return II; |
| 988 | } |
| 989 | |
| 990 | unsigned ObjCOrBuiltinID = endian::readNext<uint16_t, little, unaligned>(d); |
| 991 | unsigned Bits = endian::readNext<uint16_t, little, unaligned>(d); |
| 992 | bool CPlusPlusOperatorKeyword = readBit(Bits); |
| 993 | bool HasRevertedTokenIDToIdentifier = readBit(Bits); |
| 994 | bool Poisoned = readBit(Bits); |
| 995 | bool ExtensionToken = readBit(Bits); |
| 996 | bool HadMacroDefinition = readBit(Bits); |
| 997 | |
| 998 | assert(Bits == 0 && "Extra bits in the identifier?"); |
| 999 | DataLen -= 8; |
| 1000 | |
| 1001 | |
| 1002 | |
| 1003 | if (HasRevertedTokenIDToIdentifier && II->getTokenID() != tok::identifier) |
| 1004 | II->revertTokenIDToIdentifier(); |
| 1005 | if (!F.isModule()) |
| 1006 | II->setObjCOrBuiltinID(ObjCOrBuiltinID); |
| 1007 | assert(II->isExtensionToken() == ExtensionToken && |
| 1008 | "Incorrect extension token flag"); |
| 1009 | (void)ExtensionToken; |
| 1010 | if (Poisoned) |
| 1011 | II->setIsPoisoned(true); |
| 1012 | assert(II->isCPlusPlusOperatorKeyword() == CPlusPlusOperatorKeyword && |
| 1013 | "Incorrect C++ operator keyword flag"); |
| 1014 | (void)CPlusPlusOperatorKeyword; |
| 1015 | |
| 1016 | |
| 1017 | |
| 1018 | if (HadMacroDefinition) { |
| 1019 | uint32_t MacroDirectivesOffset = |
| 1020 | endian::readNext<uint32_t, little, unaligned>(d); |
| 1021 | DataLen -= 4; |
| 1022 | |
| 1023 | Reader.addPendingMacro(II, &F, MacroDirectivesOffset); |
| 1024 | } |
| 1025 | |
| 1026 | Reader.SetIdentifierInfo(ID, II); |
| 1027 | |
| 1028 | |
| 1029 | |
| 1030 | if (DataLen > 0) { |
| 1031 | SmallVector<uint32_t, 4> DeclIDs; |
| 1032 | for (; DataLen > 0; DataLen -= 4) |
| 1033 | DeclIDs.push_back(Reader.getGlobalDeclID( |
| 1034 | F, endian::readNext<uint32_t, little, unaligned>(d))); |
| 1035 | Reader.SetGloballyVisibleDecls(II, DeclIDs); |
| 1036 | } |
| 1037 | |
| 1038 | return II; |
| 1039 | } |
| 1040 | |
| 1041 | DeclarationNameKey::DeclarationNameKey(DeclarationName Name) |
| 1042 | : Kind(Name.getNameKind()) { |
| 1043 | switch (Kind) { |
| 1044 | case DeclarationName::Identifier: |
| 1045 | Data = (uint64_t)Name.getAsIdentifierInfo(); |
| 1046 | break; |
| 1047 | case DeclarationName::ObjCZeroArgSelector: |
| 1048 | case DeclarationName::ObjCOneArgSelector: |
| 1049 | case DeclarationName::ObjCMultiArgSelector: |
| 1050 | Data = (uint64_t)Name.getObjCSelector().getAsOpaquePtr(); |
| 1051 | break; |
| 1052 | case DeclarationName::CXXOperatorName: |
| 1053 | Data = Name.getCXXOverloadedOperator(); |
| 1054 | break; |
| 1055 | case DeclarationName::CXXLiteralOperatorName: |
| 1056 | Data = (uint64_t)Name.getCXXLiteralIdentifier(); |
| 1057 | break; |
| 1058 | case DeclarationName::CXXDeductionGuideName: |
| 1059 | Data = (uint64_t)Name.getCXXDeductionGuideTemplate() |
| 1060 | ->getDeclName().getAsIdentifierInfo(); |
| 1061 | break; |
| 1062 | case DeclarationName::CXXConstructorName: |
| 1063 | case DeclarationName::CXXDestructorName: |
| 1064 | case DeclarationName::CXXConversionFunctionName: |
| 1065 | case DeclarationName::CXXUsingDirective: |
| 1066 | Data = 0; |
| 1067 | break; |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | unsigned DeclarationNameKey::getHash() const { |
| 1072 | llvm::FoldingSetNodeID ID; |
| 1073 | ID.AddInteger(Kind); |
| 1074 | |
| 1075 | switch (Kind) { |
| 1076 | case DeclarationName::Identifier: |
| 1077 | case DeclarationName::CXXLiteralOperatorName: |
| 1078 | case DeclarationName::CXXDeductionGuideName: |
| 1079 | ID.AddString(((IdentifierInfo*)Data)->getName()); |
| 1080 | break; |
| 1081 | case DeclarationName::ObjCZeroArgSelector: |
| 1082 | case DeclarationName::ObjCOneArgSelector: |
| 1083 | case DeclarationName::ObjCMultiArgSelector: |
| 1084 | ID.AddInteger(serialization::ComputeHash(Selector(Data))); |
| 1085 | break; |
| 1086 | case DeclarationName::CXXOperatorName: |
| 1087 | ID.AddInteger((OverloadedOperatorKind)Data); |
| 1088 | break; |
| 1089 | case DeclarationName::CXXConstructorName: |
| 1090 | case DeclarationName::CXXDestructorName: |
| 1091 | case DeclarationName::CXXConversionFunctionName: |
| 1092 | case DeclarationName::CXXUsingDirective: |
| 1093 | break; |
| 1094 | } |
| 1095 | |
| 1096 | return ID.ComputeHash(); |
| 1097 | } |
| 1098 | |
| 1099 | ModuleFile * |
| 1100 | ASTDeclContextNameLookupTrait::ReadFileRef(const unsigned char *&d) { |
| 1101 | using namespace llvm::support; |
| 1102 | |
| 1103 | uint32_t ModuleFileID = endian::readNext<uint32_t, little, unaligned>(d); |
| 1104 | return Reader.getLocalModuleFile(F, ModuleFileID); |
| 1105 | } |
| 1106 | |
| 1107 | std::pair<unsigned, unsigned> |
| 1108 | ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char *&d) { |
| 1109 | return readULEBKeyDataLength(d); |
| 1110 | } |
| 1111 | |
| 1112 | ASTDeclContextNameLookupTrait::internal_key_type |
| 1113 | ASTDeclContextNameLookupTrait::ReadKey(const unsigned char *d, unsigned) { |
| 1114 | using namespace llvm::support; |
| 1115 | |
| 1116 | auto Kind = (DeclarationName::NameKind)*d++; |
| 1117 | uint64_t Data; |
| 1118 | switch (Kind) { |
| 1119 | case DeclarationName::Identifier: |
| 1120 | case DeclarationName::CXXLiteralOperatorName: |
| 1121 | case DeclarationName::CXXDeductionGuideName: |
| 1122 | Data = (uint64_t)Reader.getLocalIdentifier( |
| 1123 | F, endian::readNext<uint32_t, little, unaligned>(d)); |
| 1124 | break; |
| 1125 | case DeclarationName::ObjCZeroArgSelector: |
| 1126 | case DeclarationName::ObjCOneArgSelector: |
| 1127 | case DeclarationName::ObjCMultiArgSelector: |
| 1128 | Data = |
| 1129 | (uint64_t)Reader.getLocalSelector( |
| 1130 | F, endian::readNext<uint32_t, little, unaligned>( |
| 1131 | d)).getAsOpaquePtr(); |
| 1132 | break; |
| 1133 | case DeclarationName::CXXOperatorName: |
| 1134 | Data = *d++; |
| 1135 | break; |
| 1136 | case DeclarationName::CXXConstructorName: |
| 1137 | case DeclarationName::CXXDestructorName: |
| 1138 | case DeclarationName::CXXConversionFunctionName: |
| 1139 | case DeclarationName::CXXUsingDirective: |
| 1140 | Data = 0; |
| 1141 | break; |
| 1142 | } |
| 1143 | |
| 1144 | return DeclarationNameKey(Kind, Data); |
| 1145 | } |
| 1146 | |
| 1147 | void ASTDeclContextNameLookupTrait::ReadDataInto(internal_key_type, |
| 1148 | const unsigned char *d, |
| 1149 | unsigned DataLen, |
| 1150 | data_type_builder &Val) { |
| 1151 | using namespace llvm::support; |
| 1152 | |
| 1153 | for (unsigned NumDecls = DataLen / 4; NumDecls; --NumDecls) { |
| 1154 | uint32_t LocalID = endian::readNext<uint32_t, little, unaligned>(d); |
| 1155 | Val.insert(Reader.getGlobalDeclID(F, LocalID)); |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | bool ASTReader::ReadLexicalDeclContextStorage(ModuleFile &M, |
| 1160 | BitstreamCursor &Cursor, |
| 1161 | uint64_t Offset, |
| 1162 | DeclContext *DC) { |
| 1163 | assert(Offset != 0); |
| 1164 | |
| 1165 | SavedStreamPosition SavedPosition(Cursor); |
| 1166 | if (llvm::Error Err = Cursor.JumpToBit(Offset)) { |
| 1167 | Error(std::move(Err)); |
| 1168 | return true; |
| 1169 | } |
| 1170 | |
| 1171 | RecordData Record; |
| 1172 | StringRef Blob; |
| 1173 | Expected<unsigned> MaybeCode = Cursor.ReadCode(); |
| 1174 | if (!MaybeCode) { |
| 1175 | Error(MaybeCode.takeError()); |
| 1176 | return true; |
| 1177 | } |
| 1178 | unsigned Code = MaybeCode.get(); |
| 1179 | |
| 1180 | Expected<unsigned> MaybeRecCode = Cursor.readRecord(Code, Record, &Blob); |
| 1181 | if (!MaybeRecCode) { |
| 1182 | Error(MaybeRecCode.takeError()); |
| 1183 | return true; |
| 1184 | } |
| 1185 | unsigned RecCode = MaybeRecCode.get(); |
| 1186 | if (RecCode != DECL_CONTEXT_LEXICAL) { |
| 1187 | Error("Expected lexical block"); |
| 1188 | return true; |
| 1189 | } |
| 1190 | |
| 1191 | assert(!isa<TranslationUnitDecl>(DC) && |
| 1192 | "expected a TU_UPDATE_LEXICAL record for TU"); |
| 1193 | |
| 1194 | |
| 1195 | |
| 1196 | |
| 1197 | auto &Lex = LexicalDecls[DC]; |
| 1198 | if (!Lex.first) { |
| 1199 | Lex = std::make_pair( |
| 1200 | &M, llvm::makeArrayRef( |
| 1201 | reinterpret_cast<const llvm::support::unaligned_uint32_t *>( |
| 1202 | Blob.data()), |
| 1203 | Blob.size() / 4)); |
| 1204 | } |
| 1205 | DC->setHasExternalLexicalStorage(true); |
| 1206 | return false; |
| 1207 | } |
| 1208 | |
| 1209 | bool ASTReader::ReadVisibleDeclContextStorage(ModuleFile &M, |
| 1210 | BitstreamCursor &Cursor, |
| 1211 | uint64_t Offset, |
| 1212 | DeclID ID) { |
| 1213 | assert(Offset != 0); |
| 1214 | |
| 1215 | SavedStreamPosition SavedPosition(Cursor); |
| 1216 | if (llvm::Error Err = Cursor.JumpToBit(Offset)) { |
| 1217 | Error(std::move(Err)); |
| 1218 | return true; |
| 1219 | } |
| 1220 | |
| 1221 | RecordData Record; |
| 1222 | StringRef Blob; |
| 1223 | Expected<unsigned> MaybeCode = Cursor.ReadCode(); |
| 1224 | if (!MaybeCode) { |
| 1225 | Error(MaybeCode.takeError()); |
| 1226 | return true; |
| 1227 | } |
| 1228 | unsigned Code = MaybeCode.get(); |
| 1229 | |
| 1230 | Expected<unsigned> MaybeRecCode = Cursor.readRecord(Code, Record, &Blob); |
| 1231 | if (!MaybeRecCode) { |
| 1232 | Error(MaybeRecCode.takeError()); |
| 1233 | return true; |
| 1234 | } |
| 1235 | unsigned RecCode = MaybeRecCode.get(); |
| 1236 | if (RecCode != DECL_CONTEXT_VISIBLE) { |
| 1237 | Error("Expected visible lookup table block"); |
| 1238 | return true; |
| 1239 | } |
| 1240 | |
| 1241 | |
| 1242 | |
| 1243 | auto *Data = (const unsigned char*)Blob.data(); |
| 1244 | PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&M, Data}); |
| 1245 | return false; |
| 1246 | } |
| 1247 | |
| 1248 | void ASTReader::Error(StringRef Msg) const { |
| 1249 | Error(diag::err_fe_pch_malformed, Msg); |
| 1250 | if (PP.getLangOpts().Modules && !Diags.isDiagnosticInFlight() && |
| 1251 | !PP.getHeaderSearchInfo().getModuleCachePath().empty()) { |
| 1252 | Diag(diag::note_module_cache_path) |
| 1253 | << PP.getHeaderSearchInfo().getModuleCachePath(); |
| 1254 | } |
| 1255 | } |
| 1256 | |
| 1257 | void ASTReader::Error(unsigned DiagID, StringRef Arg1, StringRef Arg2, |
| 1258 | StringRef Arg3) const { |
| 1259 | if (Diags.isDiagnosticInFlight()) |
| 1260 | Diags.SetDelayedDiagnostic(DiagID, Arg1, Arg2, Arg3); |
| 1261 | else |
| 1262 | Diag(DiagID) << Arg1 << Arg2 << Arg3; |
| 1263 | } |
| 1264 | |
| 1265 | void ASTReader::Error(llvm::Error &&Err) const { |
| 1266 | Error(toString(std::move(Err))); |
| 1267 | } |
| 1268 | |
| 1269 | |
| 1270 | |
| 1271 | |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | bool ASTReader::ParseLineTable(ModuleFile &F, |
| 1276 | const RecordData &Record) { |
| 1277 | unsigned Idx = 0; |
| 1278 | LineTableInfo &LineTable = SourceMgr.getLineTable(); |
| 1279 | |
| 1280 | |
| 1281 | std::map<int, int> FileIDs; |
| 1282 | FileIDs[-1] = -1; |
| 1283 | for (unsigned I = 0; Record[Idx]; ++I) { |
| 1284 | |
| 1285 | auto Filename = ReadPath(F, Record, Idx); |
| 1286 | FileIDs[I] = LineTable.getLineTableFilenameID(Filename); |
| 1287 | } |
| 1288 | ++Idx; |
| 1289 | |
| 1290 | |
| 1291 | std::vector<LineEntry> Entries; |
| 1292 | while (Idx < Record.size()) { |
| 1293 | int FID = Record[Idx++]; |
| 1294 | assert(FID >= 0 && "Serialized line entries for non-local file."); |
| 1295 | |
| 1296 | FID += F.SLocEntryBaseID - 1; |
| 1297 | |
| 1298 | |
| 1299 | unsigned NumEntries = Record[Idx++]; |
| 1300 | assert(NumEntries && "no line entries for file ID"); |
| 1301 | Entries.clear(); |
| 1302 | Entries.reserve(NumEntries); |
| 1303 | for (unsigned I = 0; I != NumEntries; ++I) { |
| 1304 | unsigned FileOffset = Record[Idx++]; |
| 1305 | unsigned LineNo = Record[Idx++]; |
| 1306 | int FilenameID = FileIDs[Record[Idx++]]; |
| 1307 | SrcMgr::CharacteristicKind FileKind |
| 1308 | = (SrcMgr::CharacteristicKind)Record[Idx++]; |
| 1309 | unsigned IncludeOffset = Record[Idx++]; |
| 1310 | Entries.push_back(LineEntry::get(FileOffset, LineNo, FilenameID, |
| 1311 | FileKind, IncludeOffset)); |
| 1312 | } |
| 1313 | LineTable.AddEntry(FileID::get(FID), Entries); |
| 1314 | } |
| 1315 | |
| 1316 | return false; |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | bool ASTReader::ReadSourceManagerBlock(ModuleFile &F) { |
| 1321 | using namespace SrcMgr; |
| 1322 | |
| 1323 | BitstreamCursor &SLocEntryCursor = F.SLocEntryCursor; |
| 1324 | |
| 1325 | |
| 1326 | |
| 1327 | |
| 1328 | |
| 1329 | SLocEntryCursor = F.Stream; |
| 1330 | |
| 1331 | |
| 1332 | if (llvm::Error Err = F.Stream.SkipBlock()) { |
| 1333 | Error(std::move(Err)); |
| 1334 | return true; |
| 1335 | } |
| 1336 | |
| 1337 | |
| 1338 | if (llvm::Error Err = |
| 1339 | SLocEntryCursor.EnterSubBlock(SOURCE_MANAGER_BLOCK_ID)) { |
| 1340 | Error(std::move(Err)); |
| 1341 | return true; |
| 1342 | } |
| 1343 | F.SourceManagerBlockStartOffset = SLocEntryCursor.GetCurrentBitNo(); |
| 1344 | |
| 1345 | RecordData Record; |
| 1346 | while (true) { |
| 1347 | Expected<llvm::BitstreamEntry> MaybeE = |
| 1348 | SLocEntryCursor.advanceSkippingSubblocks(); |
| 1349 | if (!MaybeE) { |
| 1350 | Error(MaybeE.takeError()); |
| 1351 | return true; |
| 1352 | } |
| 1353 | llvm::BitstreamEntry E = MaybeE.get(); |
| 1354 | |
| 1355 | switch (E.Kind) { |
| 1356 | case llvm::BitstreamEntry::SubBlock: |
| 1357 | case llvm::BitstreamEntry::Error: |
| 1358 | Error("malformed block record in AST file"); |
| 1359 | return true; |
| 1360 | case llvm::BitstreamEntry::EndBlock: |
| 1361 | return false; |
| 1362 | case llvm::BitstreamEntry::Record: |
| 1363 | |
| 1364 | break; |
| 1365 | } |
| 1366 | |
| 1367 | |
| 1368 | Record.clear(); |
| 1369 | StringRef Blob; |
| 1370 | Expected<unsigned> MaybeRecord = |
| 1371 | SLocEntryCursor.readRecord(E.ID, Record, &Blob); |
| 1372 | if (!MaybeRecord) { |
| 1373 | Error(MaybeRecord.takeError()); |
| 1374 | return true; |
| 1375 | } |
| 1376 | switch (MaybeRecord.get()) { |
| 1377 | default: |
| 1378 | break; |
| 1379 | |
| 1380 | case SM_SLOC_FILE_ENTRY: |
| 1381 | case SM_SLOC_BUFFER_ENTRY: |
| 1382 | case SM_SLOC_EXPANSION_ENTRY: |
| 1383 | |
| 1384 | return false; |
| 1385 | } |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | |
| 1390 | |
| 1391 | |
| 1392 | |
| 1393 | static std::string |
| 1394 | resolveFileRelativeToOriginalDir(const std::string &Filename, |
| 1395 | const std::string &OriginalDir, |
| 1396 | const std::string &CurrDir) { |
| 1397 | assert(OriginalDir != CurrDir && |
| 1398 | "No point trying to resolve the file if the PCH dir didn't change"); |
| 1399 | |
| 1400 | using namespace llvm::sys; |
| 1401 | |
| 1402 | SmallString<128> filePath(Filename); |
| 1403 | fs::make_absolute(filePath); |
| 1404 | assert(path::is_absolute(OriginalDir)); |
| 1405 | SmallString<128> currPCHPath(CurrDir); |
| 1406 | |
| 1407 | path::const_iterator fileDirI = path::begin(path::parent_path(filePath)), |
| 1408 | fileDirE = path::end(path::parent_path(filePath)); |
| 1409 | path::const_iterator origDirI = path::begin(OriginalDir), |
| 1410 | origDirE = path::end(OriginalDir); |
| 1411 | |
| 1412 | while (fileDirI != fileDirE && origDirI != origDirE && |
| 1413 | *fileDirI == *origDirI) { |
| 1414 | ++fileDirI; |
| 1415 | ++origDirI; |
| 1416 | } |
| 1417 | for (; origDirI != origDirE; ++origDirI) |
| 1418 | path::append(currPCHPath, ".."); |
| 1419 | path::append(currPCHPath, fileDirI, fileDirE); |
| 1420 | path::append(currPCHPath, path::filename(Filename)); |
| 1421 | return std::string(currPCHPath.str()); |
| 1422 | } |
| 1423 | |
| 1424 | bool ASTReader::ReadSLocEntry(int ID) { |
| 1425 | if (ID == 0) |
| 1426 | return false; |
| 1427 | |
| 1428 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
| 1429 | Error("source location entry ID out-of-range for AST file"); |
| 1430 | return true; |
| 1431 | } |
| 1432 | |
| 1433 | |
| 1434 | |
| 1435 | auto ReadBuffer = [this]( |
| 1436 | BitstreamCursor &SLocEntryCursor, |
| 1437 | StringRef Name) -> std::unique_ptr<llvm::MemoryBuffer> { |
| 1438 | RecordData Record; |
| 1439 | StringRef Blob; |
| 1440 | Expected<unsigned> MaybeCode = SLocEntryCursor.ReadCode(); |
| 1441 | if (!MaybeCode) { |
| 1442 | Error(MaybeCode.takeError()); |
| 1443 | return nullptr; |
| 1444 | } |
| 1445 | unsigned Code = MaybeCode.get(); |
| 1446 | |
| 1447 | Expected<unsigned> MaybeRecCode = |
| 1448 | SLocEntryCursor.readRecord(Code, Record, &Blob); |
| 1449 | if (!MaybeRecCode) { |
| 1450 | Error(MaybeRecCode.takeError()); |
| 1451 | return nullptr; |
| 1452 | } |
| 1453 | unsigned RecCode = MaybeRecCode.get(); |
| 1454 | |
| 1455 | if (RecCode == SM_SLOC_BUFFER_BLOB_COMPRESSED) { |
| 1456 | if (!llvm::zlib::isAvailable()) { |
| 1457 | Error("zlib is not available"); |
| 1458 | return nullptr; |
| 1459 | } |
| 1460 | SmallString<0> Uncompressed; |
| 1461 | if (llvm::Error E = |
| 1462 | llvm::zlib::uncompress(Blob, Uncompressed, Record[0])) { |
| 1463 | Error("could not decompress embedded file contents: " + |
| 1464 | llvm::toString(std::move(E))); |
| 1465 | return nullptr; |
| 1466 | } |
| 1467 | return llvm::MemoryBuffer::getMemBufferCopy(Uncompressed, Name); |
| 1468 | } else if (RecCode == SM_SLOC_BUFFER_BLOB) { |
| 1469 | return llvm::MemoryBuffer::getMemBuffer(Blob.drop_back(1), Name, true); |
| 1470 | } else { |
| 1471 | Error("AST record has invalid code"); |
| 1472 | return nullptr; |
| 1473 | } |
| 1474 | }; |
| 1475 | |
| 1476 | ModuleFile *F = GlobalSLocEntryMap.find(-ID)->second; |
| 1477 | if (llvm::Error Err = F->SLocEntryCursor.JumpToBit( |
| 1478 | F->SLocEntryOffsetsBase + |
| 1479 | F->SLocEntryOffsets[ID - F->SLocEntryBaseID])) { |
| 1480 | Error(std::move(Err)); |
| 1481 | return true; |
| 1482 | } |
| 1483 | |
| 1484 | BitstreamCursor &SLocEntryCursor = F->SLocEntryCursor; |
| 1485 | SourceLocation::UIntTy BaseOffset = F->SLocEntryBaseOffset; |
| 1486 | |
| 1487 | ++NumSLocEntriesRead; |
| 1488 | Expected<llvm::BitstreamEntry> MaybeEntry = SLocEntryCursor.advance(); |
| 1489 | if (!MaybeEntry) { |
| 1490 | Error(MaybeEntry.takeError()); |
| 1491 | return true; |
| 1492 | } |
| 1493 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 1494 | |
| 1495 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| 1496 | Error("incorrectly-formatted source location entry in AST file"); |
| 1497 | return true; |
| 1498 | } |
| 1499 | |
| 1500 | RecordData Record; |
| 1501 | StringRef Blob; |
| 1502 | Expected<unsigned> MaybeSLOC = |
| 1503 | SLocEntryCursor.readRecord(Entry.ID, Record, &Blob); |
| 1504 | if (!MaybeSLOC) { |
| 1505 | Error(MaybeSLOC.takeError()); |
| 1506 | return true; |
| 1507 | } |
| 1508 | switch (MaybeSLOC.get()) { |
| 1509 | default: |
| 1510 | Error("incorrectly-formatted source location entry in AST file"); |
| 1511 | return true; |
| 1512 | |
| 1513 | case SM_SLOC_FILE_ENTRY: { |
| 1514 | |
| 1515 | |
| 1516 | unsigned InputID = Record[4]; |
| 1517 | InputFile IF = getInputFile(*F, InputID); |
| 1518 | Optional<FileEntryRef> File = IF.getFile(); |
| 1519 | bool OverriddenBuffer = IF.isOverridden(); |
| 1520 | |
| 1521 | |
| 1522 | |
| 1523 | |
| 1524 | if (!File) |
| 1525 | return true; |
| 1526 | |
| 1527 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
| 1528 | if (IncludeLoc.isInvalid() && F->Kind != MK_MainFile) { |
| 1529 | |
| 1530 | IncludeLoc = getImportLocation(F); |
| 1531 | } |
| 1532 | SrcMgr::CharacteristicKind |
| 1533 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1534 | FileID FID = SourceMgr.createFileID(*File, IncludeLoc, FileCharacter, ID, |
| 1535 | BaseOffset + Record[0]); |
| 1536 | SrcMgr::FileInfo &FileInfo = |
| 1537 | const_cast<SrcMgr::FileInfo&>(SourceMgr.getSLocEntry(FID).getFile()); |
| 1538 | FileInfo.NumCreatedFIDs = Record[5]; |
| 1539 | if (Record[3]) |
| 1540 | FileInfo.setHasLineDirectives(); |
| 1541 | |
| 1542 | unsigned NumFileDecls = Record[7]; |
| 1543 | if (NumFileDecls && ContextObj) { |
| 1544 | const DeclID *FirstDecl = F->FileSortedDecls + Record[6]; |
| 1545 | assert(F->FileSortedDecls && "FILE_SORTED_DECLS not encountered yet ?"); |
| 1546 | FileDeclIDs[FID] = FileDeclsInfo(F, llvm::makeArrayRef(FirstDecl, |
| 1547 | NumFileDecls)); |
| 1548 | } |
| 1549 | |
| 1550 | const SrcMgr::ContentCache &ContentCache = |
| 1551 | SourceMgr.getOrCreateContentCache(*File, isSystem(FileCharacter)); |
| 1552 | if (OverriddenBuffer && !ContentCache.BufferOverridden && |
| 1553 | ContentCache.ContentsEntry == ContentCache.OrigEntry && |
| 1554 | !ContentCache.getBufferIfLoaded()) { |
| 1555 | auto Buffer = ReadBuffer(SLocEntryCursor, File->getName()); |
| 1556 | if (!Buffer) |
| 1557 | return true; |
| 1558 | SourceMgr.overrideFileContents(*File, std::move(Buffer)); |
| 1559 | } |
| 1560 | |
| 1561 | break; |
| 1562 | } |
| 1563 | |
| 1564 | case SM_SLOC_BUFFER_ENTRY: { |
| 1565 | const char *Name = Blob.data(); |
| 1566 | unsigned Offset = Record[0]; |
| 1567 | SrcMgr::CharacteristicKind |
| 1568 | FileCharacter = (SrcMgr::CharacteristicKind)Record[2]; |
| 1569 | SourceLocation IncludeLoc = ReadSourceLocation(*F, Record[1]); |
| 1570 | if (IncludeLoc.isInvalid() && F->isModule()) { |
| 1571 | IncludeLoc = getImportLocation(F); |
| 1572 | } |
| 1573 | |
| 1574 | auto Buffer = ReadBuffer(SLocEntryCursor, Name); |
| 1575 | if (!Buffer) |
| 1576 | return true; |
| 1577 | SourceMgr.createFileID(std::move(Buffer), FileCharacter, ID, |
| 1578 | BaseOffset + Offset, IncludeLoc); |
| 1579 | break; |
| 1580 | } |
| 1581 | |
| 1582 | case SM_SLOC_EXPANSION_ENTRY: { |
| 1583 | SourceLocation SpellingLoc = ReadSourceLocation(*F, Record[1]); |
| 1584 | SourceMgr.createExpansionLoc(SpellingLoc, |
| 1585 | ReadSourceLocation(*F, Record[2]), |
| 1586 | ReadSourceLocation(*F, Record[3]), |
| 1587 | Record[5], |
| 1588 | Record[4], |
| 1589 | ID, |
| 1590 | BaseOffset + Record[0]); |
| 1591 | break; |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | return false; |
| 1596 | } |
| 1597 | |
| 1598 | std::pair<SourceLocation, StringRef> ASTReader::getModuleImportLoc(int ID) { |
| 1599 | if (ID == 0) |
| 1600 | return std::make_pair(SourceLocation(), ""); |
| 1601 | |
| 1602 | if (unsigned(-ID) - 2 >= getTotalNumSLocs() || ID > 0) { |
| 1603 | Error("source location entry ID out-of-range for AST file"); |
| 1604 | return std::make_pair(SourceLocation(), ""); |
| 1605 | } |
| 1606 | |
| 1607 | |
| 1608 | ModuleFile *M = GlobalSLocEntryMap.find(-ID)->second; |
| 1609 | if (!M->isModule()) |
| 1610 | return std::make_pair(SourceLocation(), ""); |
| 1611 | |
| 1612 | |
| 1613 | |
| 1614 | return std::make_pair(M->ImportLoc, StringRef(M->ModuleName)); |
| 1615 | } |
| 1616 | |
| 1617 | |
| 1618 | SourceLocation ASTReader::getImportLocation(ModuleFile *F) { |
| 1619 | if (F->ImportLoc.isValid()) |
| 1620 | return F->ImportLoc; |
| 1621 | |
| 1622 | |
| 1623 | |
| 1624 | if (F->ImportedBy.empty() || !F->ImportedBy[0]) { |
| 1625 | |
| 1626 | assert(SourceMgr.getMainFileID().isValid() && "missing main file"); |
| 1627 | return SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID()); |
| 1628 | } |
| 1629 | return F->ImportedBy[0]->FirstLoc; |
| 1630 | } |
| 1631 | |
| 1632 | |
| 1633 | |
| 1634 | |
| 1635 | bool ASTReader::ReadBlockAbbrevs(BitstreamCursor &Cursor, unsigned BlockID, |
| 1636 | uint64_t *StartOfBlockOffset) { |
| 1637 | if (llvm::Error Err = Cursor.EnterSubBlock(BlockID)) { |
| 1638 | |
| 1639 | consumeError(std::move(Err)); |
| 1640 | return true; |
| 1641 | } |
| 1642 | |
| 1643 | if (StartOfBlockOffset) |
| 1644 | *StartOfBlockOffset = Cursor.GetCurrentBitNo(); |
| 1645 | |
| 1646 | while (true) { |
| 1647 | uint64_t Offset = Cursor.GetCurrentBitNo(); |
| 1648 | Expected<unsigned> MaybeCode = Cursor.ReadCode(); |
| 1649 | if (!MaybeCode) { |
| 1650 | |
| 1651 | consumeError(MaybeCode.takeError()); |
| 1652 | return true; |
| 1653 | } |
| 1654 | unsigned Code = MaybeCode.get(); |
| 1655 | |
| 1656 | |
| 1657 | if (Code != llvm::bitc::DEFINE_ABBREV) { |
| 1658 | if (llvm::Error Err = Cursor.JumpToBit(Offset)) { |
| 1659 | |
| 1660 | consumeError(std::move(Err)); |
| 1661 | return true; |
| 1662 | } |
| 1663 | return false; |
| 1664 | } |
| 1665 | if (llvm::Error Err = Cursor.ReadAbbrevRecord()) { |
| 1666 | |
| 1667 | consumeError(std::move(Err)); |
| 1668 | return true; |
| 1669 | } |
| 1670 | } |
| 1671 | } |
| 1672 | |
| 1673 | Token ASTReader::ReadToken(ModuleFile &F, const RecordDataImpl &Record, |
| 1674 | unsigned &Idx) { |
| 1675 | Token Tok; |
| 1676 | Tok.startToken(); |
| 1677 | Tok.setLocation(ReadSourceLocation(F, Record, Idx)); |
| 1678 | Tok.setLength(Record[Idx++]); |
| 1679 | if (IdentifierInfo *II = getLocalIdentifier(F, Record[Idx++])) |
| 1680 | Tok.setIdentifierInfo(II); |
| 1681 | Tok.setKind((tok::TokenKind)Record[Idx++]); |
| 1682 | Tok.setFlag((Token::TokenFlags)Record[Idx++]); |
| 1683 | return Tok; |
| 1684 | } |
| 1685 | |
| 1686 | MacroInfo *ASTReader::ReadMacroRecord(ModuleFile &F, uint64_t Offset) { |
| 1687 | BitstreamCursor &Stream = F.MacroCursor; |
| 1688 | |
| 1689 | |
| 1690 | |
| 1691 | SavedStreamPosition SavedPosition(Stream); |
| 1692 | |
| 1693 | if (llvm::Error Err = Stream.JumpToBit(Offset)) { |
| 1694 | |
| 1695 | consumeError(std::move(Err)); |
| 1696 | return nullptr; |
| 1697 | } |
| 1698 | RecordData Record; |
| 1699 | SmallVector<IdentifierInfo*, 16> MacroParams; |
| 1700 | MacroInfo *Macro = nullptr; |
| 1701 | |
| 1702 | while (true) { |
| 1703 | |
| 1704 | |
| 1705 | |
| 1706 | unsigned Flags = BitstreamCursor::AF_DontPopBlockAtEnd; |
| 1707 | Expected<llvm::BitstreamEntry> MaybeEntry = |
| 1708 | Stream.advanceSkippingSubblocks(Flags); |
| 1709 | if (!MaybeEntry) { |
| 1710 | Error(MaybeEntry.takeError()); |
| 1711 | return Macro; |
| 1712 | } |
| 1713 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 1714 | |
| 1715 | switch (Entry.Kind) { |
| 1716 | case llvm::BitstreamEntry::SubBlock: |
| 1717 | case llvm::BitstreamEntry::Error: |
| 1718 | Error("malformed block record in AST file"); |
| 1719 | return Macro; |
| 1720 | case llvm::BitstreamEntry::EndBlock: |
| 1721 | return Macro; |
| 1722 | case llvm::BitstreamEntry::Record: |
| 1723 | |
| 1724 | break; |
| 1725 | } |
| 1726 | |
| 1727 | |
| 1728 | Record.clear(); |
| 1729 | PreprocessorRecordTypes RecType; |
| 1730 | if (Expected<unsigned> MaybeRecType = Stream.readRecord(Entry.ID, Record)) |
| 1731 | RecType = (PreprocessorRecordTypes)MaybeRecType.get(); |
| 1732 | else { |
| 1733 | Error(MaybeRecType.takeError()); |
| 1734 | return Macro; |
| 1735 | } |
| 1736 | switch (RecType) { |
| 1737 | case PP_MODULE_MACRO: |
| 1738 | case PP_MACRO_DIRECTIVE_HISTORY: |
| 1739 | return Macro; |
| 1740 | |
| 1741 | case PP_MACRO_OBJECT_LIKE: |
| 1742 | case PP_MACRO_FUNCTION_LIKE: { |
| 1743 | |
| 1744 | |
| 1745 | |
| 1746 | if (Macro) |
| 1747 | return Macro; |
| 1748 | |
| 1749 | unsigned NextIndex = 1; |
| 1750 | SourceLocation Loc = ReadSourceLocation(F, Record, NextIndex); |
| 1751 | MacroInfo *MI = PP.AllocateMacroInfo(Loc); |
| 1752 | MI->setDefinitionEndLoc(ReadSourceLocation(F, Record, NextIndex)); |
| 1753 | MI->setIsUsed(Record[NextIndex++]); |
| 1754 | MI->setUsedForHeaderGuard(Record[NextIndex++]); |
| 1755 | |
| 1756 | if (RecType == PP_MACRO_FUNCTION_LIKE) { |
| 1757 | |
| 1758 | bool isC99VarArgs = Record[NextIndex++]; |
| 1759 | bool isGNUVarArgs = Record[NextIndex++]; |
| 1760 | bool hasCommaPasting = Record[NextIndex++]; |
| 1761 | MacroParams.clear(); |
| 1762 | unsigned NumArgs = Record[NextIndex++]; |
| 1763 | for (unsigned i = 0; i != NumArgs; ++i) |
| 1764 | MacroParams.push_back(getLocalIdentifier(F, Record[NextIndex++])); |
| 1765 | |
| 1766 | |
| 1767 | MI->setIsFunctionLike(); |
| 1768 | if (isC99VarArgs) MI->setIsC99Varargs(); |
| 1769 | if (isGNUVarArgs) MI->setIsGNUVarargs(); |
| 1770 | if (hasCommaPasting) MI->setHasCommaPasting(); |
| 1771 | MI->setParameterList(MacroParams, PP.getPreprocessorAllocator()); |
| 1772 | } |
| 1773 | |
| 1774 | |
| 1775 | |
| 1776 | Macro = MI; |
| 1777 | |
| 1778 | if (NextIndex + 1 == Record.size() && PP.getPreprocessingRecord() && |
| 1779 | Record[NextIndex]) { |
| 1780 | |
| 1781 | PreprocessedEntityID |
| 1782 | GlobalID = getGlobalPreprocessedEntityID(F, Record[NextIndex]); |
| 1783 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 1784 | PreprocessingRecord::PPEntityID PPID = |
| 1785 | PPRec.getPPEntityID(GlobalID - 1, true); |
| 1786 | MacroDefinitionRecord *PPDef = cast_or_null<MacroDefinitionRecord>( |
| 1787 | PPRec.getPreprocessedEntity(PPID)); |
| 1788 | if (PPDef) |
| 1789 | PPRec.RegisterMacroDefinition(Macro, PPDef); |
| 1790 | } |
| 1791 | |
| 1792 | ++NumMacrosRead; |
| 1793 | break; |
| 1794 | } |
| 1795 | |
| 1796 | case PP_TOKEN: { |
| 1797 | |
| 1798 | |
| 1799 | if (!Macro) break; |
| 1800 | |
| 1801 | unsigned Idx = 0; |
| 1802 | Token Tok = ReadToken(F, Record, Idx); |
| 1803 | Macro->AddTokenToBody(Tok); |
| 1804 | break; |
| 1805 | } |
| 1806 | } |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | PreprocessedEntityID |
| 1811 | ASTReader::getGlobalPreprocessedEntityID(ModuleFile &M, |
| 1812 | unsigned LocalID) const { |
| 1813 | if (!M.ModuleOffsetMap.empty()) |
| 1814 | ReadModuleOffsetMap(M); |
| 1815 | |
| 1816 | ContinuousRangeMap<uint32_t, int, 2>::const_iterator |
| 1817 | I = M.PreprocessedEntityRemap.find(LocalID - NUM_PREDEF_PP_ENTITY_IDS); |
| 1818 | assert(I != M.PreprocessedEntityRemap.end() |
| 1819 | && "Invalid index into preprocessed entity index remap"); |
| 1820 | |
| 1821 | return LocalID + I->second; |
| 1822 | } |
| 1823 | |
| 1824 | unsigned HeaderFileInfoTrait::ComputeHash(internal_key_ref ikey) { |
| 1825 | return llvm::hash_combine(ikey.Size, ikey.ModTime); |
| 1826 | } |
| 1827 | |
| 1828 | HeaderFileInfoTrait::internal_key_type |
| 1829 | HeaderFileInfoTrait::GetInternalKey(const FileEntry *FE) { |
| 1830 | internal_key_type ikey = {FE->getSize(), |
| 1831 | M.HasTimestamps ? FE->getModificationTime() : 0, |
| 1832 | FE->getName(), false}; |
| 1833 | return ikey; |
| 1834 | } |
| 1835 | |
| 1836 | bool HeaderFileInfoTrait::EqualKey(internal_key_ref a, internal_key_ref b) { |
| 1837 | if (a.Size != b.Size || (a.ModTime && b.ModTime && a.ModTime != b.ModTime)) |
| 1838 | return false; |
| 1839 | |
| 1840 | if (llvm::sys::path::is_absolute(a.Filename) && a.Filename == b.Filename) |
| 1841 | return true; |
| 1842 | |
| 1843 | |
| 1844 | FileManager &FileMgr = Reader.getFileManager(); |
| 1845 | auto GetFile = [&](const internal_key_type &Key) -> const FileEntry* { |
| 1846 | if (!Key.Imported) { |
| 1847 | if (auto File = FileMgr.getFile(Key.Filename)) |
| 1848 | return *File; |
| 1849 | return nullptr; |
| 1850 | } |
| 1851 | |
| 1852 | std::string Resolved = std::string(Key.Filename); |
| 1853 | Reader.ResolveImportedPath(M, Resolved); |
| 1854 | if (auto File = FileMgr.getFile(Resolved)) |
| 1855 | return *File; |
| 1856 | return nullptr; |
| 1857 | }; |
| 1858 | |
| 1859 | const FileEntry *FEA = GetFile(a); |
| 1860 | const FileEntry *FEB = GetFile(b); |
| 1861 | return FEA && FEA == FEB; |
| 1862 | } |
| 1863 | |
| 1864 | std::pair<unsigned, unsigned> |
| 1865 | HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) { |
| 1866 | return readULEBKeyDataLength(d); |
| 1867 | } |
| 1868 | |
| 1869 | HeaderFileInfoTrait::internal_key_type |
| 1870 | HeaderFileInfoTrait::ReadKey(const unsigned char *d, unsigned) { |
| 1871 | using namespace llvm::support; |
| 1872 | |
| 1873 | internal_key_type ikey; |
| 1874 | ikey.Size = off_t(endian::readNext<uint64_t, little, unaligned>(d)); |
| 1875 | ikey.ModTime = time_t(endian::readNext<uint64_t, little, unaligned>(d)); |
| 1876 | ikey.Filename = (const char *)d; |
| 1877 | ikey.Imported = true; |
| 1878 | return ikey; |
| 1879 | } |
| 1880 | |
| 1881 | HeaderFileInfoTrait::data_type |
| 1882 | HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, |
| 1883 | unsigned DataLen) { |
| 1884 | using namespace llvm::support; |
| 1885 | |
| 1886 | const unsigned char *End = d + DataLen; |
| 1887 | HeaderFileInfo HFI; |
| 1888 | unsigned Flags = *d++; |
| 1889 | |
| 1890 | HFI.isImport |= (Flags >> 5) & 0x01; |
| 1891 | HFI.isPragmaOnce |= (Flags >> 4) & 0x01; |
| 1892 | HFI.DirInfo = (Flags >> 1) & 0x07; |
| 1893 | HFI.IndexHeaderMapHeader = Flags & 0x01; |
| 1894 | |
| 1895 | |
| 1896 | HFI.NumIncludes = std::max(endian::readNext<uint16_t, little, unaligned>(d), |
| 1897 | HFI.NumIncludes); |
| 1898 | HFI.ControllingMacroID = Reader.getGlobalIdentifierID( |
| 1899 | M, endian::readNext<uint32_t, little, unaligned>(d)); |
| 1900 | if (unsigned FrameworkOffset = |
| 1901 | endian::readNext<uint32_t, little, unaligned>(d)) { |
| 1902 | |
| 1903 | |
| 1904 | StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); |
| 1905 | HFI.Framework = HS->getUniqueFrameworkName(FrameworkName); |
| 1906 | } |
| 1907 | |
| 1908 | assert((End - d) % 4 == 0 && |
| 1909 | "Wrong data length in HeaderFileInfo deserialization"); |
| 1910 | while (d != End) { |
| 1911 | uint32_t LocalSMID = endian::readNext<uint32_t, little, unaligned>(d); |
| 1912 | auto HeaderRole = static_cast<ModuleMap::ModuleHeaderRole>(LocalSMID & 3); |
| 1913 | LocalSMID >>= 2; |
| 1914 | |
| 1915 | |
| 1916 | |
| 1917 | SubmoduleID GlobalSMID = Reader.getGlobalSubmoduleID(M, LocalSMID); |
| 1918 | Module *Mod = Reader.getSubmodule(GlobalSMID); |
| 1919 | FileManager &FileMgr = Reader.getFileManager(); |
| 1920 | ModuleMap &ModMap = |
| 1921 | Reader.getPreprocessor().getHeaderSearchInfo().getModuleMap(); |
| 1922 | |
| 1923 | std::string Filename = std::string(key.Filename); |
| 1924 | if (key.Imported) |
| 1925 | Reader.ResolveImportedPath(M, Filename); |
| 1926 | |
| 1927 | Module::Header H = {std::string(key.Filename), "", |
| 1928 | *FileMgr.getFile(Filename)}; |
| 1929 | ModMap.addHeader(Mod, H, HeaderRole, true); |
| 1930 | HFI.isModuleHeader |= !(HeaderRole & ModuleMap::TextualHeader); |
| 1931 | } |
| 1932 | |
| 1933 | |
| 1934 | HFI.External = true; |
| 1935 | HFI.IsValid = true; |
| 1936 | return HFI; |
| 1937 | } |
| 1938 | |
| 1939 | void ASTReader::addPendingMacro(IdentifierInfo *II, ModuleFile *M, |
| 1940 | uint32_t MacroDirectivesOffset) { |
| 1941 | assert(NumCurrentElementsDeserializing > 0 &&"Missing deserialization guard"); |
| 1942 | PendingMacroIDs[II].push_back(PendingMacroInfo(M, MacroDirectivesOffset)); |
| 1943 | } |
| 1944 | |
| 1945 | void ASTReader::ReadDefinedMacros() { |
| 1946 | |
| 1947 | Deserializing Macros(this); |
| 1948 | |
| 1949 | for (ModuleFile &I : llvm::reverse(ModuleMgr)) { |
| 1950 | BitstreamCursor &MacroCursor = I.MacroCursor; |
| 1951 | |
| 1952 | |
| 1953 | if (MacroCursor.getBitcodeBytes().empty()) |
| 1954 | continue; |
| 1955 | |
| 1956 | BitstreamCursor Cursor = MacroCursor; |
| 1957 | if (llvm::Error Err = Cursor.JumpToBit(I.MacroStartOffset)) { |
| 1958 | Error(std::move(Err)); |
| 1959 | return; |
| 1960 | } |
| 1961 | |
| 1962 | RecordData Record; |
| 1963 | while (true) { |
| 1964 | Expected<llvm::BitstreamEntry> MaybeE = Cursor.advanceSkippingSubblocks(); |
| 1965 | if (!MaybeE) { |
| 1966 | Error(MaybeE.takeError()); |
| 1967 | return; |
| 1968 | } |
| 1969 | llvm::BitstreamEntry E = MaybeE.get(); |
| 1970 | |
| 1971 | switch (E.Kind) { |
| 1972 | case llvm::BitstreamEntry::SubBlock: |
| 1973 | case llvm::BitstreamEntry::Error: |
| 1974 | Error("malformed block record in AST file"); |
| 1975 | return; |
| 1976 | case llvm::BitstreamEntry::EndBlock: |
| 1977 | goto NextCursor; |
| 1978 | |
| 1979 | case llvm::BitstreamEntry::Record: { |
| 1980 | Record.clear(); |
| 1981 | Expected<unsigned> MaybeRecord = Cursor.readRecord(E.ID, Record); |
| 1982 | if (!MaybeRecord) { |
| 1983 | Error(MaybeRecord.takeError()); |
| 1984 | return; |
| 1985 | } |
| 1986 | switch (MaybeRecord.get()) { |
| 1987 | default: |
| 1988 | break; |
| 1989 | |
| 1990 | case PP_MACRO_OBJECT_LIKE: |
| 1991 | case PP_MACRO_FUNCTION_LIKE: { |
| 1992 | IdentifierInfo *II = getLocalIdentifier(I, Record[0]); |
| 1993 | if (II->isOutOfDate()) |
| 1994 | updateOutOfDateIdentifier(*II); |
| 1995 | break; |
| 1996 | } |
| 1997 | |
| 1998 | case PP_TOKEN: |
| 1999 | |
| 2000 | break; |
| 2001 | } |
| 2002 | break; |
| 2003 | } |
| 2004 | } |
| 2005 | } |
| 2006 | NextCursor: ; |
| 2007 | } |
| 2008 | } |
| 2009 | |
| 2010 | namespace { |
| 2011 | |
| 2012 | |
| 2013 | class IdentifierLookupVisitor { |
| 2014 | StringRef Name; |
| 2015 | unsigned NameHash; |
| 2016 | unsigned PriorGeneration; |
| 2017 | unsigned &NumIdentifierLookups; |
| 2018 | unsigned &NumIdentifierLookupHits; |
| 2019 | IdentifierInfo *Found = nullptr; |
| 2020 | |
| 2021 | public: |
| 2022 | IdentifierLookupVisitor(StringRef Name, unsigned PriorGeneration, |
| 2023 | unsigned &NumIdentifierLookups, |
| 2024 | unsigned &NumIdentifierLookupHits) |
| 2025 | : Name(Name), NameHash(ASTIdentifierLookupTrait::ComputeHash(Name)), |
| 2026 | PriorGeneration(PriorGeneration), |
| 2027 | NumIdentifierLookups(NumIdentifierLookups), |
| 2028 | NumIdentifierLookupHits(NumIdentifierLookupHits) {} |
| 2029 | |
| 2030 | bool operator()(ModuleFile &M) { |
| 2031 | |
| 2032 | if (M.Generation <= PriorGeneration) |
| 2033 | return true; |
| 2034 | |
| 2035 | ASTIdentifierLookupTable *IdTable |
| 2036 | = (ASTIdentifierLookupTable *)M.IdentifierLookupTable; |
| 2037 | if (!IdTable) |
| 2038 | return false; |
| 2039 | |
| 2040 | ASTIdentifierLookupTrait Trait(IdTable->getInfoObj().getReader(), M, |
| 2041 | Found); |
| 2042 | ++NumIdentifierLookups; |
| 2043 | ASTIdentifierLookupTable::iterator Pos = |
| 2044 | IdTable->find_hashed(Name, NameHash, &Trait); |
| 2045 | if (Pos == IdTable->end()) |
| 2046 | return false; |
| 2047 | |
| 2048 | |
| 2049 | |
| 2050 | |
| 2051 | ++NumIdentifierLookupHits; |
| 2052 | Found = *Pos; |
| 2053 | return true; |
| 2054 | } |
| 2055 | |
| 2056 | |
| 2057 | |
| 2058 | IdentifierInfo *getIdentifierInfo() const { return Found; } |
| 2059 | }; |
| 2060 | |
| 2061 | } |
| 2062 | |
| 2063 | void ASTReader::updateOutOfDateIdentifier(IdentifierInfo &II) { |
| 2064 | |
| 2065 | Deserializing AnIdentifier(this); |
| 2066 | |
| 2067 | unsigned PriorGeneration = 0; |
| 2068 | if (getContext().getLangOpts().Modules) |
| 2069 | PriorGeneration = IdentifierGeneration[&II]; |
| 2070 | |
| 2071 | |
| 2072 | |
| 2073 | GlobalModuleIndex::HitSet Hits; |
| 2074 | GlobalModuleIndex::HitSet *HitsPtr = nullptr; |
| 2075 | if (!loadGlobalIndex()) { |
| 2076 | if (GlobalIndex->lookupIdentifier(II.getName(), Hits)) { |
| 2077 | HitsPtr = &Hits; |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | IdentifierLookupVisitor Visitor(II.getName(), PriorGeneration, |
| 2082 | NumIdentifierLookups, |
| 2083 | NumIdentifierLookupHits); |
| 2084 | ModuleMgr.visit(Visitor, HitsPtr); |
| 2085 | markIdentifierUpToDate(&II); |
| 2086 | } |
| 2087 | |
| 2088 | void ASTReader::markIdentifierUpToDate(IdentifierInfo *II) { |
| 2089 | if (!II) |
| 2090 | return; |
| 2091 | |
| 2092 | II->setOutOfDate(false); |
| 2093 | |
| 2094 | |
| 2095 | if (getContext().getLangOpts().Modules) |
| 2096 | IdentifierGeneration[II] = getGeneration(); |
| 2097 | } |
| 2098 | |
| 2099 | void ASTReader::resolvePendingMacro(IdentifierInfo *II, |
| 2100 | const PendingMacroInfo &PMInfo) { |
| 2101 | ModuleFile &M = *PMInfo.M; |
| 2102 | |
| 2103 | BitstreamCursor &Cursor = M.MacroCursor; |
| 2104 | SavedStreamPosition SavedPosition(Cursor); |
| 2105 | if (llvm::Error Err = |
| 2106 | Cursor.JumpToBit(M.MacroOffsetsBase + PMInfo.MacroDirectivesOffset)) { |
| 2107 | Error(std::move(Err)); |
| 2108 | return; |
| 2109 | } |
| 2110 | |
| 2111 | struct ModuleMacroRecord { |
| 2112 | SubmoduleID SubModID; |
| 2113 | MacroInfo *MI; |
| 2114 | SmallVector<SubmoduleID, 8> Overrides; |
| 2115 | }; |
| 2116 | llvm::SmallVector<ModuleMacroRecord, 8> ModuleMacros; |
| 2117 | |
| 2118 | |
| 2119 | |
| 2120 | |
| 2121 | RecordData Record; |
| 2122 | while (true) { |
| 2123 | Expected<llvm::BitstreamEntry> MaybeEntry = |
| 2124 | Cursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd); |
| 2125 | if (!MaybeEntry) { |
| 2126 | Error(MaybeEntry.takeError()); |
| 2127 | return; |
| 2128 | } |
| 2129 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 2130 | |
| 2131 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| 2132 | Error("malformed block record in AST file"); |
| 2133 | return; |
| 2134 | } |
| 2135 | |
| 2136 | Record.clear(); |
| 2137 | Expected<unsigned> MaybePP = Cursor.readRecord(Entry.ID, Record); |
| 2138 | if (!MaybePP) { |
| 2139 | Error(MaybePP.takeError()); |
| 2140 | return; |
| 2141 | } |
| 2142 | switch ((PreprocessorRecordTypes)MaybePP.get()) { |
| 2143 | case PP_MACRO_DIRECTIVE_HISTORY: |
| 2144 | break; |
| 2145 | |
| 2146 | case PP_MODULE_MACRO: { |
| 2147 | ModuleMacros.push_back(ModuleMacroRecord()); |
| 2148 | auto &Info = ModuleMacros.back(); |
| 2149 | Info.SubModID = getGlobalSubmoduleID(M, Record[0]); |
| 2150 | Info.MI = getMacro(getGlobalMacroID(M, Record[1])); |
| 2151 | for (int I = 2, N = Record.size(); I != N; ++I) |
| 2152 | Info.Overrides.push_back(getGlobalSubmoduleID(M, Record[I])); |
| 2153 | continue; |
| 2154 | } |
| 2155 | |
| 2156 | default: |
| 2157 | Error("malformed block record in AST file"); |
| 2158 | return; |
| 2159 | } |
| 2160 | |
| 2161 | |
| 2162 | |
| 2163 | break; |
| 2164 | } |
| 2165 | |
| 2166 | |
| 2167 | { |
| 2168 | std::reverse(ModuleMacros.begin(), ModuleMacros.end()); |
| 2169 | llvm::SmallVector<ModuleMacro*, 8> Overrides; |
| 2170 | for (auto &MMR : ModuleMacros) { |
| 2171 | Overrides.clear(); |
| 2172 | for (unsigned ModID : MMR.Overrides) { |
| 2173 | Module *Mod = getSubmodule(ModID); |
| 2174 | auto *Macro = PP.getModuleMacro(Mod, II); |
| 2175 | assert(Macro && "missing definition for overridden macro"); |
| 2176 | Overrides.push_back(Macro); |
| 2177 | } |
| 2178 | |
| 2179 | bool Inserted = false; |
| 2180 | Module *Owner = getSubmodule(MMR.SubModID); |
| 2181 | PP.addModuleMacro(Owner, II, MMR.MI, Overrides, Inserted); |
| 2182 | } |
| 2183 | } |
| 2184 | |
| 2185 | |
| 2186 | |
| 2187 | if (M.isModule()) |
| 2188 | return; |
| 2189 | |
| 2190 | |
| 2191 | MacroDirective *Latest = nullptr, *Earliest = nullptr; |
| 2192 | unsigned Idx = 0, N = Record.size(); |
| 2193 | while (Idx < N) { |
| 2194 | MacroDirective *MD = nullptr; |
| 2195 | SourceLocation Loc = ReadSourceLocation(M, Record, Idx); |
| 2196 | MacroDirective::Kind K = (MacroDirective::Kind)Record[Idx++]; |
| 2197 | switch (K) { |
| 2198 | case MacroDirective::MD_Define: { |
| 2199 | MacroInfo *MI = getMacro(getGlobalMacroID(M, Record[Idx++])); |
| 2200 | MD = PP.AllocateDefMacroDirective(MI, Loc); |
| 2201 | break; |
| 2202 | } |
| 2203 | case MacroDirective::MD_Undefine: |
| 2204 | MD = PP.AllocateUndefMacroDirective(Loc); |
| 2205 | break; |
| 2206 | case MacroDirective::MD_Visibility: |
| 2207 | bool isPublic = Record[Idx++]; |
| 2208 | MD = PP.AllocateVisibilityMacroDirective(Loc, isPublic); |
| 2209 | break; |
| 2210 | } |
| 2211 | |
| 2212 | if (!Latest) |
| 2213 | Latest = MD; |
| 2214 | if (Earliest) |
| 2215 | Earliest->setPrevious(MD); |
| 2216 | Earliest = MD; |
| 2217 | } |
| 2218 | |
| 2219 | if (Latest) |
| 2220 | PP.setLoadedMacroDirective(II, Earliest, Latest); |
| 2221 | } |
| 2222 | |
| 2223 | bool ASTReader::shouldDisableValidationForFile( |
| 2224 | const serialization::ModuleFile &M) const { |
| 2225 | if (DisableValidationKind == DisableValidationForModuleKind::None) |
| 2226 | return false; |
| 2227 | |
| 2228 | |
| 2229 | |
| 2230 | ModuleKind K = CurrentDeserializingModuleKind.getValueOr(M.Kind); |
| 2231 | |
| 2232 | switch (K) { |
| 2233 | case MK_MainFile: |
| 2234 | case MK_Preamble: |
| 2235 | case MK_PCH: |
| 2236 | return bool(DisableValidationKind & DisableValidationForModuleKind::PCH); |
| 2237 | case MK_ImplicitModule: |
| 2238 | case MK_ExplicitModule: |
| 2239 | case MK_PrebuiltModule: |
| 2240 | return bool(DisableValidationKind & DisableValidationForModuleKind::Module); |
| 2241 | } |
| 2242 | |
| 2243 | return false; |
| 2244 | } |
| 2245 | |
| 2246 | ASTReader::InputFileInfo |
| 2247 | ASTReader::readInputFileInfo(ModuleFile &F, unsigned ID) { |
| 2248 | |
| 2249 | BitstreamCursor &Cursor = F.InputFilesCursor; |
| 2250 | SavedStreamPosition SavedPosition(Cursor); |
| 2251 | if (llvm::Error Err = Cursor.JumpToBit(F.InputFileOffsets[ID - 1])) { |
| 2252 | |
| 2253 | consumeError(std::move(Err)); |
| 2254 | } |
| 2255 | |
| 2256 | Expected<unsigned> MaybeCode = Cursor.ReadCode(); |
| 2257 | if (!MaybeCode) { |
| 2258 | |
| 2259 | consumeError(MaybeCode.takeError()); |
| 2260 | } |
| 2261 | unsigned Code = MaybeCode.get(); |
| 2262 | RecordData Record; |
| 2263 | StringRef Blob; |
| 2264 | |
| 2265 | if (Expected<unsigned> Maybe = Cursor.readRecord(Code, Record, &Blob)) |
| 2266 | assert(static_cast<InputFileRecordTypes>(Maybe.get()) == INPUT_FILE && |
| 2267 | "invalid record type for input file"); |
| 2268 | else { |
| 2269 | |
| 2270 | consumeError(Maybe.takeError()); |
| 2271 | } |
| 2272 | |
| 2273 | assert(Record[0] == ID && "Bogus stored ID or offset"); |
| 2274 | InputFileInfo R; |
| 2275 | R.StoredSize = static_cast<off_t>(Record[1]); |
| 2276 | R.StoredTime = static_cast<time_t>(Record[2]); |
| 2277 | R.Overridden = static_cast<bool>(Record[3]); |
| 2278 | R.Transient = static_cast<bool>(Record[4]); |
| 2279 | R.TopLevelModuleMap = static_cast<bool>(Record[5]); |
| 2280 | R.Filename = std::string(Blob); |
| 2281 | ResolveImportedPath(F, R.Filename); |
| 2282 | |
| 2283 | Expected<llvm::BitstreamEntry> MaybeEntry = Cursor.advance(); |
| 2284 | if (!MaybeEntry) |
| 2285 | consumeError(MaybeEntry.takeError()); |
| 2286 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 2287 | assert(Entry.Kind == llvm::BitstreamEntry::Record && |
| 2288 | "expected record type for input file hash"); |
| 2289 | |
| 2290 | Record.clear(); |
| 2291 | if (Expected<unsigned> Maybe = Cursor.readRecord(Entry.ID, Record)) |
| 2292 | assert(static_cast<InputFileRecordTypes>(Maybe.get()) == INPUT_FILE_HASH && |
| 2293 | "invalid record type for input file hash"); |
| 2294 | else { |
| 2295 | |
| 2296 | consumeError(Maybe.takeError()); |
| 2297 | } |
| 2298 | R.ContentHash = (static_cast<uint64_t>(Record[1]) << 32) | |
| 2299 | static_cast<uint64_t>(Record[0]); |
| 2300 | return R; |
| 2301 | } |
| 2302 | |
| 2303 | static unsigned moduleKindForDiagnostic(ModuleKind Kind); |
| 2304 | InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { |
| 2305 | |
| 2306 | if (ID == 0 || ID > F.InputFilesLoaded.size()) |
| 2307 | return InputFile(); |
| 2308 | |
| 2309 | |
| 2310 | if (F.InputFilesLoaded[ID-1].getFile()) |
| 2311 | return F.InputFilesLoaded[ID-1]; |
| 2312 | |
| 2313 | if (F.InputFilesLoaded[ID-1].isNotFound()) |
| 2314 | return InputFile(); |
| 2315 | |
| 2316 | |
| 2317 | BitstreamCursor &Cursor = F.InputFilesCursor; |
| 2318 | SavedStreamPosition SavedPosition(Cursor); |
| 2319 | if (llvm::Error Err = Cursor.JumpToBit(F.InputFileOffsets[ID - 1])) { |
| 2320 | |
| 2321 | consumeError(std::move(Err)); |
| 2322 | } |
| 2323 | |
| 2324 | InputFileInfo FI = readInputFileInfo(F, ID); |
| 2325 | off_t StoredSize = FI.StoredSize; |
| 2326 | time_t StoredTime = FI.StoredTime; |
| 2327 | bool Overridden = FI.Overridden; |
| 2328 | bool Transient = FI.Transient; |
| 2329 | StringRef Filename = FI.Filename; |
| 2330 | uint64_t StoredContentHash = FI.ContentHash; |
| 2331 | |
| 2332 | OptionalFileEntryRefDegradesToFileEntryPtr File = |
| 2333 | expectedToOptional(FileMgr.getFileRef(Filename, false)); |
| 2334 | |
| 2335 | |
| 2336 | |
| 2337 | if (!File && !F.OriginalDir.empty() && !F.BaseDirectory.empty() && |
| 2338 | F.OriginalDir != F.BaseDirectory) { |
| 2339 | std::string Resolved = resolveFileRelativeToOriginalDir( |
| 2340 | std::string(Filename), F.OriginalDir, F.BaseDirectory); |
| 2341 | if (!Resolved.empty()) |
| 2342 | File = expectedToOptional(FileMgr.getFileRef(Resolved)); |
| 2343 | } |
| 2344 | |
| 2345 | |
| 2346 | |
| 2347 | if ((Overridden || Transient) && !File) |
| 2348 | File = FileMgr.getVirtualFileRef(Filename, StoredSize, StoredTime); |
| 2349 | |
| 2350 | if (!File) { |
| 2351 | if (Complain) { |
| 2352 | std::string ErrorStr = "could not find file '"; |
| 2353 | ErrorStr += Filename; |
| 2354 | ErrorStr += "' referenced by AST file '"; |
| 2355 | ErrorStr += F.FileName; |
| 2356 | ErrorStr += "'"; |
| 2357 | Error(ErrorStr); |
| 2358 | } |
| 2359 | |
| 2360 | F.InputFilesLoaded[ID-1] = InputFile::getNotFound(); |
| 2361 | return InputFile(); |
| 2362 | } |
| 2363 | |
| 2364 | |
| 2365 | |
| 2366 | |
| 2367 | |
| 2368 | SourceManager &SM = getSourceManager(); |
| 2369 | |
| 2370 | if ((!Overridden && !Transient) && SM.isFileOverridden(File)) { |
| 2371 | if (Complain) |
| 2372 | Error(diag::err_fe_pch_file_overridden, Filename); |
| 2373 | |
| 2374 | |
| 2375 | |
| 2376 | File = SM.bypassFileContentsOverride(*File); |
| 2377 | if (!File) { |
| 2378 | F.InputFilesLoaded[ID - 1] = InputFile::getNotFound(); |
| 2379 | return InputFile(); |
| 2380 | } |
| 2381 | } |
| 2382 | |
| 2383 | enum ModificationType { |
| 2384 | Size, |
| 2385 | ModTime, |
| 2386 | Content, |
| 2387 | None, |
| 2388 | }; |
| 2389 | auto HasInputFileChanged = [&]() { |
| 2390 | if (StoredSize != File->getSize()) |
| 2391 | return ModificationType::Size; |
| 2392 | if (!shouldDisableValidationForFile(F) && StoredTime && |
| 2393 | StoredTime != File->getModificationTime()) { |
| 2394 | |
| 2395 | |
| 2396 | if (ValidateASTInputFilesContent && |
| 2397 | StoredContentHash != static_cast<uint64_t>(llvm::hash_code(-1))) { |
| 2398 | auto MemBuffOrError = FileMgr.getBufferForFile(File); |
| 2399 | if (!MemBuffOrError) { |
| 2400 | if (!Complain) |
| 2401 | return ModificationType::ModTime; |
| 2402 | std::string ErrorStr = "could not get buffer for file '"; |
| 2403 | ErrorStr += File->getName(); |
| 2404 | ErrorStr += "'"; |
| 2405 | Error(ErrorStr); |
| 2406 | return ModificationType::ModTime; |
| 2407 | } |
| 2408 | |
| 2409 | auto ContentHash = hash_value(MemBuffOrError.get()->getBuffer()); |
| 2410 | if (StoredContentHash == static_cast<uint64_t>(ContentHash)) |
| 2411 | return ModificationType::None; |
| 2412 | return ModificationType::Content; |
| 2413 | } |
| 2414 | return ModificationType::ModTime; |
| 2415 | } |
| 2416 | return ModificationType::None; |
| 2417 | }; |
| 2418 | |
| 2419 | bool IsOutOfDate = false; |
| 2420 | auto FileChange = HasInputFileChanged(); |
| 2421 | |
| 2422 | if (!Overridden && FileChange != ModificationType::None) { |
| 2423 | if (Complain && !Diags.isDiagnosticInFlight()) { |
| 2424 | |
| 2425 | SmallVector<ModuleFile *, 4> ImportStack(1, &F); |
| 2426 | while (!ImportStack.back()->ImportedBy.empty()) |
| 2427 | ImportStack.push_back(ImportStack.back()->ImportedBy[0]); |
| 2428 | |
| 2429 | |
| 2430 | StringRef TopLevelPCHName(ImportStack.back()->FileName); |
| 2431 | Diag(diag::err_fe_ast_file_modified) |
| 2432 | << Filename << moduleKindForDiagnostic(ImportStack.back()->Kind) |
| 2433 | << TopLevelPCHName << FileChange; |
| 2434 | |
| 2435 | |
| 2436 | if (ImportStack.size() > 1) { |
| 2437 | Diag(diag::note_pch_required_by) |
| 2438 | << Filename << ImportStack[0]->FileName; |
| 2439 | for (unsigned I = 1; I < ImportStack.size(); ++I) |
| 2440 | Diag(diag::note_pch_required_by) |
| 2441 | << ImportStack[I-1]->FileName << ImportStack[I]->FileName; |
| 2442 | } |
| 2443 | |
| 2444 | Diag(diag::note_pch_rebuild_required) << TopLevelPCHName; |
| 2445 | } |
| 2446 | |
| 2447 | IsOutOfDate = true; |
| 2448 | } |
| 2449 | |
| 2450 | |
| 2451 | |
| 2452 | InputFile IF = InputFile(*File, Overridden || Transient, IsOutOfDate); |
| 2453 | |
| 2454 | |
| 2455 | F.InputFilesLoaded[ID-1] = IF; |
| 2456 | return IF; |
| 2457 | } |
| 2458 | |
| 2459 | |
| 2460 | |
| 2461 | |
| 2462 | void ASTReader::ResolveImportedPath(ModuleFile &M, std::string &Filename) { |
| 2463 | |
| 2464 | if (!M.BaseDirectory.empty()) |
| 2465 | return ResolveImportedPath(Filename, M.BaseDirectory); |
| 2466 | } |
| 2467 | |
| 2468 | void ASTReader::ResolveImportedPath(std::string &Filename, StringRef Prefix) { |
| 2469 | if (Filename.empty() || llvm::sys::path::is_absolute(Filename)) |
| 2470 | return; |
| 2471 | |
| 2472 | SmallString<128> Buffer; |
| 2473 | llvm::sys::path::append(Buffer, Prefix, Filename); |
| 2474 | Filename.assign(Buffer.begin(), Buffer.end()); |
| 2475 | } |
| 2476 | |
| 2477 | static bool isDiagnosedResult(ASTReader::ASTReadResult ARR, unsigned Caps) { |
| 2478 | switch (ARR) { |
| 2479 | case ASTReader::Failure: return true; |
| 2480 | case ASTReader::Missing: return !(Caps & ASTReader::ARR_Missing); |
| 2481 | case ASTReader::OutOfDate: return !(Caps & ASTReader::ARR_OutOfDate); |
| 2482 | case ASTReader::VersionMismatch: return !(Caps & ASTReader::ARR_VersionMismatch); |
| 2483 | case ASTReader::ConfigurationMismatch: |
| 2484 | return !(Caps & ASTReader::ARR_ConfigurationMismatch); |
| 2485 | case ASTReader::HadErrors: return true; |
| 2486 | case ASTReader::Success: return false; |
| 2487 | } |
| 2488 | |
| 2489 | llvm_unreachable("unknown ASTReadResult"); |
| 2490 | } |
| 2491 | |
| 2492 | ASTReader::ASTReadResult ASTReader::ReadOptionsBlock( |
| 2493 | BitstreamCursor &Stream, unsigned ClientLoadCapabilities, |
| 2494 | bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener, |
| 2495 | std::string &SuggestedPredefines) { |
| 2496 | if (llvm::Error Err = Stream.EnterSubBlock(OPTIONS_BLOCK_ID)) { |
| 2497 | |
| 2498 | consumeError(std::move(Err)); |
| 2499 | return Failure; |
| 2500 | } |
| 2501 | |
| 2502 | |
| 2503 | RecordData Record; |
| 2504 | ASTReadResult Result = Success; |
| 2505 | while (true) { |
| 2506 | Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance(); |
| 2507 | if (!MaybeEntry) { |
| 2508 | |
| 2509 | consumeError(MaybeEntry.takeError()); |
| 2510 | return Failure; |
| 2511 | } |
| 2512 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 2513 | |
| 2514 | switch (Entry.Kind) { |
| 2515 | case llvm::BitstreamEntry::Error: |
| 2516 | case llvm::BitstreamEntry::SubBlock: |
| 2517 | return Failure; |
| 2518 | |
| 2519 | case llvm::BitstreamEntry::EndBlock: |
| 2520 | return Result; |
| 2521 | |
| 2522 | case llvm::BitstreamEntry::Record: |
| 2523 | |
| 2524 | break; |
| 2525 | } |
| 2526 | |
| 2527 | |
| 2528 | Record.clear(); |
| 2529 | Expected<unsigned> MaybeRecordType = Stream.readRecord(Entry.ID, Record); |
| 2530 | if (!MaybeRecordType) { |
| 2531 | |
| 2532 | consumeError(MaybeRecordType.takeError()); |
| 2533 | return Failure; |
| 2534 | } |
| 2535 | switch ((OptionsRecordTypes)MaybeRecordType.get()) { |
| 2536 | case LANGUAGE_OPTIONS: { |
| 2537 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2538 | if (ParseLanguageOptions(Record, Complain, Listener, |
| 2539 | AllowCompatibleConfigurationMismatch)) |
| 2540 | Result = ConfigurationMismatch; |
| 2541 | break; |
| 2542 | } |
| 2543 | |
| 2544 | case TARGET_OPTIONS: { |
| 2545 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2546 | if (ParseTargetOptions(Record, Complain, Listener, |
| 2547 | AllowCompatibleConfigurationMismatch)) |
| 2548 | Result = ConfigurationMismatch; |
| 2549 | break; |
| 2550 | } |
| 2551 | |
| 2552 | case FILE_SYSTEM_OPTIONS: { |
| 2553 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2554 | if (!AllowCompatibleConfigurationMismatch && |
| 2555 | ParseFileSystemOptions(Record, Complain, Listener)) |
| 2556 | Result = ConfigurationMismatch; |
| 2557 | break; |
| 2558 | } |
| 2559 | |
| 2560 | case HEADER_SEARCH_OPTIONS: { |
| 2561 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2562 | if (!AllowCompatibleConfigurationMismatch && |
| 2563 | ParseHeaderSearchOptions(Record, Complain, Listener)) |
| 2564 | Result = ConfigurationMismatch; |
| 2565 | break; |
| 2566 | } |
| 2567 | |
| 2568 | case PREPROCESSOR_OPTIONS: |
| 2569 | bool Complain = (ClientLoadCapabilities & ARR_ConfigurationMismatch) == 0; |
| 2570 | if (!AllowCompatibleConfigurationMismatch && |
| 2571 | ParsePreprocessorOptions(Record, Complain, Listener, |
| 2572 | SuggestedPredefines)) |
| 2573 | Result = ConfigurationMismatch; |
| 2574 | break; |
| 2575 | } |
| 2576 | } |
| 2577 | } |
| 2578 | |
| 2579 | ASTReader::ASTReadResult |
| 2580 | ASTReader::ReadControlBlock(ModuleFile &F, |
| 2581 | SmallVectorImpl<ImportedModule> &Loaded, |
| 2582 | const ModuleFile *ImportedBy, |
| 2583 | unsigned ClientLoadCapabilities) { |
| 2584 | BitstreamCursor &Stream = F.Stream; |
| 2585 | |
| 2586 | if (llvm::Error Err = Stream.EnterSubBlock(CONTROL_BLOCK_ID)) { |
| 2587 | Error(std::move(Err)); |
| 2588 | return Failure; |
| 2589 | } |
| 2590 | |
| 2591 | |
| 2592 | |
| 2593 | |
| 2594 | |
| 2595 | |
| 2596 | |
| 2597 | bool HasReadUnhashedControlBlock = false; |
| 2598 | auto readUnhashedControlBlockOnce = [&]() { |
| 2599 | if (!HasReadUnhashedControlBlock) { |
| 2600 | HasReadUnhashedControlBlock = true; |
| 2601 | if (ASTReadResult Result = |
| 2602 | readUnhashedControlBlock(F, ImportedBy, ClientLoadCapabilities)) |
| 2603 | return Result; |
| 2604 | } |
| 2605 | return Success; |
| 2606 | }; |
| 2607 | |
| 2608 | bool DisableValidation = shouldDisableValidationForFile(F); |
| 2609 | |
| 2610 | |
| 2611 | RecordData Record; |
| 2612 | unsigned NumInputs = 0; |
| 2613 | unsigned NumUserInputs = 0; |
| 2614 | StringRef BaseDirectoryAsWritten; |
| 2615 | while (true) { |
| 2616 | Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance(); |
| 2617 | if (!MaybeEntry) { |
| 2618 | Error(MaybeEntry.takeError()); |
| 2619 | return Failure; |
| 2620 | } |
| 2621 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 2622 | |
| 2623 | switch (Entry.Kind) { |
| 2624 | case llvm::BitstreamEntry::Error: |
| 2625 | Error("malformed block record in AST file"); |
| 2626 | return Failure; |
| 2627 | case llvm::BitstreamEntry::EndBlock: { |
| 2628 | |
| 2629 | |
| 2630 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2631 | return Result; |
| 2632 | |
| 2633 | |
| 2634 | const HeaderSearchOptions &HSOpts = |
| 2635 | PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 2636 | |
| 2637 | |
| 2638 | |
| 2639 | |
| 2640 | if (!DisableValidation && F.Kind != MK_ExplicitModule && |
| 2641 | F.Kind != MK_PrebuiltModule) { |
| 2642 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
| 2643 | |
| 2644 | |
| 2645 | |
| 2646 | |
| 2647 | |
| 2648 | unsigned N = NumUserInputs; |
| 2649 | if (ValidateSystemInputs || |
| 2650 | (HSOpts.ModulesValidateOncePerBuildSession && |
| 2651 | F.InputFilesValidationTimestamp <= HSOpts.BuildSessionTimestamp && |
| 2652 | F.Kind == MK_ImplicitModule)) |
| 2653 | N = NumInputs; |
| 2654 | |
| 2655 | for (unsigned I = 0; I < N; ++I) { |
| 2656 | InputFile IF = getInputFile(F, I+1, Complain); |
| 2657 | if (!IF.getFile() || IF.isOutOfDate()) |
| 2658 | return OutOfDate; |
| 2659 | } |
| 2660 | } |
| 2661 | |
| 2662 | if (Listener) |
| 2663 | Listener->visitModuleFile(F.FileName, F.Kind); |
| 2664 | |
| 2665 | if (Listener && Listener->needsInputFileVisitation()) { |
| 2666 | unsigned N = Listener->needsSystemInputFileVisitation() ? NumInputs |
| 2667 | : NumUserInputs; |
| 2668 | for (unsigned I = 0; I < N; ++I) { |
| 2669 | bool IsSystem = I >= NumUserInputs; |
| 2670 | InputFileInfo FI = readInputFileInfo(F, I+1); |
| 2671 | Listener->visitInputFile(FI.Filename, IsSystem, FI.Overridden, |
| 2672 | F.Kind == MK_ExplicitModule || |
| 2673 | F.Kind == MK_PrebuiltModule); |
| 2674 | } |
| 2675 | } |
| 2676 | |
| 2677 | return Success; |
| 2678 | } |
| 2679 | |
| 2680 | case llvm::BitstreamEntry::SubBlock: |
| 2681 | switch (Entry.ID) { |
| 2682 | case INPUT_FILES_BLOCK_ID: |
| 2683 | F.InputFilesCursor = Stream; |
| 2684 | if (llvm::Error Err = Stream.SkipBlock()) { |
| 2685 | Error(std::move(Err)); |
| 2686 | return Failure; |
| 2687 | } |
| 2688 | if (ReadBlockAbbrevs(F.InputFilesCursor, INPUT_FILES_BLOCK_ID)) { |
| 2689 | Error("malformed block record in AST file"); |
| 2690 | return Failure; |
| 2691 | } |
| 2692 | continue; |
| 2693 | |
| 2694 | case OPTIONS_BLOCK_ID: |
| 2695 | |
| 2696 | |
| 2697 | |
| 2698 | if (Listener && !ImportedBy) { |
| 2699 | |
| 2700 | |
| 2701 | |
| 2702 | |
| 2703 | |
| 2704 | bool AllowCompatibleConfigurationMismatch = |
| 2705 | F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule; |
| 2706 | |
| 2707 | ASTReadResult Result = |
| 2708 | ReadOptionsBlock(Stream, ClientLoadCapabilities, |
| 2709 | AllowCompatibleConfigurationMismatch, *Listener, |
| 2710 | SuggestedPredefines); |
| 2711 | if (Result == Failure) { |
| 2712 | Error("malformed block record in AST file"); |
| 2713 | return Result; |
| 2714 | } |
| 2715 | |
| 2716 | if (DisableValidation || |
| 2717 | (AllowConfigurationMismatch && Result == ConfigurationMismatch)) |
| 2718 | Result = Success; |
| 2719 | |
| 2720 | |
| 2721 | |
| 2722 | |
| 2723 | if (Result != Success) |
| 2724 | return Result; |
| 2725 | } else if (llvm::Error Err = Stream.SkipBlock()) { |
| 2726 | Error(std::move(Err)); |
| 2727 | return Failure; |
| 2728 | } |
| 2729 | continue; |
| 2730 | |
| 2731 | default: |
| 2732 | if (llvm::Error Err = Stream.SkipBlock()) { |
| 2733 | Error(std::move(Err)); |
| 2734 | return Failure; |
| 2735 | } |
| 2736 | continue; |
| 2737 | } |
| 2738 | |
| 2739 | case llvm::BitstreamEntry::Record: |
| 2740 | |
| 2741 | break; |
| 2742 | } |
| 2743 | |
| 2744 | |
| 2745 | Record.clear(); |
| 2746 | StringRef Blob; |
| 2747 | Expected<unsigned> MaybeRecordType = |
| 2748 | Stream.readRecord(Entry.ID, Record, &Blob); |
| 2749 | if (!MaybeRecordType) { |
| 2750 | Error(MaybeRecordType.takeError()); |
| 2751 | return Failure; |
| 2752 | } |
| 2753 | switch ((ControlRecordTypes)MaybeRecordType.get()) { |
| 2754 | case METADATA: { |
| 2755 | if (Record[0] != VERSION_MAJOR && !DisableValidation) { |
| 2756 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
| 2757 | Diag(Record[0] < VERSION_MAJOR? diag::err_pch_version_too_old |
| 2758 | : diag::err_pch_version_too_new); |
| 2759 | return VersionMismatch; |
| 2760 | } |
| 2761 | |
| 2762 | bool hasErrors = Record[6]; |
| 2763 | if (hasErrors && !DisableValidation) { |
| 2764 | |
| 2765 | |
| 2766 | if ((ClientLoadCapabilities & ARR_TreatModuleWithErrorsAsOutOfDate) && |
| 2767 | canRecoverFromOutOfDate(F.FileName, ClientLoadCapabilities)) |
| 2768 | return OutOfDate; |
| 2769 | |
| 2770 | if (!AllowASTWithCompilerErrors) { |
| 2771 | Diag(diag::err_pch_with_compiler_errors); |
| 2772 | return HadErrors; |
| 2773 | } |
| 2774 | } |
| 2775 | if (hasErrors) { |
| 2776 | Diags.ErrorOccurred = true; |
| 2777 | Diags.UncompilableErrorOccurred = true; |
| 2778 | Diags.UnrecoverableErrorOccurred = true; |
| 2779 | } |
| 2780 | |
| 2781 | F.RelocatablePCH = Record[4]; |
| 2782 | |
| 2783 | if (F.RelocatablePCH) |
| 2784 | F.BaseDirectory = isysroot.empty() ? "/" : isysroot; |
| 2785 | |
| 2786 | F.HasTimestamps = Record[5]; |
| 2787 | |
| 2788 | const std::string &CurBranch = getClangFullRepositoryVersion(); |
| 2789 | StringRef ASTBranch = Blob; |
| 2790 | if (StringRef(CurBranch) != ASTBranch && !DisableValidation) { |
| 2791 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
| 2792 | Diag(diag::err_pch_different_branch) << ASTBranch << CurBranch; |
| 2793 | return VersionMismatch; |
| 2794 | } |
| 2795 | break; |
| 2796 | } |
| 2797 | |
| 2798 | case IMPORTS: { |
| 2799 | |
| 2800 | |
| 2801 | |
| 2802 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2803 | return Result; |
| 2804 | |
| 2805 | |
| 2806 | unsigned Idx = 0, N = Record.size(); |
| 2807 | while (Idx < N) { |
| 2808 | |
| 2809 | ModuleKind ImportedKind = (ModuleKind)Record[Idx++]; |
| 2810 | |
| 2811 | |
| 2812 | |
| 2813 | SourceLocation ImportLoc = |
| 2814 | ReadUntranslatedSourceLocation(Record[Idx++]); |
| 2815 | off_t StoredSize = (off_t)Record[Idx++]; |
| 2816 | time_t StoredModTime = (time_t)Record[Idx++]; |
| 2817 | auto FirstSignatureByte = Record.begin() + Idx; |
| 2818 | ASTFileSignature StoredSignature = ASTFileSignature::create( |
| 2819 | FirstSignatureByte, FirstSignatureByte + ASTFileSignature::size); |
| 2820 | Idx += ASTFileSignature::size; |
| 2821 | |
| 2822 | std::string ImportedName = ReadString(Record, Idx); |
| 2823 | std::string ImportedFile; |
| 2824 | |
| 2825 | |
| 2826 | |
| 2827 | |
| 2828 | |
| 2829 | |
| 2830 | if (ImportedKind == MK_PrebuiltModule || ImportedKind == MK_ExplicitModule) |
| 2831 | ImportedFile = PP.getHeaderSearchInfo().getPrebuiltModuleFileName( |
| 2832 | ImportedName, true); |
| 2833 | |
| 2834 | if (ImportedFile.empty()) |
| 2835 | |
| 2836 | |
| 2837 | ImportedFile = ReadPath(BaseDirectoryAsWritten, Record, Idx); |
| 2838 | else |
| 2839 | SkipPath(Record, Idx); |
| 2840 | |
| 2841 | |
| 2842 | |
| 2843 | unsigned Capabilities = ClientLoadCapabilities; |
| 2844 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 2845 | Capabilities &= ~ARR_Missing; |
| 2846 | |
| 2847 | |
| 2848 | auto Result = ReadASTCore(ImportedFile, ImportedKind, ImportLoc, &F, |
| 2849 | Loaded, StoredSize, StoredModTime, |
| 2850 | StoredSignature, Capabilities); |
| 2851 | |
| 2852 | |
| 2853 | bool recompilingFinalized = |
| 2854 | Result == OutOfDate && (Capabilities & ARR_OutOfDate) && |
| 2855 | getModuleManager().getModuleCache().isPCMFinal(F.FileName); |
| 2856 | if (isDiagnosedResult(Result, Capabilities) || recompilingFinalized) |
| 2857 | Diag(diag::note_module_file_imported_by) |
| 2858 | << F.FileName << !F.ModuleName.empty() << F.ModuleName; |
| 2859 | if (recompilingFinalized) |
| 2860 | Diag(diag::note_module_file_conflict); |
| 2861 | |
| 2862 | switch (Result) { |
| 2863 | case Failure: return Failure; |
| 2864 | |
| 2865 | case Missing: |
| 2866 | case OutOfDate: return OutOfDate; |
| 2867 | case VersionMismatch: return VersionMismatch; |
| 2868 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 2869 | case HadErrors: return HadErrors; |
| 2870 | case Success: break; |
| 2871 | } |
| 2872 | } |
| 2873 | break; |
| 2874 | } |
| 2875 | |
| 2876 | case ORIGINAL_FILE: |
| 2877 | F.OriginalSourceFileID = FileID::get(Record[0]); |
| 2878 | F.ActualOriginalSourceFileName = std::string(Blob); |
| 2879 | F.OriginalSourceFileName = F.ActualOriginalSourceFileName; |
| 2880 | ResolveImportedPath(F, F.OriginalSourceFileName); |
| 2881 | break; |
| 2882 | |
| 2883 | case ORIGINAL_FILE_ID: |
| 2884 | F.OriginalSourceFileID = FileID::get(Record[0]); |
| 2885 | break; |
| 2886 | |
| 2887 | case ORIGINAL_PCH_DIR: |
| 2888 | F.OriginalDir = std::string(Blob); |
| 2889 | break; |
| 2890 | |
| 2891 | case MODULE_NAME: |
| 2892 | F.ModuleName = std::string(Blob); |
| 2893 | Diag(diag::remark_module_import) |
| 2894 | << F.ModuleName << F.FileName << (ImportedBy ? true : false) |
| 2895 | << (ImportedBy ? StringRef(ImportedBy->ModuleName) : StringRef()); |
| 2896 | if (Listener) |
| 2897 | Listener->ReadModuleName(F.ModuleName); |
| 2898 | |
| 2899 | |
| 2900 | |
| 2901 | if (ASTReadResult Result = readUnhashedControlBlockOnce()) |
| 2902 | return Result; |
| 2903 | |
| 2904 | break; |
| 2905 | |
| 2906 | case MODULE_DIRECTORY: { |
| 2907 | |
| 2908 | |
| 2909 | BaseDirectoryAsWritten = Blob; |
| 2910 | assert(!F.ModuleName.empty() && |
| 2911 | "MODULE_DIRECTORY found before MODULE_NAME"); |
| 2912 | |
| 2913 | |
| 2914 | Module *M = PP.getHeaderSearchInfo().lookupModule( |
| 2915 | F.ModuleName, true, |
| 2916 | true); |
| 2917 | if (M && M->Directory) { |
| 2918 | |
| 2919 | |
| 2920 | |
| 2921 | if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation & |
| 2922 | DisableValidationForModuleKind::Module) && |
| 2923 | F.Kind != MK_ExplicitModule && F.Kind != MK_PrebuiltModule) { |
| 2924 | auto BuildDir = PP.getFileManager().getDirectory(Blob); |
| 2925 | if (!BuildDir || *BuildDir != M->Directory) { |
| 2926 | if (!canRecoverFromOutOfDate(F.FileName, ClientLoadCapabilities)) |
| 2927 | Diag(diag::err_imported_module_relocated) |
| 2928 | << F.ModuleName << Blob << M->Directory->getName(); |
| 2929 | return OutOfDate; |
| 2930 | } |
| 2931 | } |
| 2932 | F.BaseDirectory = std::string(M->Directory->getName()); |
| 2933 | } else { |
| 2934 | F.BaseDirectory = std::string(Blob); |
| 2935 | } |
| 2936 | break; |
| 2937 | } |
| 2938 | |
| 2939 | case MODULE_MAP_FILE: |
| 2940 | if (ASTReadResult Result = |
| 2941 | ReadModuleMapFileBlock(Record, F, ImportedBy, ClientLoadCapabilities)) |
| 2942 | return Result; |
| 2943 | break; |
| 2944 | |
| 2945 | case INPUT_FILE_OFFSETS: |
| 2946 | NumInputs = Record[0]; |
| 2947 | NumUserInputs = Record[1]; |
| 2948 | F.InputFileOffsets = |
| 2949 | (const llvm::support::unaligned_uint64_t *)Blob.data(); |
| 2950 | F.InputFilesLoaded.resize(NumInputs); |
| 2951 | F.NumUserInputFiles = NumUserInputs; |
| 2952 | break; |
| 2953 | } |
| 2954 | } |
| 2955 | } |
| 2956 | |
| 2957 | ASTReader::ASTReadResult |
| 2958 | ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { |
| 2959 | BitstreamCursor &Stream = F.Stream; |
| 2960 | |
| 2961 | if (llvm::Error Err = Stream.EnterSubBlock(AST_BLOCK_ID)) { |
| 2962 | Error(std::move(Err)); |
| 2963 | return Failure; |
| 2964 | } |
| 2965 | F.ASTBlockStartOffset = Stream.GetCurrentBitNo(); |
| 2966 | |
| 2967 | |
| 2968 | RecordData Record; |
| 2969 | while (true) { |
| 2970 | Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance(); |
| 2971 | if (!MaybeEntry) { |
| 2972 | Error(MaybeEntry.takeError()); |
| 2973 | return Failure; |
| 2974 | } |
| 2975 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 2976 | |
| 2977 | switch (Entry.Kind) { |
| 2978 | case llvm::BitstreamEntry::Error: |
| 2979 | Error("error at end of module block in AST file"); |
| 2980 | return Failure; |
| 2981 | case llvm::BitstreamEntry::EndBlock: |
| 2982 | |
| 2983 | |
| 2984 | |
| 2985 | |
| 2986 | |
| 2987 | if (ASTContext *Ctx = ContextObj) { |
| 2988 | DeclContext *DC = Ctx->getTranslationUnitDecl(); |
| 2989 | if (DC->hasExternalLexicalStorage() && !Ctx->getLangOpts().CPlusPlus) |
| 2990 | DC->setMustBuildLookupTable(); |
| 2991 | } |
| 2992 | |
| 2993 | return Success; |
| 2994 | case llvm::BitstreamEntry::SubBlock: |
| 2995 | switch (Entry.ID) { |
| 2996 | case DECLTYPES_BLOCK_ID: |
| 2997 | |
| 2998 | |
| 2999 | |
| 3000 | |
| 3001 | F.DeclsCursor = Stream; |
| 3002 | if (llvm::Error Err = Stream.SkipBlock()) { |
| 3003 | Error(std::move(Err)); |
| 3004 | return Failure; |
| 3005 | } |
| 3006 | if (ReadBlockAbbrevs(F.DeclsCursor, DECLTYPES_BLOCK_ID, |
| 3007 | &F.DeclsBlockStartOffset)) { |
| 3008 | Error("malformed block record in AST file"); |
| 3009 | return Failure; |
| 3010 | } |
| 3011 | break; |
| 3012 | |
| 3013 | case PREPROCESSOR_BLOCK_ID: |
| 3014 | F.MacroCursor = Stream; |
| 3015 | if (!PP.getExternalSource()) |
| 3016 | PP.setExternalSource(this); |
| 3017 | |
| 3018 | if (llvm::Error Err = Stream.SkipBlock()) { |
| 3019 | Error(std::move(Err)); |
| 3020 | return Failure; |
| 3021 | } |
| 3022 | if (ReadBlockAbbrevs(F.MacroCursor, PREPROCESSOR_BLOCK_ID)) { |
| 3023 | Error("malformed block record in AST file"); |
| 3024 | return Failure; |
| 3025 | } |
| 3026 | F.MacroStartOffset = F.MacroCursor.GetCurrentBitNo(); |
| 3027 | break; |
| 3028 | |
| 3029 | case PREPROCESSOR_DETAIL_BLOCK_ID: |
| 3030 | F.PreprocessorDetailCursor = Stream; |
| 3031 | |
| 3032 | if (llvm::Error Err = Stream.SkipBlock()) { |
| 3033 | Error(std::move(Err)); |
| 3034 | return Failure; |
| 3035 | } |
| 3036 | if (ReadBlockAbbrevs(F.PreprocessorDetailCursor, |
| 3037 | PREPROCESSOR_DETAIL_BLOCK_ID)) { |
| 3038 | Error("malformed preprocessor detail record in AST file"); |
| 3039 | return Failure; |
| 3040 | } |
| 3041 | F.PreprocessorDetailStartOffset |
| 3042 | = F.PreprocessorDetailCursor.GetCurrentBitNo(); |
| 3043 | |
| 3044 | if (!PP.getPreprocessingRecord()) |
| 3045 | PP.createPreprocessingRecord(); |
| 3046 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 3047 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 3048 | break; |
| 3049 | |
| 3050 | case SOURCE_MANAGER_BLOCK_ID: |
| 3051 | if (ReadSourceManagerBlock(F)) |
| 3052 | return Failure; |
| 3053 | break; |
| 3054 | |
| 3055 | case SUBMODULE_BLOCK_ID: |
| 3056 | if (ASTReadResult Result = |
| 3057 | ReadSubmoduleBlock(F, ClientLoadCapabilities)) |
| 3058 | return Result; |
| 3059 | break; |
| 3060 | |
| 3061 | case COMMENTS_BLOCK_ID: { |
| 3062 | BitstreamCursor C = Stream; |
| 3063 | |
| 3064 | if (llvm::Error Err = Stream.SkipBlock()) { |
| 3065 | Error(std::move(Err)); |
| 3066 | return Failure; |
| 3067 | } |
| 3068 | if (ReadBlockAbbrevs(C, COMMENTS_BLOCK_ID)) { |
| 3069 | Error("malformed comments block in AST file"); |
| 3070 | return Failure; |
| 3071 | } |
| 3072 | CommentsCursors.push_back(std::make_pair(C, &F)); |
| 3073 | break; |
| 3074 | } |
| 3075 | |
| 3076 | default: |
| 3077 | if (llvm::Error Err = Stream.SkipBlock()) { |
| 3078 | Error(std::move(Err)); |
| 3079 | return Failure; |
| 3080 | } |
| 3081 | break; |
| 3082 | } |
| 3083 | continue; |
| 3084 | |
| 3085 | case llvm::BitstreamEntry::Record: |
| 3086 | |
| 3087 | break; |
| 3088 | } |
| 3089 | |
| 3090 | |
| 3091 | Record.clear(); |
| 3092 | StringRef Blob; |
| 3093 | Expected<unsigned> MaybeRecordType = |
| 3094 | Stream.readRecord(Entry.ID, Record, &Blob); |
| 3095 | if (!MaybeRecordType) { |
| 3096 | Error(MaybeRecordType.takeError()); |
| 3097 | return Failure; |
| 3098 | } |
| 3099 | ASTRecordTypes RecordType = (ASTRecordTypes)MaybeRecordType.get(); |
| 3100 | |
| 3101 | |
| 3102 | if (!ContextObj) { |
| 3103 | switch (RecordType) { |
| 3104 | case IDENTIFIER_TABLE: |
| 3105 | case IDENTIFIER_OFFSET: |
| 3106 | case INTERESTING_IDENTIFIERS: |
| 3107 | case STATISTICS: |
| 3108 | case PP_CONDITIONAL_STACK: |
| 3109 | case PP_COUNTER_VALUE: |
| 3110 | case SOURCE_LOCATION_OFFSETS: |
| 3111 | case MODULE_OFFSET_MAP: |
| 3112 | case SOURCE_MANAGER_LINE_TABLE: |
| 3113 | case SOURCE_LOCATION_PRELOADS: |
| 3114 | case PPD_ENTITIES_OFFSETS: |
| 3115 | case HEADER_SEARCH_TABLE: |
| 3116 | case IMPORTED_MODULES: |
| 3117 | case MACRO_OFFSET: |
| 3118 | break; |
| 3119 | default: |
| 3120 | continue; |
| 3121 | } |
| 3122 | } |
| 3123 | |
| 3124 | switch (RecordType) { |
| 3125 | default: |
| 3126 | break; |
| 3127 | |
| 3128 | case TYPE_OFFSET: { |
| 3129 | if (F.LocalNumTypes != 0) { |
| 3130 | Error("duplicate TYPE_OFFSET record in AST file"); |
| 3131 | return Failure; |
| 3132 | } |
| 3133 | F.TypeOffsets = reinterpret_cast<const UnderalignedInt64 *>(Blob.data()); |
| 3134 | F.LocalNumTypes = Record[0]; |
| 3135 | unsigned LocalBaseTypeIndex = Record[1]; |
| 3136 | F.BaseTypeIndex = getTotalNumTypes(); |
| 3137 | |
| 3138 | if (F.LocalNumTypes > 0) { |
| 3139 | |
| 3140 | GlobalTypeMap.insert(std::make_pair(getTotalNumTypes(), &F)); |
| 3141 | |
| 3142 | |
| 3143 | F.TypeRemap.insertOrReplace( |
| 3144 | std::make_pair(LocalBaseTypeIndex, |
| 3145 | F.BaseTypeIndex - LocalBaseTypeIndex)); |
| 3146 | |
| 3147 | TypesLoaded.resize(TypesLoaded.size() + F.LocalNumTypes); |
| 3148 | } |
| 3149 | break; |
| 3150 | } |
| 3151 | |
| 3152 | case DECL_OFFSET: { |
| 3153 | if (F.LocalNumDecls != 0) { |
| 3154 | Error("duplicate DECL_OFFSET record in AST file"); |
| 3155 | return Failure; |
| 3156 | } |
| 3157 | F.DeclOffsets = (const DeclOffset *)Blob.data(); |
| 3158 | F.LocalNumDecls = Record[0]; |
| 3159 | unsigned LocalBaseDeclID = Record[1]; |
| 3160 | F.BaseDeclID = getTotalNumDecls(); |
| 3161 | |
| 3162 | if (F.LocalNumDecls > 0) { |
| 3163 | |
| 3164 | |
| 3165 | GlobalDeclMap.insert( |
| 3166 | std::make_pair(getTotalNumDecls() + NUM_PREDEF_DECL_IDS, &F)); |
| 3167 | |
| 3168 | |
| 3169 | |
| 3170 | F.DeclRemap.insertOrReplace( |
| 3171 | std::make_pair(LocalBaseDeclID, F.BaseDeclID - LocalBaseDeclID)); |
| 3172 | |
| 3173 | |
| 3174 | |
| 3175 | F.GlobalToLocalDeclIDs[&F] = LocalBaseDeclID; |
| 3176 | |
| 3177 | DeclsLoaded.resize(DeclsLoaded.size() + F.LocalNumDecls); |
| 3178 | } |
| 3179 | break; |
| 3180 | } |
| 3181 | |
| 3182 | case TU_UPDATE_LEXICAL: { |
| 3183 | DeclContext *TU = ContextObj->getTranslationUnitDecl(); |
| 3184 | LexicalContents Contents( |
| 3185 | reinterpret_cast<const llvm::support::unaligned_uint32_t *>( |
| 3186 | Blob.data()), |
| 3187 | static_cast<unsigned int>(Blob.size() / 4)); |
| 3188 | TULexicalDecls.push_back(std::make_pair(&F, Contents)); |
| 3189 | TU->setHasExternalLexicalStorage(true); |
| 3190 | break; |
| 3191 | } |
| 3192 | |
| 3193 | case UPDATE_VISIBLE: { |
| 3194 | unsigned Idx = 0; |
| 3195 | serialization::DeclID ID = ReadDeclID(F, Record, Idx); |
| 3196 | auto *Data = (const unsigned char*)Blob.data(); |
| 3197 | PendingVisibleUpdates[ID].push_back(PendingVisibleUpdate{&F, Data}); |
| 3198 | |
| 3199 | |
| 3200 | if (Decl *D = GetExistingDecl(ID)) |
| 3201 | PendingUpdateRecords.push_back( |
| 3202 | PendingUpdateRecord(ID, D, false)); |
| 3203 | break; |
| 3204 | } |
| 3205 | |
| 3206 | case IDENTIFIER_TABLE: |
| 3207 | F.IdentifierTableData = |
| 3208 | reinterpret_cast<const unsigned char *>(Blob.data()); |
| 3209 | if (Record[0]) { |
| 3210 | F.IdentifierLookupTable = ASTIdentifierLookupTable::Create( |
| 3211 | F.IdentifierTableData + Record[0], |
| 3212 | F.IdentifierTableData + sizeof(uint32_t), |
| 3213 | F.IdentifierTableData, |
| 3214 | ASTIdentifierLookupTrait(*this, F)); |
| 3215 | |
| 3216 | PP.getIdentifierTable().setExternalIdentifierLookup(this); |
| 3217 | } |
| 3218 | break; |
| 3219 | |
| 3220 | case IDENTIFIER_OFFSET: { |
| 3221 | if (F.LocalNumIdentifiers != 0) { |
| 3222 | Error("duplicate IDENTIFIER_OFFSET record in AST file"); |
| 3223 | return Failure; |
| 3224 | } |
| 3225 | F.IdentifierOffsets = (const uint32_t *)Blob.data(); |
| 3226 | F.LocalNumIdentifiers = Record[0]; |
| 3227 | unsigned LocalBaseIdentifierID = Record[1]; |
| 3228 | F.BaseIdentifierID = getTotalNumIdentifiers(); |
| 3229 | |
| 3230 | if (F.LocalNumIdentifiers > 0) { |
| 3231 | |
| 3232 | |
| 3233 | GlobalIdentifierMap.insert(std::make_pair(getTotalNumIdentifiers() + 1, |
| 3234 | &F)); |
| 3235 | |
| 3236 | |
| 3237 | |
| 3238 | F.IdentifierRemap.insertOrReplace( |
| 3239 | std::make_pair(LocalBaseIdentifierID, |
| 3240 | F.BaseIdentifierID - LocalBaseIdentifierID)); |
| 3241 | |
| 3242 | IdentifiersLoaded.resize(IdentifiersLoaded.size() |
| 3243 | + F.LocalNumIdentifiers); |
| 3244 | } |
| 3245 | break; |
| 3246 | } |
| 3247 | |
| 3248 | case INTERESTING_IDENTIFIERS: |
| 3249 | F.PreloadIdentifierOffsets.assign(Record.begin(), Record.end()); |
| 3250 | break; |
| 3251 | |
| 3252 | case EAGERLY_DESERIALIZED_DECLS: |
| 3253 | |
| 3254 | |
| 3255 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3256 | EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 3257 | break; |
| 3258 | |
| 3259 | case MODULAR_CODEGEN_DECLS: |
| 3260 | |
| 3261 | |
| 3262 | if (F.Kind == MK_MainFile || |
| 3263 | getContext().getLangOpts().BuildingPCHWithObjectFile) |
| 3264 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3265 | EagerlyDeserializedDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 3266 | break; |
| 3267 | |
| 3268 | case SPECIAL_TYPES: |
| 3269 | if (SpecialTypes.empty()) { |
| 3270 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3271 | SpecialTypes.push_back(getGlobalTypeID(F, Record[I])); |
| 3272 | break; |
| 3273 | } |
| 3274 | |
| 3275 | if (SpecialTypes.size() != Record.size()) { |
| 3276 | Error("invalid special-types record"); |
| 3277 | return Failure; |
| 3278 | } |
| 3279 | |
| 3280 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 3281 | serialization::TypeID ID = getGlobalTypeID(F, Record[I]); |
| 3282 | if (!SpecialTypes[I]) |
| 3283 | SpecialTypes[I] = ID; |
| 3284 | |
| 3285 | |
| 3286 | } |
| 3287 | break; |
| 3288 | |
| 3289 | case STATISTICS: |
| 3290 | TotalNumStatements += Record[0]; |
| 3291 | TotalNumMacros += Record[1]; |
| 3292 | TotalLexicalDeclContexts += Record[2]; |
| 3293 | TotalVisibleDeclContexts += Record[3]; |
| 3294 | break; |
| 3295 | |
| 3296 | case UNUSED_FILESCOPED_DECLS: |
| 3297 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3298 | UnusedFileScopedDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 3299 | break; |
| 3300 | |
| 3301 | case DELEGATING_CTORS: |
| 3302 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3303 | DelegatingCtorDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 3304 | break; |
| 3305 | |
| 3306 | case WEAK_UNDECLARED_IDENTIFIERS: |
| 3307 | if (Record.size() % 4 != 0) { |
| 3308 | Error("invalid weak identifiers record"); |
| 3309 | return Failure; |
| 3310 | } |
| 3311 | |
| 3312 | |
| 3313 | |
| 3314 | WeakUndeclaredIdentifiers.clear(); |
| 3315 | |
| 3316 | |
| 3317 | for (unsigned I = 0, N = Record.size(); I < N; ) { |
| 3318 | WeakUndeclaredIdentifiers.push_back( |
| 3319 | getGlobalIdentifierID(F, Record[I++])); |
| 3320 | WeakUndeclaredIdentifiers.push_back( |
| 3321 | getGlobalIdentifierID(F, Record[I++])); |
| 3322 | WeakUndeclaredIdentifiers.push_back( |
| 3323 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3324 | WeakUndeclaredIdentifiers.push_back(Record[I++]); |
| 3325 | } |
| 3326 | break; |
| 3327 | |
| 3328 | case SELECTOR_OFFSETS: { |
| 3329 | F.SelectorOffsets = (const uint32_t *)Blob.data(); |
| 3330 | F.LocalNumSelectors = Record[0]; |
| 3331 | unsigned LocalBaseSelectorID = Record[1]; |
| 3332 | F.BaseSelectorID = getTotalNumSelectors(); |
| 3333 | |
| 3334 | if (F.LocalNumSelectors > 0) { |
| 3335 | |
| 3336 | |
| 3337 | GlobalSelectorMap.insert(std::make_pair(getTotalNumSelectors()+1, &F)); |
| 3338 | |
| 3339 | |
| 3340 | |
| 3341 | F.SelectorRemap.insertOrReplace( |
| 3342 | std::make_pair(LocalBaseSelectorID, |
| 3343 | F.BaseSelectorID - LocalBaseSelectorID)); |
| 3344 | |
| 3345 | SelectorsLoaded.resize(SelectorsLoaded.size() + F.LocalNumSelectors); |
| 3346 | } |
| 3347 | break; |
| 3348 | } |
| 3349 | |
| 3350 | case METHOD_POOL: |
| 3351 | F.SelectorLookupTableData = (const unsigned char *)Blob.data(); |
| 3352 | if (Record[0]) |
| 3353 | F.SelectorLookupTable |
| 3354 | = ASTSelectorLookupTable::Create( |
| 3355 | F.SelectorLookupTableData + Record[0], |
| 3356 | F.SelectorLookupTableData, |
| 3357 | ASTSelectorLookupTrait(*this, F)); |
| 3358 | TotalNumMethodPoolEntries += Record[1]; |
| 3359 | break; |
| 3360 | |
| 3361 | case REFERENCED_SELECTOR_POOL: |
| 3362 | if (!Record.empty()) { |
| 3363 | for (unsigned Idx = 0, N = Record.size() - 1; Idx < N; ) { |
| 3364 | ReferencedSelectorsData.push_back(getGlobalSelectorID(F, |
| 3365 | Record[Idx++])); |
| 3366 | ReferencedSelectorsData.push_back(ReadSourceLocation(F, Record, Idx). |
| 3367 | getRawEncoding()); |
| 3368 | } |
| 3369 | } |
| 3370 | break; |
| 3371 | |
| 3372 | case PP_CONDITIONAL_STACK: |
| 3373 | if (!Record.empty()) { |
| 3374 | unsigned Idx = 0, End = Record.size() - 1; |
| 3375 | bool ReachedEOFWhileSkipping = Record[Idx++]; |
| 3376 | llvm::Optional<Preprocessor::PreambleSkipInfo> SkipInfo; |
| 3377 | if (ReachedEOFWhileSkipping) { |
| 3378 | SourceLocation HashToken = ReadSourceLocation(F, Record, Idx); |
| 3379 | SourceLocation IfTokenLoc = ReadSourceLocation(F, Record, Idx); |
| 3380 | bool FoundNonSkipPortion = Record[Idx++]; |
| 3381 | bool FoundElse = Record[Idx++]; |
| 3382 | SourceLocation ElseLoc = ReadSourceLocation(F, Record, Idx); |
| 3383 | SkipInfo.emplace(HashToken, IfTokenLoc, FoundNonSkipPortion, |
| 3384 | FoundElse, ElseLoc); |
| 3385 | } |
| 3386 | SmallVector<PPConditionalInfo, 4> ConditionalStack; |
| 3387 | while (Idx < End) { |
| 3388 | auto Loc = ReadSourceLocation(F, Record, Idx); |
| 3389 | bool WasSkipping = Record[Idx++]; |
| 3390 | bool FoundNonSkip = Record[Idx++]; |
| 3391 | bool FoundElse = Record[Idx++]; |
| 3392 | ConditionalStack.push_back( |
| 3393 | {Loc, WasSkipping, FoundNonSkip, FoundElse}); |
| 3394 | } |
| 3395 | PP.setReplayablePreambleConditionalStack(ConditionalStack, SkipInfo); |
| 3396 | } |
| 3397 | break; |
| 3398 | |
| 3399 | case PP_COUNTER_VALUE: |
| 3400 | if (!Record.empty() && Listener) |
| 3401 | Listener->ReadCounter(F, Record[0]); |
| 3402 | break; |
| 3403 | |
| 3404 | case FILE_SORTED_DECLS: |
| 3405 | F.FileSortedDecls = (const DeclID *)Blob.data(); |
| 3406 | F.NumFileSortedDecls = Record[0]; |
| 3407 | break; |
| 3408 | |
| 3409 | case SOURCE_LOCATION_OFFSETS: { |
| 3410 | F.SLocEntryOffsets = (const uint32_t *)Blob.data(); |
| 3411 | F.LocalNumSLocEntries = Record[0]; |
| 3412 | SourceLocation::UIntTy SLocSpaceSize = Record[1]; |
| 3413 | F.SLocEntryOffsetsBase = Record[2] + F.SourceManagerBlockStartOffset; |
| 3414 | std::tie(F.SLocEntryBaseID, F.SLocEntryBaseOffset) = |
| 3415 | SourceMgr.AllocateLoadedSLocEntries(F.LocalNumSLocEntries, |
| 3416 | SLocSpaceSize); |
| 3417 | if (!F.SLocEntryBaseID) { |
| 3418 | Error("ran out of source locations"); |
| 3419 | break; |
| 3420 | } |
| 3421 | |
| 3422 | |
| 3423 | |
| 3424 | unsigned RangeStart = |
| 3425 | unsigned(-F.SLocEntryBaseID) - F.LocalNumSLocEntries + 1; |
| 3426 | GlobalSLocEntryMap.insert(std::make_pair(RangeStart, &F)); |
| 3427 | F.FirstLoc = SourceLocation::getFromRawEncoding(F.SLocEntryBaseOffset); |
| 3428 | |
| 3429 | |
| 3430 | assert((F.SLocEntryBaseOffset & SourceLocation::MacroIDBit) == 0); |
| 3431 | GlobalSLocOffsetMap.insert( |
| 3432 | std::make_pair(SourceManager::MaxLoadedOffset - F.SLocEntryBaseOffset |
| 3433 | - SLocSpaceSize,&F)); |
| 3434 | |
| 3435 | |
| 3436 | |
| 3437 | F.SLocRemap.insertOrReplace(std::make_pair(0U, 0)); |
| 3438 | |
| 3439 | F.SLocRemap.insertOrReplace(std::make_pair( |
| 3440 | 2U, static_cast<SourceLocation::IntTy>(F.SLocEntryBaseOffset - 2))); |
| 3441 | |
| 3442 | TotalNumSLocEntries += F.LocalNumSLocEntries; |
| 3443 | break; |
| 3444 | } |
| 3445 | |
| 3446 | case MODULE_OFFSET_MAP: |
| 3447 | F.ModuleOffsetMap = Blob; |
| 3448 | break; |
| 3449 | |
| 3450 | case SOURCE_MANAGER_LINE_TABLE: |
| 3451 | if (ParseLineTable(F, Record)) { |
| 3452 | Error("malformed SOURCE_MANAGER_LINE_TABLE in AST file"); |
| 3453 | return Failure; |
| 3454 | } |
| 3455 | break; |
| 3456 | |
| 3457 | case SOURCE_LOCATION_PRELOADS: { |
| 3458 | |
| 3459 | |
| 3460 | if (!F.PreloadSLocEntries.empty()) { |
| 3461 | Error("Multiple SOURCE_LOCATION_PRELOADS records in AST file"); |
| 3462 | return Failure; |
| 3463 | } |
| 3464 | |
| 3465 | F.PreloadSLocEntries.swap(Record); |
| 3466 | break; |
| 3467 | } |
| 3468 | |
| 3469 | case EXT_VECTOR_DECLS: |
| 3470 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3471 | ExtVectorDecls.push_back(getGlobalDeclID(F, Record[I])); |
| 3472 | break; |
| 3473 | |
| 3474 | case VTABLE_USES: |
| 3475 | if (Record.size() % 3 != 0) { |
| 3476 | Error("Invalid VTABLE_USES record"); |
| 3477 | return Failure; |
| 3478 | } |
| 3479 | |
| 3480 | |
| 3481 | |
| 3482 | |
| 3483 | VTableUses.clear(); |
| 3484 | |
| 3485 | for (unsigned Idx = 0, N = Record.size(); Idx != N; ) { |
| 3486 | VTableUses.push_back(getGlobalDeclID(F, Record[Idx++])); |
| 3487 | VTableUses.push_back( |
| 3488 | ReadSourceLocation(F, Record, Idx).getRawEncoding()); |
| 3489 | VTableUses.push_back(Record[Idx++]); |
| 3490 | } |
| 3491 | break; |
| 3492 | |
| 3493 | case PENDING_IMPLICIT_INSTANTIATIONS: |
| 3494 | if (PendingInstantiations.size() % 2 != 0) { |
| 3495 | Error("Invalid existing PendingInstantiations"); |
| 3496 | return Failure; |
| 3497 | } |
| 3498 | |
| 3499 | if (Record.size() % 2 != 0) { |
| 3500 | Error("Invalid PENDING_IMPLICIT_INSTANTIATIONS block"); |
| 3501 | return Failure; |
| 3502 | } |
| 3503 | |
| 3504 | for (unsigned I = 0, N = Record.size(); I != N; ) { |
| 3505 | PendingInstantiations.push_back(getGlobalDeclID(F, Record[I++])); |
| 3506 | PendingInstantiations.push_back( |
| 3507 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3508 | } |
| 3509 | break; |
| 3510 | |
| 3511 | case SEMA_DECL_REFS: |
| 3512 | if (Record.size() != 3) { |
| 3513 | Error("Invalid SEMA_DECL_REFS block"); |
| 3514 | return Failure; |
| 3515 | } |
| 3516 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3517 | SemaDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
| 3518 | break; |
| 3519 | |
| 3520 | case PPD_ENTITIES_OFFSETS: { |
| 3521 | F.PreprocessedEntityOffsets = (const PPEntityOffset *)Blob.data(); |
| 3522 | assert(Blob.size() % sizeof(PPEntityOffset) == 0); |
| 3523 | F.NumPreprocessedEntities = Blob.size() / sizeof(PPEntityOffset); |
| 3524 | |
| 3525 | unsigned LocalBasePreprocessedEntityID = Record[0]; |
| 3526 | |
| 3527 | unsigned StartingID; |
| 3528 | if (!PP.getPreprocessingRecord()) |
| 3529 | PP.createPreprocessingRecord(); |
| 3530 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 3531 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 3532 | StartingID |
| 3533 | = PP.getPreprocessingRecord() |
| 3534 | ->allocateLoadedEntities(F.NumPreprocessedEntities); |
| 3535 | F.BasePreprocessedEntityID = StartingID; |
| 3536 | |
| 3537 | if (F.NumPreprocessedEntities > 0) { |
| 3538 | |
| 3539 | |
| 3540 | GlobalPreprocessedEntityMap.insert(std::make_pair(StartingID, &F)); |
| 3541 | |
| 3542 | |
| 3543 | |
| 3544 | F.PreprocessedEntityRemap.insertOrReplace( |
| 3545 | std::make_pair(LocalBasePreprocessedEntityID, |
| 3546 | F.BasePreprocessedEntityID - LocalBasePreprocessedEntityID)); |
| 3547 | } |
| 3548 | |
| 3549 | break; |
| 3550 | } |
| 3551 | |
| 3552 | case PPD_SKIPPED_RANGES: { |
| 3553 | F.PreprocessedSkippedRangeOffsets = (const PPSkippedRange*)Blob.data(); |
| 3554 | assert(Blob.size() % sizeof(PPSkippedRange) == 0); |
| 3555 | F.NumPreprocessedSkippedRanges = Blob.size() / sizeof(PPSkippedRange); |
| 3556 | |
| 3557 | if (!PP.getPreprocessingRecord()) |
| 3558 | PP.createPreprocessingRecord(); |
| 3559 | if (!PP.getPreprocessingRecord()->getExternalSource()) |
| 3560 | PP.getPreprocessingRecord()->SetExternalSource(*this); |
| 3561 | F.BasePreprocessedSkippedRangeID = PP.getPreprocessingRecord() |
| 3562 | ->allocateSkippedRanges(F.NumPreprocessedSkippedRanges); |
| 3563 | |
| 3564 | if (F.NumPreprocessedSkippedRanges > 0) |
| 3565 | GlobalSkippedRangeMap.insert( |
| 3566 | std::make_pair(F.BasePreprocessedSkippedRangeID, &F)); |
| 3567 | break; |
| 3568 | } |
| 3569 | |
| 3570 | case DECL_UPDATE_OFFSETS: |
| 3571 | if (Record.size() % 2 != 0) { |
| 3572 | Error("invalid DECL_UPDATE_OFFSETS block in AST file"); |
| 3573 | return Failure; |
| 3574 | } |
| 3575 | for (unsigned I = 0, N = Record.size(); I != N; I += 2) { |
| 3576 | GlobalDeclID ID = getGlobalDeclID(F, Record[I]); |
| 3577 | DeclUpdateOffsets[ID].push_back(std::make_pair(&F, Record[I + 1])); |
| 3578 | |
| 3579 | |
| 3580 | |
| 3581 | if (Decl *D = GetExistingDecl(ID)) |
| 3582 | PendingUpdateRecords.push_back( |
| 3583 | PendingUpdateRecord(ID, D, false)); |
| 3584 | } |
| 3585 | break; |
| 3586 | |
| 3587 | case OBJC_CATEGORIES_MAP: |
| 3588 | if (F.LocalNumObjCCategoriesInMap != 0) { |
| 3589 | Error("duplicate OBJC_CATEGORIES_MAP record in AST file"); |
| 3590 | return Failure; |
| 3591 | } |
| 3592 | |
| 3593 | F.LocalNumObjCCategoriesInMap = Record[0]; |
| 3594 | F.ObjCCategoriesMap = (const ObjCCategoriesInfo *)Blob.data(); |
| 3595 | break; |
| 3596 | |
| 3597 | case OBJC_CATEGORIES: |
| 3598 | F.ObjCCategories.swap(Record); |
| 3599 | break; |
| 3600 | |
| 3601 | case CUDA_SPECIAL_DECL_REFS: |
| 3602 | |
| 3603 | |
| 3604 | CUDASpecialDeclRefs.clear(); |
| 3605 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3606 | CUDASpecialDeclRefs.push_back(getGlobalDeclID(F, Record[I])); |
| 3607 | break; |
| 3608 | |
| 3609 | case HEADER_SEARCH_TABLE: |
| 3610 | F.HeaderFileInfoTableData = Blob.data(); |
| 3611 | F.LocalNumHeaderFileInfos = Record[1]; |
| 3612 | if (Record[0]) { |
| 3613 | F.HeaderFileInfoTable |
| 3614 | = HeaderFileInfoLookupTable::Create( |
| 3615 | (const unsigned char *)F.HeaderFileInfoTableData + Record[0], |
| 3616 | (const unsigned char *)F.HeaderFileInfoTableData, |
| 3617 | HeaderFileInfoTrait(*this, F, |
| 3618 | &PP.getHeaderSearchInfo(), |
| 3619 | Blob.data() + Record[2])); |
| 3620 | |
| 3621 | PP.getHeaderSearchInfo().SetExternalSource(this); |
| 3622 | if (!PP.getHeaderSearchInfo().getExternalLookup()) |
| 3623 | PP.getHeaderSearchInfo().SetExternalLookup(this); |
| 3624 | } |
| 3625 | break; |
| 3626 | |
| 3627 | case FP_PRAGMA_OPTIONS: |
| 3628 | |
| 3629 | FPPragmaOptions.swap(Record); |
| 3630 | break; |
| 3631 | |
| 3632 | case OPENCL_EXTENSIONS: |
| 3633 | for (unsigned I = 0, E = Record.size(); I != E; ) { |
| 3634 | auto Name = ReadString(Record, I); |
| 3635 | auto &OptInfo = OpenCLExtensions.OptMap[Name]; |
| 3636 | OptInfo.Supported = Record[I++] != 0; |
| 3637 | OptInfo.Enabled = Record[I++] != 0; |
| 3638 | OptInfo.WithPragma = Record[I++] != 0; |
| 3639 | OptInfo.Avail = Record[I++]; |
| 3640 | OptInfo.Core = Record[I++]; |
| 3641 | OptInfo.Opt = Record[I++]; |
| 3642 | } |
| 3643 | break; |
| 3644 | |
| 3645 | case TENTATIVE_DEFINITIONS: |
| 3646 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3647 | TentativeDefinitions.push_back(getGlobalDeclID(F, Record[I])); |
| 3648 | break; |
| 3649 | |
| 3650 | case KNOWN_NAMESPACES: |
| 3651 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3652 | KnownNamespaces.push_back(getGlobalDeclID(F, Record[I])); |
| 3653 | break; |
| 3654 | |
| 3655 | case UNDEFINED_BUT_USED: |
| 3656 | if (UndefinedButUsed.size() % 2 != 0) { |
| 3657 | Error("Invalid existing UndefinedButUsed"); |
| 3658 | return Failure; |
| 3659 | } |
| 3660 | |
| 3661 | if (Record.size() % 2 != 0) { |
| 3662 | Error("invalid undefined-but-used record"); |
| 3663 | return Failure; |
| 3664 | } |
| 3665 | for (unsigned I = 0, N = Record.size(); I != N; ) { |
| 3666 | UndefinedButUsed.push_back(getGlobalDeclID(F, Record[I++])); |
| 3667 | UndefinedButUsed.push_back( |
| 3668 | ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3669 | } |
| 3670 | break; |
| 3671 | |
| 3672 | case DELETE_EXPRS_TO_ANALYZE: |
| 3673 | for (unsigned I = 0, N = Record.size(); I != N;) { |
| 3674 | DelayedDeleteExprs.push_back(getGlobalDeclID(F, Record[I++])); |
| 3675 | const uint64_t Count = Record[I++]; |
| 3676 | DelayedDeleteExprs.push_back(Count); |
| 3677 | for (uint64_t C = 0; C < Count; ++C) { |
| 3678 | DelayedDeleteExprs.push_back(ReadSourceLocation(F, Record, I).getRawEncoding()); |
| 3679 | bool IsArrayForm = Record[I++] == 1; |
| 3680 | DelayedDeleteExprs.push_back(IsArrayForm); |
| 3681 | } |
| 3682 | } |
| 3683 | break; |
| 3684 | |
| 3685 | case IMPORTED_MODULES: |
| 3686 | if (!F.isModule()) { |
| 3687 | |
| 3688 | |
| 3689 | |
| 3690 | for (unsigned I = 0, N = Record.size(); I != N; ) { |
| 3691 | unsigned GlobalID = getGlobalSubmoduleID(F, Record[I++]); |
| 3692 | SourceLocation Loc = ReadSourceLocation(F, Record, I); |
| 3693 | if (GlobalID) { |
| 3694 | ImportedModules.push_back(ImportedSubmodule(GlobalID, Loc)); |
| 3695 | if (DeserializationListener) |
| 3696 | DeserializationListener->ModuleImportRead(GlobalID, Loc); |
| 3697 | } |
| 3698 | } |
| 3699 | } |
| 3700 | break; |
| 3701 | |
| 3702 | case MACRO_OFFSET: { |
| 3703 | if (F.LocalNumMacros != 0) { |
| 3704 | Error("duplicate MACRO_OFFSET record in AST file"); |
| 3705 | return Failure; |
| 3706 | } |
| 3707 | F.MacroOffsets = (const uint32_t *)Blob.data(); |
| 3708 | F.LocalNumMacros = Record[0]; |
| 3709 | unsigned LocalBaseMacroID = Record[1]; |
| 3710 | F.MacroOffsetsBase = Record[2] + F.ASTBlockStartOffset; |
| 3711 | F.BaseMacroID = getTotalNumMacros(); |
| 3712 | |
| 3713 | if (F.LocalNumMacros > 0) { |
| 3714 | |
| 3715 | GlobalMacroMap.insert(std::make_pair(getTotalNumMacros() + 1, &F)); |
| 3716 | |
| 3717 | |
| 3718 | F.MacroRemap.insertOrReplace( |
| 3719 | std::make_pair(LocalBaseMacroID, |
| 3720 | F.BaseMacroID - LocalBaseMacroID)); |
| 3721 | |
| 3722 | MacrosLoaded.resize(MacrosLoaded.size() + F.LocalNumMacros); |
| 3723 | } |
| 3724 | break; |
| 3725 | } |
| 3726 | |
| 3727 | case LATE_PARSED_TEMPLATE: |
| 3728 | LateParsedTemplates.emplace_back( |
| 3729 | std::piecewise_construct, std::forward_as_tuple(&F), |
| 3730 | std::forward_as_tuple(Record.begin(), Record.end())); |
| 3731 | break; |
| 3732 | |
| 3733 | case OPTIMIZE_PRAGMA_OPTIONS: |
| 3734 | if (Record.size() != 1) { |
| 3735 | Error("invalid pragma optimize record"); |
| 3736 | return Failure; |
| 3737 | } |
| 3738 | OptimizeOffPragmaLocation = ReadSourceLocation(F, Record[0]); |
| 3739 | break; |
| 3740 | |
| 3741 | case MSSTRUCT_PRAGMA_OPTIONS: |
| 3742 | if (Record.size() != 1) { |
| 3743 | Error("invalid pragma ms_struct record"); |
| 3744 | return Failure; |
| 3745 | } |
| 3746 | PragmaMSStructState = Record[0]; |
| 3747 | break; |
| 3748 | |
| 3749 | case POINTERS_TO_MEMBERS_PRAGMA_OPTIONS: |
| 3750 | if (Record.size() != 2) { |
| 3751 | Error("invalid pragma ms_struct record"); |
| 3752 | return Failure; |
| 3753 | } |
| 3754 | PragmaMSPointersToMembersState = Record[0]; |
| 3755 | PointersToMembersPragmaLocation = ReadSourceLocation(F, Record[1]); |
| 3756 | break; |
| 3757 | |
| 3758 | case UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES: |
| 3759 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3760 | UnusedLocalTypedefNameCandidates.push_back( |
| 3761 | getGlobalDeclID(F, Record[I])); |
| 3762 | break; |
| 3763 | |
| 3764 | case CUDA_PRAGMA_FORCE_HOST_DEVICE_DEPTH: |
| 3765 | if (Record.size() != 1) { |
| 3766 | Error("invalid cuda pragma options record"); |
| 3767 | return Failure; |
| 3768 | } |
| 3769 | ForceCUDAHostDeviceDepth = Record[0]; |
| 3770 | break; |
| 3771 | |
| 3772 | case ALIGN_PACK_PRAGMA_OPTIONS: { |
| 3773 | if (Record.size() < 3) { |
| 3774 | Error("invalid pragma pack record"); |
| 3775 | return Failure; |
| 3776 | } |
| 3777 | PragmaAlignPackCurrentValue = ReadAlignPackInfo(Record[0]); |
| 3778 | PragmaAlignPackCurrentLocation = ReadSourceLocation(F, Record[1]); |
| 3779 | unsigned NumStackEntries = Record[2]; |
| 3780 | unsigned Idx = 3; |
| 3781 | |
| 3782 | PragmaAlignPackStack.clear(); |
| 3783 | for (unsigned I = 0; I < NumStackEntries; ++I) { |
| 3784 | PragmaAlignPackStackEntry Entry; |
| 3785 | Entry.Value = ReadAlignPackInfo(Record[Idx++]); |
| 3786 | Entry.Location = ReadSourceLocation(F, Record[Idx++]); |
| 3787 | Entry.PushLocation = ReadSourceLocation(F, Record[Idx++]); |
| 3788 | PragmaAlignPackStrings.push_back(ReadString(Record, Idx)); |
| 3789 | Entry.SlotLabel = PragmaAlignPackStrings.back(); |
| 3790 | PragmaAlignPackStack.push_back(Entry); |
| 3791 | } |
| 3792 | break; |
| 3793 | } |
| 3794 | |
| 3795 | case FLOAT_CONTROL_PRAGMA_OPTIONS: { |
| 3796 | if (Record.size() < 3) { |
| 3797 | Error("invalid pragma pack record"); |
| 3798 | return Failure; |
| 3799 | } |
| 3800 | FpPragmaCurrentValue = FPOptionsOverride::getFromOpaqueInt(Record[0]); |
| 3801 | FpPragmaCurrentLocation = ReadSourceLocation(F, Record[1]); |
| 3802 | unsigned NumStackEntries = Record[2]; |
| 3803 | unsigned Idx = 3; |
| 3804 | |
| 3805 | FpPragmaStack.clear(); |
| 3806 | for (unsigned I = 0; I < NumStackEntries; ++I) { |
| 3807 | FpPragmaStackEntry Entry; |
| 3808 | Entry.Value = FPOptionsOverride::getFromOpaqueInt(Record[Idx++]); |
| 3809 | Entry.Location = ReadSourceLocation(F, Record[Idx++]); |
| 3810 | Entry.PushLocation = ReadSourceLocation(F, Record[Idx++]); |
| 3811 | FpPragmaStrings.push_back(ReadString(Record, Idx)); |
| 3812 | Entry.SlotLabel = FpPragmaStrings.back(); |
| 3813 | FpPragmaStack.push_back(Entry); |
| 3814 | } |
| 3815 | break; |
| 3816 | } |
| 3817 | |
| 3818 | case DECLS_TO_CHECK_FOR_DEFERRED_DIAGS: |
| 3819 | for (unsigned I = 0, N = Record.size(); I != N; ++I) |
| 3820 | DeclsToCheckForDeferredDiags.insert(getGlobalDeclID(F, Record[I])); |
| 3821 | break; |
| 3822 | } |
| 3823 | } |
| 3824 | } |
| 3825 | |
| 3826 | void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const { |
| 3827 | assert(!F.ModuleOffsetMap.empty() && "no module offset map to read"); |
| 3828 | |
| 3829 | |
| 3830 | const unsigned char *Data = (const unsigned char*)F.ModuleOffsetMap.data(); |
| 3831 | const unsigned char *DataEnd = Data + F.ModuleOffsetMap.size(); |
| 3832 | F.ModuleOffsetMap = StringRef(); |
| 3833 | |
| 3834 | |
| 3835 | if (F.SLocRemap.find(0) == F.SLocRemap.end()) { |
| 3836 | F.SLocRemap.insert(std::make_pair(0U, 0)); |
| 3837 | F.SLocRemap.insert(std::make_pair(2U, 1)); |
| 3838 | } |
| 3839 | |
| 3840 | |
| 3841 | using SLocRemapBuilder = |
| 3842 | ContinuousRangeMap<SourceLocation::UIntTy, SourceLocation::IntTy, |
| 3843 | 2>::Builder; |
| 3844 | using RemapBuilder = ContinuousRangeMap<uint32_t, int, 2>::Builder; |
| 3845 | SLocRemapBuilder SLocRemap(F.SLocRemap); |
| 3846 | RemapBuilder IdentifierRemap(F.IdentifierRemap); |
| 3847 | RemapBuilder MacroRemap(F.MacroRemap); |
| 3848 | RemapBuilder PreprocessedEntityRemap(F.PreprocessedEntityRemap); |
| 3849 | RemapBuilder SubmoduleRemap(F.SubmoduleRemap); |
| 3850 | RemapBuilder SelectorRemap(F.SelectorRemap); |
| 3851 | RemapBuilder DeclRemap(F.DeclRemap); |
| 3852 | RemapBuilder TypeRemap(F.TypeRemap); |
| 3853 | |
| 3854 | while (Data < DataEnd) { |
| 3855 | |
| 3856 | |
| 3857 | |
| 3858 | using namespace llvm::support; |
| 3859 | ModuleKind Kind = static_cast<ModuleKind>( |
| 3860 | endian::readNext<uint8_t, little, unaligned>(Data)); |
| 3861 | uint16_t Len = endian::readNext<uint16_t, little, unaligned>(Data); |
| 3862 | StringRef Name = StringRef((const char*)Data, Len); |
| 3863 | Data += Len; |
| 3864 | ModuleFile *OM = (Kind == MK_PrebuiltModule || Kind == MK_ExplicitModule || |
| 3865 | Kind == MK_ImplicitModule |
| 3866 | ? ModuleMgr.lookupByModuleName(Name) |
| 3867 | : ModuleMgr.lookupByFileName(Name)); |
| 3868 | if (!OM) { |
| 3869 | std::string Msg = |
| 3870 | "SourceLocation remap refers to unknown module, cannot find "; |
| 3871 | Msg.append(std::string(Name)); |
| 3872 | Error(Msg); |
| 3873 | return; |
| 3874 | } |
| 3875 | |
| 3876 | SourceLocation::UIntTy SLocOffset = |
| 3877 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3878 | uint32_t IdentifierIDOffset = |
| 3879 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3880 | uint32_t MacroIDOffset = |
| 3881 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3882 | uint32_t PreprocessedEntityIDOffset = |
| 3883 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3884 | uint32_t SubmoduleIDOffset = |
| 3885 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3886 | uint32_t SelectorIDOffset = |
| 3887 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3888 | uint32_t DeclIDOffset = |
| 3889 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3890 | uint32_t TypeIndexOffset = |
| 3891 | endian::readNext<uint32_t, little, unaligned>(Data); |
| 3892 | |
| 3893 | auto mapOffset = [&](uint32_t Offset, uint32_t BaseOffset, |
| 3894 | RemapBuilder &Remap) { |
| 3895 | constexpr uint32_t None = std::numeric_limits<uint32_t>::max(); |
| 3896 | if (Offset != None) |
| 3897 | Remap.insert(std::make_pair(Offset, |
| 3898 | static_cast<int>(BaseOffset - Offset))); |
| 3899 | }; |
| 3900 | |
| 3901 | constexpr SourceLocation::UIntTy SLocNone = |
| 3902 | std::numeric_limits<SourceLocation::UIntTy>::max(); |
| 3903 | if (SLocOffset != SLocNone) |
| 3904 | SLocRemap.insert(std::make_pair( |
| 3905 | SLocOffset, static_cast<SourceLocation::IntTy>( |
| 3906 | OM->SLocEntryBaseOffset - SLocOffset))); |
| 3907 | |
| 3908 | mapOffset(IdentifierIDOffset, OM->BaseIdentifierID, IdentifierRemap); |
| 3909 | mapOffset(MacroIDOffset, OM->BaseMacroID, MacroRemap); |
| 3910 | mapOffset(PreprocessedEntityIDOffset, OM->BasePreprocessedEntityID, |
| 3911 | PreprocessedEntityRemap); |
| 3912 | mapOffset(SubmoduleIDOffset, OM->BaseSubmoduleID, SubmoduleRemap); |
| 3913 | mapOffset(SelectorIDOffset, OM->BaseSelectorID, SelectorRemap); |
| 3914 | mapOffset(DeclIDOffset, OM->BaseDeclID, DeclRemap); |
| 3915 | mapOffset(TypeIndexOffset, OM->BaseTypeIndex, TypeRemap); |
| 3916 | |
| 3917 | |
| 3918 | F.GlobalToLocalDeclIDs[OM] = DeclIDOffset; |
| 3919 | } |
| 3920 | } |
| 3921 | |
| 3922 | ASTReader::ASTReadResult |
| 3923 | ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, |
| 3924 | const ModuleFile *ImportedBy, |
| 3925 | unsigned ClientLoadCapabilities) { |
| 3926 | unsigned Idx = 0; |
| 3927 | F.ModuleMapPath = ReadPath(F, Record, Idx); |
| 3928 | |
| 3929 | |
| 3930 | |
| 3931 | |
| 3932 | |
| 3933 | assert(!F.ModuleName.empty() && |
| 3934 | "MODULE_NAME should come before MODULE_MAP_FILE"); |
| 3935 | if (F.Kind == MK_ImplicitModule && ModuleMgr.begin()->Kind != MK_MainFile) { |
| 3936 | |
| 3937 | |
| 3938 | Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName); |
| 3939 | auto &Map = PP.getHeaderSearchInfo().getModuleMap(); |
| 3940 | const FileEntry *ModMap = M ? Map.getModuleMapFileForUniquing(M) : nullptr; |
| 3941 | |
| 3942 | if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation & |
| 3943 | DisableValidationForModuleKind::Module) && |
| 3944 | !ModMap) { |
| 3945 | if (!canRecoverFromOutOfDate(F.FileName, ClientLoadCapabilities)) { |
| 3946 | if (auto ASTFE = M ? M->getASTFile() : None) { |
| 3947 | |
| 3948 | Diag(diag::err_module_file_conflict) << F.ModuleName << F.FileName |
| 3949 | << ASTFE->getName(); |
| 3950 | } else { |
| 3951 | |
| 3952 | Diag(diag::err_imported_module_not_found) |
| 3953 | << F.ModuleName << F.FileName |
| 3954 | << (ImportedBy ? ImportedBy->FileName : "") << F.ModuleMapPath |
| 3955 | << !ImportedBy; |
| 3956 | |
| 3957 | |
| 3958 | |
| 3959 | if (ImportedBy && ImportedBy->Kind == MK_PCH) |
| 3960 | Diag(diag::note_imported_by_pch_module_not_found) |
| 3961 | << llvm::sys::path::parent_path(F.ModuleMapPath); |
| 3962 | } |
| 3963 | } |
| 3964 | return OutOfDate; |
| 3965 | } |
| 3966 | |
| 3967 | assert(M && M->Name == F.ModuleName && "found module with different name"); |
| 3968 | |
| 3969 | |
| 3970 | auto StoredModMap = FileMgr.getFile(F.ModuleMapPath); |
| 3971 | if (!StoredModMap || *StoredModMap != ModMap) { |
| 3972 | assert(ModMap && "found module is missing module map file"); |
| 3973 | assert((ImportedBy || F.Kind == MK_ImplicitModule) && |
| 3974 | "top-level import should be verified"); |
| 3975 | bool NotImported = F.Kind == MK_ImplicitModule && !ImportedBy; |
| 3976 | if (!canRecoverFromOutOfDate(F.FileName, ClientLoadCapabilities)) |
| 3977 | Diag(diag::err_imported_module_modmap_changed) |
| 3978 | << F.ModuleName << (NotImported ? F.FileName : ImportedBy->FileName) |
| 3979 | << ModMap->getName() << F.ModuleMapPath << NotImported; |
| 3980 | return OutOfDate; |
| 3981 | } |
| 3982 | |
| 3983 | llvm::SmallPtrSet<const FileEntry *, 1> AdditionalStoredMaps; |
| 3984 | for (unsigned I = 0, N = Record[Idx++]; I < N; ++I) { |
| 3985 | |
| 3986 | std::string Filename = ReadPath(F, Record, Idx); |
| 3987 | auto SF = FileMgr.getFile(Filename, false, false); |
| 3988 | if (!SF) { |
| 3989 | if (!canRecoverFromOutOfDate(F.FileName, ClientLoadCapabilities)) |
| 3990 | Error("could not find file '" + Filename +"' referenced by AST file"); |
| 3991 | return OutOfDate; |
| 3992 | } |
| 3993 | AdditionalStoredMaps.insert(*SF); |
| 3994 | } |
| 3995 | |
| 3996 | |
| 3997 | |
| 3998 | if (auto *AdditionalModuleMaps = Map.getAdditionalModuleMapFiles(M)) { |
| 3999 | for (const FileEntry *ModMap : *AdditionalModuleMaps) { |
| 4000 | |
| 4001 | |
| 4002 | if (!AdditionalStoredMaps.erase(ModMap)) { |
| 4003 | if (!canRecoverFromOutOfDate(F.FileName, ClientLoadCapabilities)) |
| 4004 | Diag(diag::err_module_different_modmap) |
| 4005 | << F.ModuleName << 0 << ModMap->getName(); |
| 4006 | return OutOfDate; |
| 4007 | } |
| 4008 | } |
| 4009 | } |
| 4010 | |
| 4011 | |
| 4012 | |
| 4013 | for (const FileEntry *ModMap : AdditionalStoredMaps) { |
| 4014 | if (!canRecoverFromOutOfDate(F.FileName, ClientLoadCapabilities)) |
| 4015 | Diag(diag::err_module_different_modmap) |
| 4016 | << F.ModuleName << 1 << ModMap->getName(); |
| 4017 | return OutOfDate; |
| 4018 | } |
| 4019 | } |
| 4020 | |
| 4021 | if (Listener) |
| 4022 | Listener->ReadModuleMapFile(F.ModuleMapPath); |
| 4023 | return Success; |
| 4024 | } |
| 4025 | |
| 4026 | |
| 4027 | static void moveMethodToBackOfGlobalList(Sema &S, ObjCMethodDecl *Method) { |
| 4028 | |
| 4029 | Sema::GlobalMethodPool::iterator Known |
| 4030 | = S.MethodPool.find(Method->getSelector()); |
| 4031 | if (Known == S.MethodPool.end()) |
| 4032 | return; |
| 4033 | |
| 4034 | |
| 4035 | ObjCMethodList &Start = Method->isInstanceMethod()? Known->second.first |
| 4036 | : Known->second.second; |
| 4037 | bool Found = false; |
| 4038 | for (ObjCMethodList *List = &Start; List; List = List->getNext()) { |
| 4039 | if (!Found) { |
| 4040 | if (List->getMethod() == Method) { |
| 4041 | Found = true; |
| 4042 | } else { |
| 4043 | |
| 4044 | continue; |
| 4045 | } |
| 4046 | } |
| 4047 | |
| 4048 | if (List->getNext()) |
| 4049 | List->setMethod(List->getNext()->getMethod()); |
| 4050 | else |
| 4051 | List->setMethod(Method); |
| 4052 | } |
| 4053 | } |
| 4054 | |
| 4055 | void ASTReader::makeNamesVisible(const HiddenNames &Names, Module *Owner) { |
| 4056 | assert(Owner->NameVisibility != Module::Hidden && "nothing to make visible?"); |
| 4057 | for (Decl *D : Names) { |
| 4058 | bool wasHidden = !D->isUnconditionallyVisible(); |
| 4059 | D->setVisibleDespiteOwningModule(); |
| 4060 | |
| 4061 | if (wasHidden && SemaObj) { |
| 4062 | if (ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(D)) { |
| 4063 | moveMethodToBackOfGlobalList(*SemaObj, Method); |
| 4064 | } |
| 4065 | } |
| 4066 | } |
| 4067 | } |
| 4068 | |
| 4069 | void ASTReader::makeModuleVisible(Module *Mod, |
| 4070 | Module::NameVisibilityKind NameVisibility, |
| 4071 | SourceLocation ImportLoc) { |
| 4072 | llvm::SmallPtrSet<Module *, 4> Visited; |
| 4073 | SmallVector<Module *, 4> Stack; |
| 4074 | Stack.push_back(Mod); |
| 4075 | while (!Stack.empty()) { |
| 4076 | Mod = Stack.pop_back_val(); |
| 4077 | |
| 4078 | if (NameVisibility <= Mod->NameVisibility) { |
| 4079 | |
| 4080 | |
| 4081 | continue; |
| 4082 | } |
| 4083 | |
| 4084 | if (Mod->isUnimportable()) { |
| 4085 | |
| 4086 | continue; |
| 4087 | } |
| 4088 | |
| 4089 | |
| 4090 | Mod->NameVisibility = NameVisibility; |
| 4091 | |
| 4092 | |
| 4093 | |
| 4094 | HiddenNamesMapType::iterator Hidden = HiddenNamesMap.find(Mod); |
| 4095 | if (Hidden != HiddenNamesMap.end()) { |
| 4096 | auto HiddenNames = std::move(*Hidden); |
| 4097 | HiddenNamesMap.erase(Hidden); |
| 4098 | makeNamesVisible(HiddenNames.second, HiddenNames.first); |
| 4099 | assert(HiddenNamesMap.find(Mod) == HiddenNamesMap.end() && |
| 4100 | "making names visible added hidden names"); |
| 4101 | } |
| 4102 | |
| 4103 | |
| 4104 | SmallVector<Module *, 16> Exports; |
| 4105 | Mod->getExportedModules(Exports); |
| 4106 | for (SmallVectorImpl<Module *>::iterator |
| 4107 | I = Exports.begin(), E = Exports.end(); I != E; ++I) { |
| 4108 | Module *Exported = *I; |
| 4109 | if (Visited.insert(Exported).second) |
| 4110 | Stack.push_back(Exported); |
| 4111 | } |
| 4112 | } |
| 4113 | } |
| 4114 | |
| 4115 | |
| 4116 | |
| 4117 | |
| 4118 | void ASTReader::mergeDefinitionVisibility(NamedDecl *Def, |
| 4119 | NamedDecl *MergedDef) { |
| 4120 | if (!Def->isUnconditionallyVisible()) { |
| 4121 | |
| 4122 | if (MergedDef->isUnconditionallyVisible()) |
| 4123 | Def->setVisibleDespiteOwningModule(); |
| 4124 | else { |
| 4125 | getContext().mergeDefinitionIntoModule( |
| 4126 | Def, MergedDef->getImportedOwningModule(), |
| 4127 | false); |
| 4128 | PendingMergedDefinitionsToDeduplicate.insert(Def); |
| 4129 | } |
| 4130 | } |
| 4131 | } |
| 4132 | |
| 4133 | bool ASTReader::loadGlobalIndex() { |
| 4134 | if (GlobalIndex) |
| 4135 | return false; |
| 4136 | |
| 4137 | if (TriedLoadingGlobalIndex || !UseGlobalIndex || |
| 4138 | !PP.getLangOpts().Modules) |
| 4139 | return true; |
| 4140 | |
| 4141 | |
| 4142 | TriedLoadingGlobalIndex = true; |
| 4143 | StringRef ModuleCachePath |
| 4144 | = getPreprocessor().getHeaderSearchInfo().getModuleCachePath(); |
| 4145 | std::pair<GlobalModuleIndex *, llvm::Error> Result = |
| 4146 | GlobalModuleIndex::readIndex(ModuleCachePath); |
| 4147 | if (llvm::Error Err = std::move(Result.second)) { |
| 4148 | assert(!Result.first); |
| 4149 | consumeError(std::move(Err)); |
| 4150 | return true; |
| 4151 | } |
| 4152 | |
| 4153 | GlobalIndex.reset(Result.first); |
| 4154 | ModuleMgr.setGlobalIndex(GlobalIndex.get()); |
| 4155 | return false; |
| 4156 | } |
| 4157 | |
| 4158 | bool ASTReader::isGlobalIndexUnavailable() const { |
| 4159 | return PP.getLangOpts().Modules && UseGlobalIndex && |
| 4160 | !hasGlobalIndex() && TriedLoadingGlobalIndex; |
| 4161 | } |
| 4162 | |
| 4163 | static void updateModuleTimestamp(ModuleFile &MF) { |
| 4164 | |
| 4165 | std::string TimestampFilename = MF.getTimestampFilename(); |
| 4166 | std::error_code EC; |
| 4167 | llvm::raw_fd_ostream OS(TimestampFilename, EC, |
| 4168 | llvm::sys::fs::OF_TextWithCRLF); |
| 4169 | if (EC) |
| 4170 | return; |
| 4171 | OS << "Timestamp file\n"; |
| 4172 | OS.close(); |
| 4173 | OS.clear_error(); |
| 4174 | } |
| 4175 | |
| 4176 | |
| 4177 | |
| 4178 | |
| 4179 | static bool SkipCursorToBlock(BitstreamCursor &Cursor, unsigned BlockID) { |
| 4180 | while (true) { |
| 4181 | Expected<llvm::BitstreamEntry> MaybeEntry = Cursor.advance(); |
| 4182 | if (!MaybeEntry) { |
| 4183 | |
| 4184 | consumeError(MaybeEntry.takeError()); |
| 4185 | return true; |
| 4186 | } |
| 4187 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 4188 | |
| 4189 | switch (Entry.Kind) { |
| 4190 | case llvm::BitstreamEntry::Error: |
| 4191 | case llvm::BitstreamEntry::EndBlock: |
| 4192 | return true; |
| 4193 | |
| 4194 | case llvm::BitstreamEntry::Record: |
| 4195 | |
| 4196 | if (Expected<unsigned> Skipped = Cursor.skipRecord(Entry.ID)) |
| 4197 | break; |
| 4198 | else { |
| 4199 | |
| 4200 | consumeError(Skipped.takeError()); |
| 4201 | return true; |
| 4202 | } |
| 4203 | |
| 4204 | case llvm::BitstreamEntry::SubBlock: |
| 4205 | if (Entry.ID == BlockID) { |
| 4206 | if (llvm::Error Err = Cursor.EnterSubBlock(BlockID)) { |
| 4207 | |
| 4208 | consumeError(std::move(Err)); |
| 4209 | return true; |
| 4210 | } |
| 4211 | |
| 4212 | return false; |
| 4213 | } |
| 4214 | |
| 4215 | if (llvm::Error Err = Cursor.SkipBlock()) { |
| 4216 | |
| 4217 | consumeError(std::move(Err)); |
| 4218 | return true; |
| 4219 | } |
| 4220 | } |
| 4221 | } |
| 4222 | } |
| 4223 | |
| 4224 | ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName, |
| 4225 | ModuleKind Type, |
| 4226 | SourceLocation ImportLoc, |
| 4227 | unsigned ClientLoadCapabilities, |
| 4228 | SmallVectorImpl<ImportedSubmodule> *Imported) { |
| 4229 | llvm::SaveAndRestore<SourceLocation> |
| 4230 | SetCurImportLocRAII(CurrentImportLoc, ImportLoc); |
| 4231 | llvm::SaveAndRestore<Optional<ModuleKind>> SetCurModuleKindRAII( |
| 4232 | CurrentDeserializingModuleKind, Type); |
| 4233 | |
| 4234 | |
| 4235 | Deserializing AnASTFile(this); |
| 4236 | |
| 4237 | |
| 4238 | unsigned PreviousGeneration = 0; |
| 4239 | if (ContextObj) |
| 1 | Assuming field 'ContextObj' is null | |
|
| |
| 4240 | PreviousGeneration = incrementGeneration(*ContextObj); |
| 4241 | |
| 4242 | unsigned NumModules = ModuleMgr.size(); |
| 4243 | auto removeModulesAndReturn = [&](ASTReadResult ReadResult) { |
| 4244 | assert(ReadResult && "expected to return error"); |
| 4245 | ModuleMgr.removeModules(ModuleMgr.begin() + NumModules, |
| 4246 | PP.getLangOpts().Modules |
| 4247 | ? &PP.getHeaderSearchInfo().getModuleMap() |
| 4248 | : nullptr); |
| 4249 | |
| 4250 | |
| 4251 | |
| 4252 | GlobalIndex.reset(); |
| 4253 | ModuleMgr.setGlobalIndex(nullptr); |
| 4254 | return ReadResult; |
| 4255 | }; |
| 4256 | |
| 4257 | SmallVector<ImportedModule, 4> Loaded; |
| 4258 | switch (ASTReadResult ReadResult = |
| 3 | | Control jumps to 'case Success:' at line 4269 | |
|
| 4259 | ReadASTCore(FileName, Type, ImportLoc, |
| 4260 | nullptr, Loaded, 0, 0, |
| 4261 | ASTFileSignature(), ClientLoadCapabilities)) { |
| 4262 | case Failure: |
| 4263 | case Missing: |
| 4264 | case OutOfDate: |
| 4265 | case VersionMismatch: |
| 4266 | case ConfigurationMismatch: |
| 4267 | case HadErrors: |
| 4268 | return removeModulesAndReturn(ReadResult); |
| 4269 | case Success: |
| 4270 | break; |
| 4 | | Execution continues on line 4277 | |
|
| 4271 | } |
| 4272 | |
| 4273 | |
| 4274 | |
| 4275 | |
| 4276 | |
| 4277 | for (ImportedModule &M : Loaded) { |
| 5 | | Assuming '__begin1' is equal to '__end1' | |
|
| 4278 | ModuleFile &F = *M.Mod; |
| 4279 | |
| 4280 | |
| 4281 | if (ASTReadResult Result = ReadASTBlock(F, ClientLoadCapabilities)) |
| 4282 | return removeModulesAndReturn(Result); |
| 4283 | |
| 4284 | |
| 4285 | if (F.isModule() && !F.DidReadTopLevelSubmodule) { |
| 4286 | Error(diag::err_module_file_missing_top_level_submodule, F.FileName); |
| 4287 | return removeModulesAndReturn(Failure); |
| 4288 | } |
| 4289 | |
| 4290 | |
| 4291 | while (!SkipCursorToBlock(F.Stream, EXTENSION_BLOCK_ID)) { |
| 4292 | if (ASTReadResult Result = ReadExtensionBlock(F)) |
| 4293 | return removeModulesAndReturn(Result); |
| 4294 | } |
| 4295 | |
| 4296 | |
| 4297 | |
| 4298 | F.GlobalBitOffset = TotalModulesSizeInBits; |
| 4299 | TotalModulesSizeInBits += F.SizeInBits; |
| 4300 | GlobalBitOffsetsMap.insert(std::make_pair(F.GlobalBitOffset, &F)); |
| 4301 | } |
| 4302 | |
| 4303 | |
| 4304 | for (ImportedModule &M : Loaded) { |
| 6 | | Assuming '__begin1' is equal to '__end1' | |
|
| 4305 | ModuleFile &F = *M.Mod; |
| 4306 | |
| 4307 | |
| 4308 | for (unsigned I = 0, N = F.PreloadSLocEntries.size(); I != N; ++I) { |
| 4309 | int Index = int(F.PreloadSLocEntries[I] - 1) + F.SLocEntryBaseID; |
| 4310 | |
| 4311 | |
| 4312 | |
| 4313 | |
| 4314 | SourceMgr.getLoadedSLocEntryByID(Index); |
| 4315 | } |
| 4316 | |
| 4317 | |
| 4318 | |
| 4319 | if (F.OriginalSourceFileID.isValid()) { |
| 4320 | F.OriginalSourceFileID = FileID::get( |
| 4321 | F.SLocEntryBaseID + F.OriginalSourceFileID.getOpaqueValue() - 1); |
| 4322 | } |
| 4323 | |
| 4324 | |
| 4325 | |
| 4326 | for (auto Offset : F.PreloadIdentifierOffsets) { |
| 4327 | const unsigned char *Data = F.IdentifierTableData + Offset; |
| 4328 | |
| 4329 | ASTIdentifierLookupTrait Trait(*this, F); |
| 4330 | auto KeyDataLen = Trait.ReadKeyDataLength(Data); |
| 4331 | auto Key = Trait.ReadKey(Data, KeyDataLen.first); |
| 4332 | auto &II = PP.getIdentifierTable().getOwn(Key); |
| 4333 | II.setOutOfDate(true); |
| 4334 | |
| 4335 | |
| 4336 | |
| 4337 | markIdentifierFromAST(*this, II); |
| 4338 | |
| 4339 | |
| 4340 | auto ID = Trait.ReadIdentifierID(Data + KeyDataLen.first); |
| 4341 | SetIdentifierInfo(ID, &II); |
| 4342 | } |
| 4343 | } |
| 4344 | |
| 4345 | |
| 4346 | |
| 4347 | for (ImportedModule &M : Loaded) { |
| 7 | | Assuming '__begin1' is equal to '__end1' | |
|
| 4348 | ModuleFile &F = *M.Mod; |
| 4349 | |
| 4350 | ModuleMgr.moduleFileAccepted(&F); |
| 4351 | |
| 4352 | |
| 4353 | F.DirectImportLoc = ImportLoc; |
| 4354 | |
| 4355 | |
| 4356 | if (!M.ImportedBy) |
| 4357 | F.ImportLoc = M.ImportLoc; |
| 4358 | else |
| 4359 | F.ImportLoc = TranslateSourceLocation(*M.ImportedBy, M.ImportLoc); |
| 4360 | } |
| 4361 | |
| 4362 | if (!PP.getLangOpts().CPlusPlus || |
| 8 | | Assuming field 'CPlusPlus' is not equal to 0 | |
|
| 4363 | (Type != MK_ImplicitModule && Type != MK_ExplicitModule && |
| 9 | | Assuming 'Type' is equal to MK_ImplicitModule | |
|
| 4364 | Type != MK_PrebuiltModule)) { |
| 4365 | |
| 4366 | |
| 4367 | |
| 4368 | |
| 4369 | |
| 4370 | |
| 4371 | |
| 4372 | for (IdentifierTable::iterator Id = PP.getIdentifierTable().begin(), |
| 4373 | IdEnd = PP.getIdentifierTable().end(); |
| 4374 | Id != IdEnd; ++Id) |
| 4375 | Id->second->setOutOfDate(true); |
| 4376 | } |
| 4377 | |
| 4378 | for (auto Sel : SelectorGeneration) |
| 4379 | SelectorOutOfDate[Sel.first] = true; |
| 4380 | |
| 4381 | |
| 4382 | for (unsigned I = 0, N = UnresolvedModuleRefs.size(); I != N; ++I) { |
| 10 | | Assuming 'I' is equal to 'N' | |
|
| 11 | | Loop condition is false. Execution continues on line 4409 | |
|
| 4383 | UnresolvedModuleRef &Unresolved = UnresolvedModuleRefs[I]; |
| 4384 | SubmoduleID GlobalID = getGlobalSubmoduleID(*Unresolved.File,Unresolved.ID); |
| 4385 | Module *ResolvedMod = getSubmodule(GlobalID); |
| 4386 | |
| 4387 | switch (Unresolved.Kind) { |
| 4388 | case UnresolvedModuleRef::Conflict: |
| 4389 | if (ResolvedMod) { |
| 4390 | Module::Conflict Conflict; |
| 4391 | Conflict.Other = ResolvedMod; |
| 4392 | Conflict.Message = Unresolved.String.str(); |
| 4393 | Unresolved.Mod->Conflicts.push_back(Conflict); |
| 4394 | } |
| 4395 | continue; |
| 4396 | |
| 4397 | case UnresolvedModuleRef::Import: |
| 4398 | if (ResolvedMod) |
| 4399 | Unresolved.Mod->Imports.insert(ResolvedMod); |
| 4400 | continue; |
| 4401 | |
| 4402 | case UnresolvedModuleRef::Export: |
| 4403 | if (ResolvedMod || Unresolved.IsWildcard) |
| 4404 | Unresolved.Mod->Exports.push_back( |
| 4405 | Module::ExportDecl(ResolvedMod, Unresolved.IsWildcard)); |
| 4406 | continue; |
| 4407 | } |
| 4408 | } |
| 4409 | UnresolvedModuleRefs.clear(); |
| 4410 | |
| 4411 | if (Imported) |
| 12 | | Assuming 'Imported' is null | |
|
| |
| 4412 | Imported->append(ImportedModules.begin(), |
| 4413 | ImportedModules.end()); |
| 4414 | |
| 4415 | |
| 4416 | |
| 4417 | |
| 4418 | |
| 4419 | if (ContextObj) |
| 14 | | Assuming field 'ContextObj' is non-null | |
|
| |
| 4420 | InitializeContext(); |
| 16 | | Calling 'ASTReader::InitializeContext' | |
|
| 4421 | |
| 4422 | if (SemaObj) |
| 4423 | UpdateSema(); |
| 4424 | |
| 4425 | if (DeserializationListener) |
| 4426 | DeserializationListener->ReaderInitialized(this); |
| 4427 | |
| 4428 | ModuleFile &PrimaryModule = ModuleMgr.getPrimaryModule(); |
| 4429 | if (PrimaryModule.OriginalSourceFileID.isValid()) { |
| 4430 | |
| 4431 | |
| 4432 | |
| 4433 | if (Type == MK_Preamble) { |
| 4434 | SourceMgr.setPreambleFileID(PrimaryModule.OriginalSourceFileID); |
| 4435 | } else if (Type == MK_MainFile) { |
| 4436 | SourceMgr.setMainFileID(PrimaryModule.OriginalSourceFileID); |
| 4437 | } |
| 4438 | } |
| 4439 | |
| 4440 | |
| 4441 | |
| 4442 | if (ContextObj) { |
| 4443 | for (unsigned I = 0, N = ObjCClassesLoaded.size(); I != N; ++I) { |
| 4444 | loadObjCCategories(ObjCClassesLoaded[I]->getGlobalID(), |
| 4445 | ObjCClassesLoaded[I], |
| 4446 | PreviousGeneration); |
| 4447 | } |
| 4448 | } |
| 4449 | |
| 4450 | if (PP.getHeaderSearchInfo() |
| 4451 | .getHeaderSearchOpts() |
| 4452 | .ModulesValidateOncePerBuildSession) { |
| 4453 | |
| 4454 | |
| 4455 | |
| 4456 | |
| 4457 | for (unsigned I = 0, N = Loaded.size(); I != N; ++I) { |
| 4458 | ImportedModule &M = Loaded[I]; |
| 4459 | if (M.Mod->Kind == MK_ImplicitModule) { |
| 4460 | updateModuleTimestamp(*M.Mod); |
| 4461 | } |
| 4462 | } |
| 4463 | } |
| 4464 | |
| 4465 | return Success; |
| 4466 | } |
| 4467 | |
| 4468 | static ASTFileSignature readASTFileSignature(StringRef PCH); |
| 4469 | |
| 4470 | |
| 4471 | static llvm::Error doesntStartWithASTFileMagic(BitstreamCursor &Stream) { |
| 4472 | |
| 4473 | |
| 4474 | |
| 4475 | if (!Stream.canSkipToPos(4)) |
| 4476 | return llvm::createStringError(std::errc::illegal_byte_sequence, |
| 4477 | "file too small to contain AST file magic"); |
| 4478 | for (unsigned C : {'C', 'P', 'C', 'H'}) |
| 4479 | if (Expected<llvm::SimpleBitstreamCursor::word_t> Res = Stream.Read(8)) { |
| 4480 | if (Res.get() != C) |
| 4481 | return llvm::createStringError( |
| 4482 | std::errc::illegal_byte_sequence, |
| 4483 | "file doesn't start with AST file magic"); |
| 4484 | } else |
| 4485 | return Res.takeError(); |
| 4486 | return llvm::Error::success(); |
| 4487 | } |
| 4488 | |
| 4489 | static unsigned moduleKindForDiagnostic(ModuleKind Kind) { |
| 4490 | switch (Kind) { |
| 4491 | case MK_PCH: |
| 4492 | return 0; |
| 4493 | case MK_ImplicitModule: |
| 4494 | case MK_ExplicitModule: |
| 4495 | case MK_PrebuiltModule: |
| 4496 | return 1; |
| 4497 | case MK_MainFile: |
| 4498 | case MK_Preamble: |
| 4499 | return 2; |
| 4500 | } |
| 4501 | llvm_unreachable("unknown module kind"); |
| 4502 | } |
| 4503 | |
| 4504 | ASTReader::ASTReadResult |
| 4505 | ASTReader::ReadASTCore(StringRef FileName, |
| 4506 | ModuleKind Type, |
| 4507 | SourceLocation ImportLoc, |
| 4508 | ModuleFile *ImportedBy, |
| 4509 | SmallVectorImpl<ImportedModule> &Loaded, |
| 4510 | off_t ExpectedSize, time_t ExpectedModTime, |
| 4511 | ASTFileSignature ExpectedSignature, |
| 4512 | unsigned ClientLoadCapabilities) { |
| 4513 | ModuleFile *M; |
| 4514 | std::string ErrorStr; |
| 4515 | ModuleManager::AddModuleResult AddResult |
| 4516 | = ModuleMgr.addModule(FileName, Type, ImportLoc, ImportedBy, |
| 4517 | getGeneration(), ExpectedSize, ExpectedModTime, |
| 4518 | ExpectedSignature, readASTFileSignature, |
| 4519 | M, ErrorStr); |
| 4520 | |
| 4521 | switch (AddResult) { |
| 4522 | case ModuleManager::AlreadyLoaded: |
| 4523 | Diag(diag::remark_module_import) |
| 4524 | << M->ModuleName << M->FileName << (ImportedBy ? true : false) |
| 4525 | << (ImportedBy ? StringRef(ImportedBy->ModuleName) : StringRef()); |
| 4526 | return Success; |
| 4527 | |
| 4528 | case ModuleManager::NewlyLoaded: |
| 4529 | |
| 4530 | break; |
| 4531 | |
| 4532 | case ModuleManager::Missing: |
| 4533 | |
| 4534 | |
| 4535 | if (ClientLoadCapabilities & ARR_Missing) |
| 4536 | return Missing; |
| 4537 | |
| 4538 | |
| 4539 | Diag(diag::err_ast_file_not_found) |
| 4540 | << moduleKindForDiagnostic(Type) << FileName << !ErrorStr.empty() |
| 4541 | << ErrorStr; |
| 4542 | return Failure; |
| 4543 | |
| 4544 | case ModuleManager::OutOfDate: |
| 4545 | |
| 4546 | |
| 4547 | if (ClientLoadCapabilities & ARR_OutOfDate) |
| 4548 | return OutOfDate; |
| 4549 | |
| 4550 | |
| 4551 | Diag(diag::err_ast_file_out_of_date) |
| 4552 | << moduleKindForDiagnostic(Type) << FileName << !ErrorStr.empty() |
| 4553 | << ErrorStr; |
| 4554 | return Failure; |
| 4555 | } |
| 4556 | |
| 4557 | assert(M && "Missing module file"); |
| 4558 | |
| 4559 | bool ShouldFinalizePCM = false; |
| 4560 | auto FinalizeOrDropPCM = llvm::make_scope_exit([&]() { |
| 4561 | auto &MC = getModuleManager().getModuleCache(); |
| 4562 | if (ShouldFinalizePCM) |
| 4563 | MC.finalizePCM(FileName); |
| 4564 | else |
| 4565 | MC.tryToDropPCM(FileName); |
| 4566 | }); |
| 4567 | ModuleFile &F = *M; |
| 4568 | BitstreamCursor &Stream = F.Stream; |
| 4569 | Stream = BitstreamCursor(PCHContainerRdr.ExtractPCH(*F.Buffer)); |
| 4570 | F.SizeInBits = F.Buffer->getBufferSize() * 8; |
| 4571 | |
| 4572 | |
| 4573 | if (llvm::Error Err = doesntStartWithASTFileMagic(Stream)) { |
| 4574 | Diag(diag::err_ast_file_invalid) |
| 4575 | << moduleKindForDiagnostic(Type) << FileName << std::move(Err); |
| 4576 | return Failure; |
| 4577 | } |
| 4578 | |
| 4579 | |
| 4580 | bool HaveReadControlBlock = false; |
| 4581 | while (true) { |
| 4582 | Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance(); |
| 4583 | if (!MaybeEntry) { |
| 4584 | Error(MaybeEntry.takeError()); |
| 4585 | return Failure; |
| 4586 | } |
| 4587 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 4588 | |
| 4589 | switch (Entry.Kind) { |
| 4590 | case llvm::BitstreamEntry::Error: |
| 4591 | case llvm::BitstreamEntry::Record: |
| 4592 | case llvm::BitstreamEntry::EndBlock: |
| 4593 | Error("invalid record at top-level of AST file"); |
| 4594 | return Failure; |
| 4595 | |
| 4596 | case llvm::BitstreamEntry::SubBlock: |
| 4597 | break; |
| 4598 | } |
| 4599 | |
| 4600 | switch (Entry.ID) { |
| 4601 | case CONTROL_BLOCK_ID: |
| 4602 | HaveReadControlBlock = true; |
| 4603 | switch (ReadControlBlock(F, Loaded, ImportedBy, ClientLoadCapabilities)) { |
| 4604 | case Success: |
| 4605 | |
| 4606 | |
| 4607 | |
| 4608 | |
| 4609 | if ((Type == MK_ImplicitModule || Type == MK_ExplicitModule || |
| 4610 | Type == MK_PrebuiltModule) && |
| 4611 | F.ModuleName.empty()) { |
| 4612 | auto Result = (Type == MK_ImplicitModule) ? OutOfDate : Failure; |
| 4613 | if (Result != OutOfDate || |
| 4614 | (ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 4615 | Diag(diag::err_module_file_not_module) << FileName; |
| 4616 | return Result; |
| 4617 | } |
| 4618 | break; |
| 4619 | |
| 4620 | case Failure: return Failure; |
| 4621 | case Missing: return Missing; |
| 4622 | case OutOfDate: return OutOfDate; |
| 4623 | case VersionMismatch: return VersionMismatch; |
| 4624 | case ConfigurationMismatch: return ConfigurationMismatch; |
| 4625 | case HadErrors: return HadErrors; |
| 4626 | } |
| 4627 | break; |
| 4628 | |
| 4629 | case AST_BLOCK_ID: |
| 4630 | if (!HaveReadControlBlock) { |
| 4631 | if ((ClientLoadCapabilities & ARR_VersionMismatch) == 0) |
| 4632 | Diag(diag::err_pch_version_too_old); |
| 4633 | return VersionMismatch; |
| 4634 | } |
| 4635 | |
| 4636 | |
| 4637 | Loaded.push_back(ImportedModule(M, ImportedBy, ImportLoc)); |
| 4638 | ShouldFinalizePCM = true; |
| 4639 | return Success; |
| 4640 | |
| 4641 | case UNHASHED_CONTROL_BLOCK_ID: |
| 4642 | |
| 4643 | |
| 4644 | Error("malformed block record in AST file"); |
| 4645 | return Failure; |
| 4646 | |
| 4647 | default: |
| 4648 | if (llvm::Error Err = Stream.SkipBlock()) { |
| 4649 | Error(std::move(Err)); |
| 4650 | return Failure; |
| 4651 | } |
| 4652 | break; |
| 4653 | } |
| 4654 | } |
| 4655 | |
| 4656 | llvm_unreachable("unexpected break; expected return"); |
| 4657 | } |
| 4658 | |
| 4659 | ASTReader::ASTReadResult |
| 4660 | ASTReader::readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy, |
| 4661 | unsigned ClientLoadCapabilities) { |
| 4662 | const HeaderSearchOptions &HSOpts = |
| 4663 | PP.getHeaderSearchInfo().getHeaderSearchOpts(); |
| 4664 | bool AllowCompatibleConfigurationMismatch = |
| 4665 | F.Kind == MK_ExplicitModule || F.Kind == MK_PrebuiltModule; |
| 4666 | bool DisableValidation = shouldDisableValidationForFile(F); |
| 4667 | |
| 4668 | ASTReadResult Result = readUnhashedControlBlockImpl( |
| 4669 | &F, F.Data, ClientLoadCapabilities, AllowCompatibleConfigurationMismatch, |
| 4670 | Listener.get(), |
| 4671 | WasImportedBy ? false : HSOpts.ModulesValidateDiagnosticOptions); |
| 4672 | |
| 4673 | |
| 4674 | |
| 4675 | if (DisableValidation || WasImportedBy || |
| 4676 | (AllowConfigurationMismatch && Result == ConfigurationMismatch)) |
| 4677 | return Success; |
| 4678 | |
| 4679 | if (Result == Failure) { |
| 4680 | Error("malformed block record in AST file"); |
| 4681 | return Failure; |
| 4682 | } |
| 4683 | |
| 4684 | if (Result == OutOfDate && F.Kind == MK_ImplicitModule) { |
| 4685 | |
| 4686 | |
| 4687 | |
| 4688 | |
| 4689 | |
| 4690 | |
| 4691 | |
| 4692 | |
| 4693 | |
| 4694 | |
| 4695 | |
| 4696 | |
| 4697 | |
| 4698 | |
| 4699 | |
| 4700 | |
| 4701 | |
| 4702 | |
| 4703 | if (getModuleManager().getModuleCache().isPCMFinal(F.FileName)) { |
| 4704 | Diag(diag::warn_module_system_bit_conflict) << F.FileName; |
| 4705 | return Success; |
| 4706 | } |
| 4707 | } |
| 4708 | |
| 4709 | return Result; |
| 4710 | } |
| 4711 | |
| 4712 | ASTReader::ASTReadResult ASTReader::readUnhashedControlBlockImpl( |
| 4713 | ModuleFile *F, llvm::StringRef StreamData, unsigned ClientLoadCapabilities, |
| 4714 | bool AllowCompatibleConfigurationMismatch, ASTReaderListener *Listener, |
| 4715 | bool ValidateDiagnosticOptions) { |
| 4716 | |
| 4717 | BitstreamCursor Stream(StreamData); |
| 4718 | |
| 4719 | |
| 4720 | if (llvm::Error Err = doesntStartWithASTFileMagic(Stream)) { |
| 4721 | |
| 4722 | consumeError(std::move(Err)); |
| 4723 | return Failure; |
| 4724 | } |
| 4725 | |
| 4726 | |
| 4727 | if (SkipCursorToBlock(Stream, UNHASHED_CONTROL_BLOCK_ID)) |
| 4728 | return Failure; |
| 4729 | |
| 4730 | |
| 4731 | RecordData Record; |
| 4732 | ASTReadResult Result = Success; |
| 4733 | while (true) { |
| 4734 | Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance(); |
| 4735 | if (!MaybeEntry) { |
| 4736 | |
| 4737 | consumeError(MaybeEntry.takeError()); |
| 4738 | return Failure; |
| 4739 | } |
| 4740 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 4741 | |
| 4742 | switch (Entry.Kind) { |
| 4743 | case llvm::BitstreamEntry::Error: |
| 4744 | case llvm::BitstreamEntry::SubBlock: |
| 4745 | return Failure; |
| 4746 | |
| 4747 | case llvm::BitstreamEntry::EndBlock: |
| 4748 | return Result; |
| 4749 | |
| 4750 | case llvm::BitstreamEntry::Record: |
| 4751 | |
| 4752 | break; |
| 4753 | } |
| 4754 | |
| 4755 | |
| 4756 | Record.clear(); |
| 4757 | Expected<unsigned> MaybeRecordType = Stream.readRecord(Entry.ID, Record); |
| 4758 | if (!MaybeRecordType) { |
| 4759 | |
| 4760 | return Failure; |
| 4761 | } |
| 4762 | switch ((UnhashedControlBlockRecordTypes)MaybeRecordType.get()) { |
| 4763 | case SIGNATURE: |
| 4764 | if (F) |
| 4765 | F->Signature = ASTFileSignature::create(Record.begin(), Record.end()); |
| 4766 | break; |
| 4767 | case AST_BLOCK_HASH: |
| 4768 | if (F) |
| 4769 | F->ASTBlockHash = |
| 4770 | ASTFileSignature::create(Record.begin(), Record.end()); |
| 4771 | break; |
| 4772 | case DIAGNOSTIC_OPTIONS: { |
| 4773 | bool Complain = (ClientLoadCapabilities & ARR_OutOfDate) == 0; |
| 4774 | if (Listener && ValidateDiagnosticOptions && |
| 4775 | !AllowCompatibleConfigurationMismatch && |
| 4776 | ParseDiagnosticOptions(Record, Complain, *Listener)) |
| 4777 | Result = OutOfDate; |
| 4778 | break; |
| 4779 | } |
| 4780 | case DIAG_PRAGMA_MAPPINGS: |
| 4781 | if (!F) |
| 4782 | break; |
| 4783 | if (F->PragmaDiagMappings.empty()) |
| 4784 | F->PragmaDiagMappings.swap(Record); |
| 4785 | else |
| 4786 | F->PragmaDiagMappings.insert(F->PragmaDiagMappings.end(), |
| 4787 | Record.begin(), Record.end()); |
| 4788 | break; |
| 4789 | } |
| 4790 | } |
| 4791 | } |
| 4792 | |
| 4793 | |
| 4794 | static bool parseModuleFileExtensionMetadata( |
| 4795 | const SmallVectorImpl<uint64_t> &Record, |
| 4796 | StringRef Blob, |
| 4797 | ModuleFileExtensionMetadata &Metadata) { |
| 4798 | if (Record.size() < 4) return true; |
| 4799 | |
| 4800 | Metadata.MajorVersion = Record[0]; |
| 4801 | Metadata.MinorVersion = Record[1]; |
| 4802 | |
| 4803 | unsigned BlockNameLen = Record[2]; |
| 4804 | unsigned UserInfoLen = Record[3]; |
| 4805 | |
| 4806 | if (BlockNameLen + UserInfoLen > Blob.size()) return true; |
| 4807 | |
| 4808 | Metadata.BlockName = std::string(Blob.data(), Blob.data() + BlockNameLen); |
| 4809 | Metadata.UserInfo = std::string(Blob.data() + BlockNameLen, |
| 4810 | Blob.data() + BlockNameLen + UserInfoLen); |
| 4811 | return false; |
| 4812 | } |
| 4813 | |
| 4814 | ASTReader::ASTReadResult ASTReader::ReadExtensionBlock(ModuleFile &F) { |
| 4815 | BitstreamCursor &Stream = F.Stream; |
| 4816 | |
| 4817 | RecordData Record; |
| 4818 | while (true) { |
| 4819 | Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance(); |
| 4820 | if (!MaybeEntry) { |
| 4821 | Error(MaybeEntry.takeError()); |
| 4822 | return Failure; |
| 4823 | } |
| 4824 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 4825 | |
| 4826 | switch (Entry.Kind) { |
| 4827 | case llvm::BitstreamEntry::SubBlock: |
| 4828 | if (llvm::Error Err = Stream.SkipBlock()) { |
| 4829 | Error(std::move(Err)); |
| 4830 | return Failure; |
| 4831 | } |
| 4832 | continue; |
| 4833 | |
| 4834 | case llvm::BitstreamEntry::EndBlock: |
| 4835 | return Success; |
| 4836 | |
| 4837 | case llvm::BitstreamEntry::Error: |
| 4838 | return HadErrors; |
| 4839 | |
| 4840 | case llvm::BitstreamEntry::Record: |
| 4841 | break; |
| 4842 | } |
| 4843 | |
| 4844 | Record.clear(); |
| 4845 | StringRef Blob; |
| 4846 | Expected<unsigned> MaybeRecCode = |
| 4847 | Stream.readRecord(Entry.ID, Record, &Blob); |
| 4848 | if (!MaybeRecCode) { |
| 4849 | Error(MaybeRecCode.takeError()); |
| 4850 | return Failure; |
| 4851 | } |
| 4852 | switch (MaybeRecCode.get()) { |
| 4853 | case EXTENSION_METADATA: { |
| 4854 | ModuleFileExtensionMetadata Metadata; |
| 4855 | if (parseModuleFileExtensionMetadata(Record, Blob, Metadata)) { |
| 4856 | Error("malformed EXTENSION_METADATA in AST file"); |
| 4857 | return Failure; |
| 4858 | } |
| 4859 | |
| 4860 | |
| 4861 | auto Known = ModuleFileExtensions.find(Metadata.BlockName); |
| 4862 | if (Known == ModuleFileExtensions.end()) break; |
| 4863 | |
| 4864 | |
| 4865 | if (auto Reader = Known->second->createExtensionReader(Metadata, *this, |
| 4866 | F, Stream)) { |
| 4867 | F.ExtensionReaders.push_back(std::move(Reader)); |
| 4868 | } |
| 4869 | |
| 4870 | break; |
| 4871 | } |
| 4872 | } |
| 4873 | } |
| 4874 | |
| 4875 | return Success; |
| 4876 | } |
| 4877 | |
| 4878 | void ASTReader::InitializeContext() { |
| 4879 | assert(ContextObj && "no context to initialize"); |
| 4880 | ASTContext &Context = *ContextObj; |
| 4881 | |
| 4882 | |
| 4883 | if (DeserializationListener) |
| 17 | | Assuming field 'DeserializationListener' is null | |
|
| |
| 4884 | DeserializationListener->DeclRead(PREDEF_DECL_TRANSLATION_UNIT_ID, |
| 4885 | Context.getTranslationUnitDecl()); |
| 4886 | |
| 4887 | |
| 4888 | |
| 4889 | |
| 4890 | |
| 4891 | if (SpecialTypes.size() >= NumSpecialTypeIDs) { |
| 19 | | Assuming the condition is true | |
|
| |
| 4892 | if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) { |
| |
| |
| 4893 | if (!Context.CFConstantStringTypeDecl) |
| 4894 | Context.setCFConstantStringType(GetType(String)); |
| 4895 | } |
| 4896 | |
| 4897 | if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) { |
| |
| |
| 4898 | QualType FileType = GetType(File); |
| 4899 | if (FileType.isNull()) { |
| 4900 | Error("FILE type is NULL"); |
| 4901 | return; |
| 4902 | } |
| 4903 | |
| 4904 | if (!Context.FILEDecl) { |
| 4905 | if (const TypedefType *Typedef = FileType->getAs<TypedefType>()) |
| 4906 | Context.setFILEDecl(Typedef->getDecl()); |
| 4907 | else { |
| 4908 | const TagType *Tag = FileType->getAs<TagType>(); |
| 4909 | if (!Tag) { |
| 4910 | Error("Invalid FILE type in AST file"); |
| 4911 | return; |
| 4912 | } |
| 4913 | Context.setFILEDecl(Tag->getDecl()); |
| 4914 | } |
| 4915 | } |
| 4916 | } |
| 4917 | |
| 4918 | if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_JMP_BUF]) { |
| 25 | | Assuming 'Jmp_buf' is 0 | |
|
| |
| 4919 | QualType Jmp_bufType = GetType(Jmp_buf); |
| 4920 | if (Jmp_bufType.isNull()) { |
| 4921 | Error("jmp_buf type is NULL"); |
| 4922 | return; |
| 4923 | } |
| 4924 | |
| 4925 | if (!Context.jmp_bufDecl) { |
| 4926 | if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>()) |
| 4927 | Context.setjmp_bufDecl(Typedef->getDecl()); |
| 4928 | else { |
| 4929 | const TagType *Tag = Jmp_bufType->getAs<TagType>(); |
| 4930 | if (!Tag) { |
| 4931 | Error("Invalid jmp_buf type in AST file"); |
| 4932 | return; |
| 4933 | } |
| 4934 | Context.setjmp_bufDecl(Tag->getDecl()); |
| 4935 | } |
| 4936 | } |
| 4937 | } |
| 4938 | |
| 4939 | if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_SIGJMP_BUF]) { |
| 27 | | Assuming 'Sigjmp_buf' is not equal to 0 | |
|
| |
| 4940 | QualType Sigjmp_bufType = GetType(Sigjmp_buf); |
| 4941 | if (Sigjmp_bufType.isNull()) { |
| 29 | | Calling 'QualType::isNull' | |
|
| 35 | | Returning from 'QualType::isNull' | |
|
| |
| 4942 | Error("sigjmp_buf type is NULL"); |
| 4943 | return; |
| 4944 | } |
| 4945 | |
| 4946 | if (!Context.sigjmp_bufDecl) { |
| 37 | | Assuming field 'sigjmp_bufDecl' is null | |
|
| |
| 4947 | if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>()) |
| 39 | | Assuming the object is not a 'TypedefType' | |
|
| |
| 4948 | Context.setsigjmp_bufDecl(Typedef->getDecl()); |
| 4949 | else { |
| 4950 | const TagType *Tag = Sigjmp_bufType->getAs<TagType>(); |
| 41 | | Assuming the object is not a 'TagType' | |
|
| 42 | | 'Tag' initialized to a null pointer value | |
|
| 4951 | assert(Tag && "Invalid sigjmp_buf type in AST file"); |
| 4952 | Context.setsigjmp_bufDecl(Tag->getDecl()); |
| 43 | | Called C++ object pointer is null |
|
| 4953 | } |
| 4954 | } |
| 4955 | } |
| 4956 | |
| 4957 | if (unsigned ObjCIdRedef |
| 4958 | = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) { |
| 4959 | if (Context.ObjCIdRedefinitionType.isNull()) |
| 4960 | Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef); |
| 4961 | } |
| 4962 | |
| 4963 | if (unsigned ObjCClassRedef |
| 4964 | = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) { |
| 4965 | if (Context.ObjCClassRedefinitionType.isNull()) |
| 4966 | Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef); |
| 4967 | } |
| 4968 | |
| 4969 | if (unsigned ObjCSelRedef |
| 4970 | = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) { |
| 4971 | if (Context.ObjCSelRedefinitionType.isNull()) |
| 4972 | Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef); |
| 4973 | } |
| 4974 | |
| 4975 | if (unsigned Ucontext_t = SpecialTypes[SPECIAL_TYPE_UCONTEXT_T]) { |
| 4976 | QualType Ucontext_tType = GetType(Ucontext_t); |
| 4977 | if (Ucontext_tType.isNull()) { |
| 4978 | Error("ucontext_t type is NULL"); |
| 4979 | return; |
| 4980 | } |
| 4981 | |
| 4982 | if (!Context.ucontext_tDecl) { |
| 4983 | if (const TypedefType *Typedef = Ucontext_tType->getAs<TypedefType>()) |
| 4984 | Context.setucontext_tDecl(Typedef->getDecl()); |
| 4985 | else { |
| 4986 | const TagType *Tag = Ucontext_tType->getAs<TagType>(); |
| 4987 | assert(Tag && "Invalid ucontext_t type in AST file"); |
| 4988 | Context.setucontext_tDecl(Tag->getDecl()); |
| 4989 | } |
| 4990 | } |
| 4991 | } |
| 4992 | } |
| 4993 | |
| 4994 | ReadPragmaDiagnosticMappings(Context.getDiagnostics()); |
| 4995 | |
| 4996 | |
| 4997 | if (!CUDASpecialDeclRefs.empty()) { |
| 4998 | assert(CUDASpecialDeclRefs.size() == 1 && "More decl refs than expected!"); |
| 4999 | Context.setcudaConfigureCallDecl( |
| 5000 | cast<FunctionDecl>(GetDecl(CUDASpecialDeclRefs[0]))); |
| 5001 | } |
| 5002 | |
| 5003 | |
| 5004 | |
| 5005 | for (auto &Import : ImportedModules) { |
| 5006 | if (Module *Imported = getSubmodule(Import.ID)) { |
| 5007 | makeModuleVisible(Imported, Module::AllVisible, |
| 5008 | Import.ImportLoc); |
| 5009 | if (Import.ImportLoc.isValid()) |
| 5010 | PP.makeModuleVisible(Imported, Import.ImportLoc); |
| 5011 | |
| 5012 | |
| 5013 | } |
| 5014 | } |
| 5015 | } |
| 5016 | |
| 5017 | void ASTReader::finalizeForWriting() { |
| 5018 | |
| 5019 | } |
| 5020 | |
| 5021 | |
| 5022 | |
| 5023 | static ASTFileSignature readASTFileSignature(StringRef PCH) { |
| 5024 | BitstreamCursor Stream(PCH); |
| 5025 | if (llvm::Error Err = doesntStartWithASTFileMagic(Stream)) { |
| 5026 | |
| 5027 | consumeError(std::move(Err)); |
| 5028 | return ASTFileSignature(); |
| 5029 | } |
| 5030 | |
| 5031 | |
| 5032 | if (SkipCursorToBlock(Stream, UNHASHED_CONTROL_BLOCK_ID)) |
| 5033 | return ASTFileSignature(); |
| 5034 | |
| 5035 | |
| 5036 | ASTReader::RecordData Record; |
| 5037 | while (true) { |
| 5038 | Expected<llvm::BitstreamEntry> MaybeEntry = |
| 5039 | Stream.advanceSkippingSubblocks(); |
| 5040 | if (!MaybeEntry) { |
| 5041 | |
| 5042 | consumeError(MaybeEntry.takeError()); |
| 5043 | return ASTFileSignature(); |
| 5044 | } |
| 5045 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 5046 | |
| 5047 | if (Entry.Kind != llvm::BitstreamEntry::Record) |
| 5048 | return ASTFileSignature(); |
| 5049 | |
| 5050 | Record.clear(); |
| 5051 | StringRef Blob; |
| 5052 | Expected<unsigned> MaybeRecord = Stream.readRecord(Entry.ID, Record, &Blob); |
| 5053 | if (!MaybeRecord) { |
| 5054 | |
| 5055 | consumeError(MaybeRecord.takeError()); |
| 5056 | return ASTFileSignature(); |
| 5057 | } |
| 5058 | if (SIGNATURE == MaybeRecord.get()) |
| 5059 | return ASTFileSignature::create(Record.begin(), |
| 5060 | Record.begin() + ASTFileSignature::size); |
| 5061 | } |
| 5062 | } |
| 5063 | |
| 5064 | |
| 5065 | |
| 5066 | |
| 5067 | std::string ASTReader::getOriginalSourceFile( |
| 5068 | const std::string &ASTFileName, FileManager &FileMgr, |
| 5069 | const PCHContainerReader &PCHContainerRdr, DiagnosticsEngine &Diags) { |
| 5070 | |
| 5071 | auto Buffer = FileMgr.getBufferForFile(ASTFileName); |
| 5072 | if (!Buffer) { |
| 5073 | Diags.Report(diag::err_fe_unable_to_read_pch_file) |
| 5074 | << ASTFileName << Buffer.getError().message(); |
| 5075 | return std::string(); |
| 5076 | } |
| 5077 | |
| 5078 | |
| 5079 | BitstreamCursor Stream(PCHContainerRdr.ExtractPCH(**Buffer)); |
| 5080 | |
| 5081 | |
| 5082 | if (llvm::Error Err = doesntStartWithASTFileMagic(Stream)) { |
| 5083 | Diags.Report(diag::err_fe_not_a_pch_file) << ASTFileName << std::move(Err); |
| 5084 | return std::string(); |
| 5085 | } |
| 5086 | |
| 5087 | |
| 5088 | if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) { |
| 5089 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
| 5090 | return std::string(); |
| 5091 | } |
| 5092 | |
| 5093 | |
| 5094 | RecordData Record; |
| 5095 | while (true) { |
| 5096 | Expected<llvm::BitstreamEntry> MaybeEntry = |
| 5097 | Stream.advanceSkippingSubblocks(); |
| 5098 | if (!MaybeEntry) { |
| 5099 | |
| 5100 | consumeError(MaybeEntry.takeError()); |
| 5101 | return std::string(); |
| 5102 | } |
| 5103 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 5104 | |
| 5105 | if (Entry.Kind == llvm::BitstreamEntry::EndBlock) |
| 5106 | return std::string(); |
| 5107 | |
| 5108 | if (Entry.Kind != llvm::BitstreamEntry::Record) { |
| 5109 | Diags.Report(diag::err_fe_pch_malformed_block) << ASTFileName; |
| 5110 | return std::string(); |
| 5111 | } |
| 5112 | |
| 5113 | Record.clear(); |
| 5114 | StringRef Blob; |
| 5115 | Expected<unsigned> MaybeRecord = Stream.readRecord(Entry.ID, Record, &Blob); |
| 5116 | if (!MaybeRecord) { |
| 5117 | |
| 5118 | consumeError(MaybeRecord.takeError()); |
| 5119 | return std::string(); |
| 5120 | } |
| 5121 | if (ORIGINAL_FILE == MaybeRecord.get()) |
| 5122 | return Blob.str(); |
| 5123 | } |
| 5124 | } |
| 5125 | |
| 5126 | namespace { |
| 5127 | |
| 5128 | class SimplePCHValidator : public ASTReaderListener { |
| 5129 | const LangOptions &ExistingLangOpts; |
| 5130 | const TargetOptions &ExistingTargetOpts; |
| 5131 | const PreprocessorOptions &ExistingPPOpts; |
| 5132 | std::string ExistingModuleCachePath; |
| 5133 | FileManager &FileMgr; |
| 5134 | |
| 5135 | public: |
| 5136 | SimplePCHValidator(const LangOptions &ExistingLangOpts, |
| 5137 | const TargetOptions &ExistingTargetOpts, |
| 5138 | const PreprocessorOptions &ExistingPPOpts, |
| 5139 | StringRef ExistingModuleCachePath, FileManager &FileMgr) |
| 5140 | : ExistingLangOpts(ExistingLangOpts), |
| 5141 | ExistingTargetOpts(ExistingTargetOpts), |
| 5142 | ExistingPPOpts(ExistingPPOpts), |
| 5143 | ExistingModuleCachePath(ExistingModuleCachePath), FileMgr(FileMgr) {} |
| 5144 | |
| 5145 | bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain, |
| 5146 | bool AllowCompatibleDifferences) override { |
| 5147 | return checkLanguageOptions(ExistingLangOpts, LangOpts, nullptr, |
| 5148 | AllowCompatibleDifferences); |
| 5149 | } |
| 5150 | |
| 5151 | bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain, |
| 5152 | bool AllowCompatibleDifferences) override { |
| 5153 | return checkTargetOptions(ExistingTargetOpts, TargetOpts, nullptr, |
| 5154 | AllowCompatibleDifferences); |
| 5155 | } |
| 5156 | |
| 5157 | bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, |
| 5158 | StringRef SpecificModuleCachePath, |
| 5159 | bool Complain) override { |
| 5160 | return checkHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 5161 | ExistingModuleCachePath, nullptr, |
| 5162 | ExistingLangOpts, ExistingPPOpts); |
| 5163 | } |
| 5164 | |
| 5165 | bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, |
| 5166 | bool Complain, |
| 5167 | std::string &SuggestedPredefines) override { |
| 5168 | return checkPreprocessorOptions(ExistingPPOpts, PPOpts, nullptr, FileMgr, |
| 5169 | SuggestedPredefines, ExistingLangOpts); |
| 5170 | } |
| 5171 | }; |
| 5172 | |
| 5173 | } |
| 5174 | |
| 5175 | bool ASTReader::readASTFileControlBlock( |
| 5176 | StringRef Filename, FileManager &FileMgr, |
| 5177 | const PCHContainerReader &PCHContainerRdr, |
| 5178 | bool FindModuleFileExtensions, |
| 5179 | ASTReaderListener &Listener, bool ValidateDiagnosticOptions) { |
| 5180 | |
| 5181 | |
| 5182 | |
| 5183 | auto Buffer = FileMgr.getBufferForFile(Filename); |
| 5184 | if (!Buffer) { |
| 5185 | return true; |
| 5186 | } |
| 5187 | |
| 5188 | |
| 5189 | StringRef Bytes = PCHContainerRdr.ExtractPCH(**Buffer); |
| 5190 | BitstreamCursor Stream(Bytes); |
| 5191 | |
| 5192 | |
| 5193 | if (llvm::Error Err = doesntStartWithASTFileMagic(Stream)) { |
| 5194 | consumeError(std::move(Err)); |
| 5195 | return true; |
| 5196 | } |
| 5197 | |
| 5198 | |
| 5199 | if (SkipCursorToBlock(Stream, CONTROL_BLOCK_ID)) |
| 5200 | return true; |
| 5201 | |
| 5202 | bool NeedsInputFiles = Listener.needsInputFileVisitation(); |
| 5203 | bool NeedsSystemInputFiles = Listener.needsSystemInputFileVisitation(); |
| 5204 | bool NeedsImports = Listener.needsImportVisitation(); |
| 5205 | BitstreamCursor InputFilesCursor; |
| 5206 | |
| 5207 | RecordData Record; |
| 5208 | std::string ModuleDir; |
| 5209 | bool DoneWithControlBlock = false; |
| 5210 | while (!DoneWithControlBlock) { |
| 5211 | Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance(); |
| 5212 | if (!MaybeEntry) { |
| 5213 | |
| 5214 | consumeError(MaybeEntry.takeError()); |
| 5215 | return true; |
| 5216 | } |
| 5217 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 5218 | |
| 5219 | switch (Entry.Kind) { |
| 5220 | case llvm::BitstreamEntry::SubBlock: { |
| 5221 | switch (Entry.ID) { |
| 5222 | case OPTIONS_BLOCK_ID: { |
| 5223 | std::string IgnoredSuggestedPredefines; |
| 5224 | if (ReadOptionsBlock(Stream, ARR_ConfigurationMismatch | ARR_OutOfDate, |
| 5225 | false, |
| 5226 | Listener, IgnoredSuggestedPredefines) != Success) |
| 5227 | return true; |
| 5228 | break; |
| 5229 | } |
| 5230 | |
| 5231 | case INPUT_FILES_BLOCK_ID: |
| 5232 | InputFilesCursor = Stream; |
| 5233 | if (llvm::Error Err = Stream.SkipBlock()) { |
| 5234 | |
| 5235 | consumeError(std::move(Err)); |
| 5236 | return true; |
| 5237 | } |
| 5238 | if (NeedsInputFiles && |
| 5239 | ReadBlockAbbrevs(InputFilesCursor, INPUT_FILES_BLOCK_ID)) |
| 5240 | return true; |
| 5241 | break; |
| 5242 | |
| 5243 | default: |
| 5244 | if (llvm::Error Err = Stream.SkipBlock()) { |
| 5245 | |
| 5246 | consumeError(std::move(Err)); |
| 5247 | return true; |
| 5248 | } |
| 5249 | break; |
| 5250 | } |
| 5251 | |
| 5252 | continue; |
| 5253 | } |
| 5254 | |
| 5255 | case llvm::BitstreamEntry::EndBlock: |
| 5256 | DoneWithControlBlock = true; |
| 5257 | break; |
| 5258 | |
| 5259 | case llvm::BitstreamEntry::Error: |
| 5260 | return true; |
| 5261 | |
| 5262 | case llvm::BitstreamEntry::Record: |
| 5263 | break; |
| 5264 | } |
| 5265 | |
| 5266 | if (DoneWithControlBlock) break; |
| 5267 | |
| 5268 | Record.clear(); |
| 5269 | StringRef Blob; |
| 5270 | Expected<unsigned> MaybeRecCode = |
| 5271 | Stream.readRecord(Entry.ID, Record, &Blob); |
| 5272 | if (!MaybeRecCode) { |
| 5273 | |
| 5274 | return Failure; |
| 5275 | } |
| 5276 | switch ((ControlRecordTypes)MaybeRecCode.get()) { |
| 5277 | case METADATA: |
| 5278 | if (Record[0] != VERSION_MAJOR) |
| 5279 | return true; |
| 5280 | if (Listener.ReadFullVersionInformation(Blob)) |
| 5281 | return true; |
| 5282 | break; |
| 5283 | case MODULE_NAME: |
| 5284 | Listener.ReadModuleName(Blob); |
| 5285 | break; |
| 5286 | case MODULE_DIRECTORY: |
| 5287 | ModuleDir = std::string(Blob); |
| 5288 | break; |
| 5289 | case MODULE_MAP_FILE: { |
| 5290 | unsigned Idx = 0; |
| 5291 | auto Path = ReadString(Record, Idx); |
| 5292 | ResolveImportedPath(Path, ModuleDir); |
| 5293 | Listener.ReadModuleMapFile(Path); |
| 5294 | break; |
| 5295 | } |
| 5296 | case INPUT_FILE_OFFSETS: { |
| 5297 | if (!NeedsInputFiles) |
| 5298 | break; |
| 5299 | |
| 5300 | unsigned NumInputFiles = Record[0]; |
| 5301 | unsigned NumUserFiles = Record[1]; |
| 5302 | const llvm::support::unaligned_uint64_t *InputFileOffs = |
| 5303 | (const llvm::support::unaligned_uint64_t *)Blob.data(); |
| 5304 | for (unsigned I = 0; I != NumInputFiles; ++I) { |
| 5305 | |
| 5306 | bool isSystemFile = I >= NumUserFiles; |
| 5307 | |
| 5308 | if (isSystemFile && !NeedsSystemInputFiles) |
| 5309 | break; |
| 5310 | |
| 5311 | BitstreamCursor &Cursor = InputFilesCursor; |
| 5312 | SavedStreamPosition SavedPosition(Cursor); |
| 5313 | if (llvm::Error Err = Cursor.JumpToBit(InputFileOffs[I])) { |
| 5314 | |
| 5315 | consumeError(std::move(Err)); |
| 5316 | } |
| 5317 | |
| 5318 | Expected<unsigned> MaybeCode = Cursor.ReadCode(); |
| 5319 | if (!MaybeCode) { |
| 5320 | |
| 5321 | consumeError(MaybeCode.takeError()); |
| 5322 | } |
| 5323 | unsigned Code = MaybeCode.get(); |
| 5324 | |
| 5325 | RecordData Record; |
| 5326 | StringRef Blob; |
| 5327 | bool shouldContinue = false; |
| 5328 | Expected<unsigned> MaybeRecordType = |
| 5329 | Cursor.readRecord(Code, Record, &Blob); |
| 5330 | if (!MaybeRecordType) { |
| 5331 | |
| 5332 | consumeError(MaybeRecordType.takeError()); |
| 5333 | } |
| 5334 | switch ((InputFileRecordTypes)MaybeRecordType.get()) { |
| 5335 | case INPUT_FILE_HASH: |
| 5336 | break; |
| 5337 | case INPUT_FILE: |
| 5338 | bool Overridden = static_cast<bool>(Record[3]); |
| 5339 | std::string Filename = std::string(Blob); |
| 5340 | ResolveImportedPath(Filename, ModuleDir); |
| 5341 | shouldContinue = Listener.visitInputFile( |
| 5342 | Filename, isSystemFile, Overridden, false); |
| 5343 | break; |
| 5344 | } |
| 5345 | if (!shouldContinue) |
| 5346 | break; |
| 5347 | } |
| 5348 | break; |
| 5349 | } |
| 5350 | |
| 5351 | case IMPORTS: { |
| 5352 | if (!NeedsImports) |
| 5353 | break; |
| 5354 | |
| 5355 | unsigned Idx = 0, N = Record.size(); |
| 5356 | while (Idx < N) { |
| 5357 | |
| 5358 | Idx += |
| 5359 | 1 + 1 + 1 + 1 + |
| 5360 | ASTFileSignature::size; |
| 5361 | std::string ModuleName = ReadString(Record, Idx); |
| 5362 | std::string Filename = ReadString(Record, Idx); |
| 5363 | ResolveImportedPath(Filename, ModuleDir); |
| 5364 | Listener.visitImport(ModuleName, Filename); |
| 5365 | } |
| 5366 | break; |
| 5367 | } |
| 5368 | |
| 5369 | default: |
| 5370 | |
| 5371 | break; |
| 5372 | } |
| 5373 | } |
| 5374 | |
| 5375 | |
| 5376 | if (FindModuleFileExtensions) { |
| 5377 | BitstreamCursor SavedStream = Stream; |
| 5378 | while (!SkipCursorToBlock(Stream, EXTENSION_BLOCK_ID)) { |
| 5379 | bool DoneWithExtensionBlock = false; |
| 5380 | while (!DoneWithExtensionBlock) { |
| 5381 | Expected<llvm::BitstreamEntry> MaybeEntry = Stream.advance(); |
| 5382 | if (!MaybeEntry) { |
| 5383 | |
| 5384 | return true; |
| 5385 | } |
| 5386 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 5387 | |
| 5388 | switch (Entry.Kind) { |
| 5389 | case llvm::BitstreamEntry::SubBlock: |
| 5390 | if (llvm::Error Err = Stream.SkipBlock()) { |
| 5391 | |
| 5392 | consumeError(std::move(Err)); |
| 5393 | return true; |
| 5394 | } |
| 5395 | continue; |
| 5396 | |
| 5397 | case llvm::BitstreamEntry::EndBlock: |
| 5398 | DoneWithExtensionBlock = true; |
| 5399 | continue; |
| 5400 | |
| 5401 | case llvm::BitstreamEntry::Error: |
| 5402 | return true; |
| 5403 | |
| 5404 | case llvm::BitstreamEntry::Record: |
| 5405 | break; |
| 5406 | } |
| 5407 | |
| 5408 | Record.clear(); |
| 5409 | StringRef Blob; |
| 5410 | Expected<unsigned> MaybeRecCode = |
| 5411 | Stream.readRecord(Entry.ID, Record, &Blob); |
| 5412 | if (!MaybeRecCode) { |
| 5413 | |
| 5414 | return true; |
| 5415 | } |
| 5416 | switch (MaybeRecCode.get()) { |
| 5417 | case EXTENSION_METADATA: { |
| 5418 | ModuleFileExtensionMetadata Metadata; |
| 5419 | if (parseModuleFileExtensionMetadata(Record, Blob, Metadata)) |
| 5420 | return true; |
| 5421 | |
| 5422 | Listener.readModuleFileExtension(Metadata); |
| 5423 | break; |
| 5424 | } |
| 5425 | } |
| 5426 | } |
| 5427 | } |
| 5428 | Stream = SavedStream; |
| 5429 | } |
| 5430 | |
| 5431 | |
| 5432 | if (readUnhashedControlBlockImpl( |
| 5433 | nullptr, Bytes, ARR_ConfigurationMismatch | ARR_OutOfDate, |
| 5434 | false, &Listener, |
| 5435 | ValidateDiagnosticOptions) != Success) |
| 5436 | return true; |
| 5437 | |
| 5438 | return false; |
| 5439 | } |
| 5440 | |
| 5441 | bool ASTReader::isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, |
| 5442 | const PCHContainerReader &PCHContainerRdr, |
| 5443 | const LangOptions &LangOpts, |
| 5444 | const TargetOptions &TargetOpts, |
| 5445 | const PreprocessorOptions &PPOpts, |
| 5446 | StringRef ExistingModuleCachePath) { |
| 5447 | SimplePCHValidator validator(LangOpts, TargetOpts, PPOpts, |
| 5448 | ExistingModuleCachePath, FileMgr); |
| 5449 | return !readASTFileControlBlock(Filename, FileMgr, PCHContainerRdr, |
| 5450 | false, |
| 5451 | validator, |
| 5452 | true); |
| 5453 | } |
| 5454 | |
| 5455 | ASTReader::ASTReadResult |
| 5456 | ASTReader::ReadSubmoduleBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { |
| 5457 | |
| 5458 | if (llvm::Error Err = F.Stream.EnterSubBlock(SUBMODULE_BLOCK_ID)) { |
| 5459 | Error(std::move(Err)); |
| 5460 | return Failure; |
| 5461 | } |
| 5462 | |
| 5463 | ModuleMap &ModMap = PP.getHeaderSearchInfo().getModuleMap(); |
| 5464 | bool First = true; |
| 5465 | Module *CurrentModule = nullptr; |
| 5466 | RecordData Record; |
| 5467 | while (true) { |
| 5468 | Expected<llvm::BitstreamEntry> MaybeEntry = |
| 5469 | F.Stream.advanceSkippingSubblocks(); |
| 5470 | if (!MaybeEntry) { |
| 5471 | Error(MaybeEntry.takeError()); |
| 5472 | return Failure; |
| 5473 | } |
| 5474 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 5475 | |
| 5476 | switch (Entry.Kind) { |
| 5477 | case llvm::BitstreamEntry::SubBlock: |
| 5478 | case llvm::BitstreamEntry::Error: |
| 5479 | Error("malformed block record in AST file"); |
| 5480 | return Failure; |
| 5481 | case llvm::BitstreamEntry::EndBlock: |
| 5482 | return Success; |
| 5483 | case llvm::BitstreamEntry::Record: |
| 5484 | |
| 5485 | break; |
| 5486 | } |
| 5487 | |
| 5488 | |
| 5489 | StringRef Blob; |
| 5490 | Record.clear(); |
| 5491 | Expected<unsigned> MaybeKind = F.Stream.readRecord(Entry.ID, Record, &Blob); |
| 5492 | if (!MaybeKind) { |
| 5493 | Error(MaybeKind.takeError()); |
| 5494 | return Failure; |
| 5495 | } |
| 5496 | unsigned Kind = MaybeKind.get(); |
| 5497 | |
| 5498 | if ((Kind == SUBMODULE_METADATA) != First) { |
| 5499 | Error("submodule metadata record should be at beginning of block"); |
| 5500 | return Failure; |
| 5501 | } |
| 5502 | First = false; |
| 5503 | |
| 5504 | |
| 5505 | |
| 5506 | if (!CurrentModule && Kind != SUBMODULE_METADATA && |
| 5507 | Kind != SUBMODULE_DEFINITION) |
| 5508 | continue; |
| 5509 | |
| 5510 | switch (Kind) { |
| 5511 | default: |
| 5512 | break; |
| 5513 | |
| 5514 | case SUBMODULE_DEFINITION: { |
| 5515 | if (Record.size() < 12) { |
| 5516 | Error("malformed module definition"); |
| 5517 | return Failure; |
| 5518 | } |
| 5519 | |
| 5520 | StringRef Name = Blob; |
| 5521 | unsigned Idx = 0; |
| 5522 | SubmoduleID GlobalID = getGlobalSubmoduleID(F, Record[Idx++]); |
| 5523 | SubmoduleID Parent = getGlobalSubmoduleID(F, Record[Idx++]); |
| 5524 | Module::ModuleKind Kind = (Module::ModuleKind)Record[Idx++]; |
| 5525 | bool IsFramework = Record[Idx++]; |
| 5526 | bool IsExplicit = Record[Idx++]; |
| 5527 | bool IsSystem = Record[Idx++]; |
| 5528 | bool IsExternC = Record[Idx++]; |
| 5529 | bool InferSubmodules = Record[Idx++]; |
| 5530 | bool InferExplicitSubmodules = Record[Idx++]; |
| 5531 | bool InferExportWildcard = Record[Idx++]; |
| 5532 | bool ConfigMacrosExhaustive = Record[Idx++]; |
| 5533 | bool ModuleMapIsPrivate = Record[Idx++]; |
| 5534 | |
| 5535 | Module *ParentModule = nullptr; |
| 5536 | if (Parent) |
| 5537 | ParentModule = getSubmodule(Parent); |
| 5538 | |
| 5539 | |
| 5540 | |
| 5541 | CurrentModule = |
| 5542 | ModMap.findOrCreateModule(Name, ParentModule, IsFramework, IsExplicit) |
| 5543 | .first; |
| 5544 | |
| 5545 | |
| 5546 | |
| 5547 | |
| 5548 | SubmoduleID GlobalIndex = GlobalID - NUM_PREDEF_SUBMODULE_IDS; |
| 5549 | if (GlobalIndex >= SubmodulesLoaded.size() || |
| 5550 | SubmodulesLoaded[GlobalIndex]) { |
| 5551 | Error("too many submodules"); |
| 5552 | return Failure; |
| 5553 | } |
| 5554 | |
| 5555 | if (!ParentModule) { |
| 5556 | if (const FileEntry *CurFile = CurrentModule->getASTFile()) { |
| 5557 | |
| 5558 | if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation & |
| 5559 | DisableValidationForModuleKind::Module) && |
| 5560 | CurFile != F.File) { |
| 5561 | Error(diag::err_module_file_conflict, |
| 5562 | CurrentModule->getTopLevelModuleName(), CurFile->getName(), |
| 5563 | F.File->getName()); |
| 5564 | return Failure; |
| 5565 | } |
| 5566 | } |
| 5567 | |
| 5568 | F.DidReadTopLevelSubmodule = true; |
| 5569 | CurrentModule->setASTFile(F.File); |
| 5570 | CurrentModule->PresumedModuleMapFile = F.ModuleMapPath; |
| 5571 | } |
| 5572 | |
| 5573 | CurrentModule->Kind = Kind; |
| 5574 | CurrentModule->Signature = F.Signature; |
| 5575 | CurrentModule->IsFromModuleFile = true; |
| 5576 | CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem; |
| 5577 | CurrentModule->IsExternC = IsExternC; |
| 5578 | CurrentModule->InferSubmodules = InferSubmodules; |
| 5579 | CurrentModule->InferExplicitSubmodules = InferExplicitSubmodules; |
| 5580 | CurrentModule->InferExportWildcard = InferExportWildcard; |
| 5581 | CurrentModule->ConfigMacrosExhaustive = ConfigMacrosExhaustive; |
| 5582 | CurrentModule->ModuleMapIsPrivate = ModuleMapIsPrivate; |
| 5583 | if (DeserializationListener) |
| 5584 | DeserializationListener->ModuleRead(GlobalID, CurrentModule); |
| 5585 | |
| 5586 | SubmodulesLoaded[GlobalIndex] = CurrentModule; |
| 5587 | |
| 5588 | |
| 5589 | CurrentModule->LinkLibraries.clear(); |
| 5590 | CurrentModule->ConfigMacros.clear(); |
| 5591 | CurrentModule->UnresolvedConflicts.clear(); |
| 5592 | CurrentModule->Conflicts.clear(); |
| 5593 | |
| 5594 | |
| 5595 | |
| 5596 | |
| 5597 | |
| 5598 | |
| 5599 | CurrentModule->Requirements.clear(); |
| 5600 | CurrentModule->MissingHeaders.clear(); |
| 5601 | CurrentModule->IsUnimportable = |
| 5602 | ParentModule && ParentModule->IsUnimportable; |
| 5603 | CurrentModule->IsAvailable = !CurrentModule->IsUnimportable; |
| 5604 | break; |
| 5605 | } |
| 5606 | |
| 5607 | case SUBMODULE_UMBRELLA_HEADER: { |
| 5608 | std::string Filename = std::string(Blob); |
| 5609 | ResolveImportedPath(F, Filename); |
| 5610 | if (auto Umbrella = PP.getFileManager().getFile(Filename)) { |
| 5611 | if (!CurrentModule->getUmbrellaHeader()) |
| 5612 | |
| 5613 | ModMap.setUmbrellaHeader(CurrentModule, *Umbrella, Blob, ""); |
| 5614 | else if (CurrentModule->getUmbrellaHeader().Entry != *Umbrella) { |
| 5615 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 5616 | Error("mismatched umbrella headers in submodule"); |
| 5617 | return OutOfDate; |
| 5618 | } |
| 5619 | } |
| 5620 | break; |
| 5621 | } |
| 5622 | |
| 5623 | case SUBMODULE_HEADER: |
| 5624 | case SUBMODULE_EXCLUDED_HEADER: |
| 5625 | case SUBMODULE_PRIVATE_HEADER: |
| 5626 | |
| 5627 | |
| 5628 | |
| 5629 | break; |
| 5630 | |
| 5631 | case SUBMODULE_TEXTUAL_HEADER: |
| 5632 | case SUBMODULE_PRIVATE_TEXTUAL_HEADER: |
| 5633 | |
| 5634 | |
| 5635 | break; |
| 5636 | |
| 5637 | case SUBMODULE_TOPHEADER: |
| 5638 | CurrentModule->addTopHeaderFilename(Blob); |
| 5639 | break; |
| 5640 | |
| 5641 | case SUBMODULE_UMBRELLA_DIR: { |
| 5642 | std::string Dirname = std::string(Blob); |
| 5643 | ResolveImportedPath(F, Dirname); |
| 5644 | if (auto Umbrella = PP.getFileManager().getDirectory(Dirname)) { |
| 5645 | if (!CurrentModule->getUmbrellaDir()) |
| 5646 | |
| 5647 | ModMap.setUmbrellaDir(CurrentModule, *Umbrella, Blob, ""); |
| 5648 | else if (CurrentModule->getUmbrellaDir().Entry != *Umbrella) { |
| 5649 | if ((ClientLoadCapabilities & ARR_OutOfDate) == 0) |
| 5650 | Error("mismatched umbrella directories in submodule"); |
| 5651 | return OutOfDate; |
| 5652 | } |
| 5653 | } |
| 5654 | break; |
| 5655 | } |
| 5656 | |
| 5657 | case SUBMODULE_METADATA: { |
| 5658 | F.BaseSubmoduleID = getTotalNumSubmodules(); |
| 5659 | F.LocalNumSubmodules = Record[0]; |
| 5660 | unsigned LocalBaseSubmoduleID = Record[1]; |
| 5661 | if (F.LocalNumSubmodules > 0) { |
| 5662 | |
| 5663 | |
| 5664 | GlobalSubmoduleMap.insert(std::make_pair(getTotalNumSubmodules()+1,&F)); |
| 5665 | |
| 5666 | |
| 5667 | |
| 5668 | F.SubmoduleRemap.insertOrReplace( |
| 5669 | std::make_pair(LocalBaseSubmoduleID, |
| 5670 | F.BaseSubmoduleID - LocalBaseSubmoduleID)); |
| 5671 | |
| 5672 | SubmodulesLoaded.resize(SubmodulesLoaded.size() + F.LocalNumSubmodules); |
| 5673 | } |
| 5674 | break; |
| 5675 | } |
| 5676 | |
| 5677 | case SUBMODULE_IMPORTS: |
| 5678 | for (unsigned Idx = 0; Idx != Record.size(); ++Idx) { |
| 5679 | UnresolvedModuleRef Unresolved; |
| 5680 | Unresolved.File = &F; |
| 5681 | Unresolved.Mod = CurrentModule; |
| 5682 | Unresolved.ID = Record[Idx]; |
| 5683 | Unresolved.Kind = UnresolvedModuleRef::Import; |
| 5684 | Unresolved.IsWildcard = false; |
| 5685 | UnresolvedModuleRefs.push_back(Unresolved); |
| 5686 | } |
| 5687 | break; |
| 5688 | |
| 5689 | case SUBMODULE_EXPORTS: |
| 5690 | for (unsigned Idx = 0; Idx + 1 < Record.size(); Idx += 2) { |
| 5691 | UnresolvedModuleRef Unresolved; |
| 5692 | Unresolved.File = &F; |
| 5693 | Unresolved.Mod = CurrentModule; |
| 5694 | Unresolved.ID = Record[Idx]; |
| 5695 | Unresolved.Kind = UnresolvedModuleRef::Export; |
| 5696 | Unresolved.IsWildcard = Record[Idx + 1]; |
| 5697 | UnresolvedModuleRefs.push_back(Unresolved); |
| 5698 | } |
| 5699 | |
| 5700 | |
| 5701 | |
| 5702 | CurrentModule->UnresolvedExports.clear(); |
| 5703 | break; |
| 5704 | |
| 5705 | case SUBMODULE_REQUIRES: |
| 5706 | CurrentModule->addRequirement(Blob, Record[0], PP.getLangOpts(), |
| 5707 | PP.getTargetInfo()); |
| 5708 | break; |
| 5709 | |
| 5710 | case SUBMODULE_LINK_LIBRARY: |
| 5711 | ModMap.resolveLinkAsDependencies(CurrentModule); |
| 5712 | CurrentModule->LinkLibraries.push_back( |
| 5713 | Module::LinkLibrary(std::string(Blob), Record[0])); |
| 5714 | break; |
| 5715 | |
| 5716 | case SUBMODULE_CONFIG_MACRO: |
| 5717 | CurrentModule->ConfigMacros.push_back(Blob.str()); |
| 5718 | break; |
| 5719 | |
| 5720 | case SUBMODULE_CONFLICT: { |
| 5721 | UnresolvedModuleRef Unresolved; |
| 5722 | Unresolved.File = &F; |
| 5723 | Unresolved.Mod = CurrentModule; |
| 5724 | Unresolved.ID = Record[0]; |
| 5725 | Unresolved.Kind = UnresolvedModuleRef::Conflict; |
| 5726 | Unresolved.IsWildcard = false; |
| 5727 | Unresolved.String = Blob; |
| 5728 | UnresolvedModuleRefs.push_back(Unresolved); |
| 5729 | break; |
| 5730 | } |
| 5731 | |
| 5732 | case SUBMODULE_INITIALIZERS: { |
| 5733 | if (!ContextObj) |
| 5734 | break; |
| 5735 | SmallVector<uint32_t, 16> Inits; |
| 5736 | for (auto &ID : Record) |
| 5737 | Inits.push_back(getGlobalDeclID(F, ID)); |
| 5738 | ContextObj->addLazyModuleInitializers(CurrentModule, Inits); |
| 5739 | break; |
| 5740 | } |
| 5741 | |
| 5742 | case SUBMODULE_EXPORT_AS: |
| 5743 | CurrentModule->ExportAsModule = Blob.str(); |
| 5744 | ModMap.addLinkAsDependency(CurrentModule); |
| 5745 | break; |
| 5746 | } |
| 5747 | } |
| 5748 | } |
| 5749 | |
| 5750 | |
| 5751 | |
| 5752 | |
| 5753 | |
| 5754 | |
| 5755 | |
| 5756 | |
| 5757 | bool ASTReader::ParseLanguageOptions(const RecordData &Record, |
| 5758 | bool Complain, |
| 5759 | ASTReaderListener &Listener, |
| 5760 | bool AllowCompatibleDifferences) { |
| 5761 | LangOptions LangOpts; |
| 5762 | unsigned Idx = 0; |
| 5763 | #define LANGOPT(Name, Bits, Default, Description) \ |
| 5764 | LangOpts.Name = Record[Idx++]; |
| 5765 | #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ |
| 5766 | LangOpts.set##Name(static_cast<LangOptions::Type>(Record[Idx++])); |
| 5767 | #include "clang/Basic/LangOptions.def" |
| 5768 | #define SANITIZER(NAME, ID) \ |
| 5769 | LangOpts.Sanitize.set(SanitizerKind::ID, Record[Idx++]); |
| 5770 | #include "clang/Basic/Sanitizers.def" |
| 5771 | |
| 5772 | for (unsigned N = Record[Idx++]; N; --N) |
| 5773 | LangOpts.ModuleFeatures.push_back(ReadString(Record, Idx)); |
| 5774 | |
| 5775 | ObjCRuntime::Kind runtimeKind = (ObjCRuntime::Kind) Record[Idx++]; |
| 5776 | VersionTuple runtimeVersion = ReadVersionTuple(Record, Idx); |
| 5777 | LangOpts.ObjCRuntime = ObjCRuntime(runtimeKind, runtimeVersion); |
| 5778 | |
| 5779 | LangOpts.CurrentModule = ReadString(Record, Idx); |
| 5780 | |
| 5781 | |
| 5782 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5783 | LangOpts.CommentOpts.BlockCommandNames.push_back( |
| 5784 | ReadString(Record, Idx)); |
| 5785 | } |
| 5786 | LangOpts.CommentOpts.ParseAllComments = Record[Idx++]; |
| 5787 | |
| 5788 | |
| 5789 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5790 | LangOpts.OMPTargetTriples.push_back(llvm::Triple(ReadString(Record, Idx))); |
| 5791 | } |
| 5792 | |
| 5793 | LangOpts.OMPHostIRFile = ReadString(Record, Idx); |
| 5794 | |
| 5795 | return Listener.ReadLanguageOptions(LangOpts, Complain, |
| 5796 | AllowCompatibleDifferences); |
| 5797 | } |
| 5798 | |
| 5799 | bool ASTReader::ParseTargetOptions(const RecordData &Record, bool Complain, |
| 5800 | ASTReaderListener &Listener, |
| 5801 | bool AllowCompatibleDifferences) { |
| 5802 | unsigned Idx = 0; |
| 5803 | TargetOptions TargetOpts; |
| 5804 | TargetOpts.Triple = ReadString(Record, Idx); |
| 5805 | TargetOpts.CPU = ReadString(Record, Idx); |
| 5806 | TargetOpts.TuneCPU = ReadString(Record, Idx); |
| 5807 | TargetOpts.ABI = ReadString(Record, Idx); |
| 5808 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5809 | TargetOpts.FeaturesAsWritten.push_back(ReadString(Record, Idx)); |
| 5810 | } |
| 5811 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5812 | TargetOpts.Features.push_back(ReadString(Record, Idx)); |
| 5813 | } |
| 5814 | |
| 5815 | return Listener.ReadTargetOptions(TargetOpts, Complain, |
| 5816 | AllowCompatibleDifferences); |
| 5817 | } |
| 5818 | |
| 5819 | bool ASTReader::ParseDiagnosticOptions(const RecordData &Record, bool Complain, |
| 5820 | ASTReaderListener &Listener) { |
| 5821 | IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts(new DiagnosticOptions); |
| 5822 | unsigned Idx = 0; |
| 5823 | #define DIAGOPT(Name, Bits, Default) DiagOpts->Name = Record[Idx++]; |
| 5824 | #define ENUM_DIAGOPT(Name, Type, Bits, Default) \ |
| 5825 | DiagOpts->set##Name(static_cast<Type>(Record[Idx++])); |
| 5826 | #include "clang/Basic/DiagnosticOptions.def" |
| 5827 | |
| 5828 | for (unsigned N = Record[Idx++]; N; --N) |
| 5829 | DiagOpts->Warnings.push_back(ReadString(Record, Idx)); |
| 5830 | for (unsigned N = Record[Idx++]; N; --N) |
| 5831 | DiagOpts->Remarks.push_back(ReadString(Record, Idx)); |
| 5832 | |
| 5833 | return Listener.ReadDiagnosticOptions(DiagOpts, Complain); |
| 5834 | } |
| 5835 | |
| 5836 | bool ASTReader::ParseFileSystemOptions(const RecordData &Record, bool Complain, |
| 5837 | ASTReaderListener &Listener) { |
| 5838 | FileSystemOptions FSOpts; |
| 5839 | unsigned Idx = 0; |
| 5840 | FSOpts.WorkingDir = ReadString(Record, Idx); |
| 5841 | return Listener.ReadFileSystemOptions(FSOpts, Complain); |
| 5842 | } |
| 5843 | |
| 5844 | bool ASTReader::ParseHeaderSearchOptions(const RecordData &Record, |
| 5845 | bool Complain, |
| 5846 | ASTReaderListener &Listener) { |
| 5847 | HeaderSearchOptions HSOpts; |
| 5848 | unsigned Idx = 0; |
| 5849 | HSOpts.Sysroot = ReadString(Record, Idx); |
| 5850 | |
| 5851 | |
| 5852 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5853 | std::string Path = ReadString(Record, Idx); |
| 5854 | frontend::IncludeDirGroup Group |
| 5855 | = static_cast<frontend::IncludeDirGroup>(Record[Idx++]); |
| 5856 | bool IsFramework = Record[Idx++]; |
| 5857 | bool IgnoreSysRoot = Record[Idx++]; |
| 5858 | HSOpts.UserEntries.emplace_back(std::move(Path), Group, IsFramework, |
| 5859 | IgnoreSysRoot); |
| 5860 | } |
| 5861 | |
| 5862 | |
| 5863 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5864 | std::string Prefix = ReadString(Record, Idx); |
| 5865 | bool IsSystemHeader = Record[Idx++]; |
| 5866 | HSOpts.SystemHeaderPrefixes.emplace_back(std::move(Prefix), IsSystemHeader); |
| 5867 | } |
| 5868 | |
| 5869 | HSOpts.ResourceDir = ReadString(Record, Idx); |
| 5870 | HSOpts.ModuleCachePath = ReadString(Record, Idx); |
| 5871 | HSOpts.ModuleUserBuildPath = ReadString(Record, Idx); |
| 5872 | HSOpts.DisableModuleHash = Record[Idx++]; |
| 5873 | HSOpts.ImplicitModuleMaps = Record[Idx++]; |
| 5874 | HSOpts.ModuleMapFileHomeIsCwd = Record[Idx++]; |
| 5875 | HSOpts.EnablePrebuiltImplicitModules = Record[Idx++]; |
| 5876 | HSOpts.UseBuiltinIncludes = Record[Idx++]; |
| 5877 | HSOpts.UseStandardSystemIncludes = Record[Idx++]; |
| 5878 | HSOpts.UseStandardCXXIncludes = Record[Idx++]; |
| 5879 | HSOpts.UseLibcxx = Record[Idx++]; |
| 5880 | std::string SpecificModuleCachePath = ReadString(Record, Idx); |
| 5881 | |
| 5882 | return Listener.ReadHeaderSearchOptions(HSOpts, SpecificModuleCachePath, |
| 5883 | Complain); |
| 5884 | } |
| 5885 | |
| 5886 | bool ASTReader::ParsePreprocessorOptions(const RecordData &Record, |
| 5887 | bool Complain, |
| 5888 | ASTReaderListener &Listener, |
| 5889 | std::string &SuggestedPredefines) { |
| 5890 | PreprocessorOptions PPOpts; |
| 5891 | unsigned Idx = 0; |
| 5892 | |
| 5893 | |
| 5894 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5895 | std::string Macro = ReadString(Record, Idx); |
| 5896 | bool IsUndef = Record[Idx++]; |
| 5897 | PPOpts.Macros.push_back(std::make_pair(Macro, IsUndef)); |
| 5898 | } |
| 5899 | |
| 5900 | |
| 5901 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5902 | PPOpts.Includes.push_back(ReadString(Record, Idx)); |
| 5903 | } |
| 5904 | |
| 5905 | |
| 5906 | for (unsigned N = Record[Idx++]; N; --N) { |
| 5907 | PPOpts.MacroIncludes.push_back(ReadString(Record, Idx)); |
| 5908 | } |
| 5909 | |
| 5910 | PPOpts.UsePredefines = Record[Idx++]; |
| 5911 | PPOpts.DetailedRecord = Record[Idx++]; |
| 5912 | PPOpts.ImplicitPCHInclude = ReadString(Record, Idx); |
| 5913 | PPOpts.ObjCXXARCStandardLibrary = |
| 5914 | static_cast<ObjCXXARCStandardLibraryKind>(Record[Idx++]); |
| 5915 | SuggestedPredefines.clear(); |
| 5916 | return Listener.ReadPreprocessorOptions(PPOpts, Complain, |
| 5917 | SuggestedPredefines); |
| 5918 | } |
| 5919 | |
| 5920 | std::pair<ModuleFile *, unsigned> |
| 5921 | ASTReader::getModulePreprocessedEntity(unsigned GlobalIndex) { |
| 5922 | GlobalPreprocessedEntityMapType::iterator |
| 5923 | I = GlobalPreprocessedEntityMap.find(GlobalIndex); |
| 5924 | assert(I != GlobalPreprocessedEntityMap.end() && |
| 5925 | "Corrupted global preprocessed entity map"); |
| 5926 | ModuleFile *M = I->second; |
| 5927 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedEntityID; |
| 5928 | return std::make_pair(M, LocalIndex); |
| 5929 | } |
| 5930 | |
| 5931 | llvm::iterator_range<PreprocessingRecord::iterator> |
| 5932 | ASTReader::getModulePreprocessedEntities(ModuleFile &Mod) const { |
| 5933 | if (PreprocessingRecord *PPRec = PP.getPreprocessingRecord()) |
| 5934 | return PPRec->getIteratorsForLoadedRange(Mod.BasePreprocessedEntityID, |
| 5935 | Mod.NumPreprocessedEntities); |
| 5936 | |
| 5937 | return llvm::make_range(PreprocessingRecord::iterator(), |
| 5938 | PreprocessingRecord::iterator()); |
| 5939 | } |
| 5940 | |
| 5941 | bool ASTReader::canRecoverFromOutOfDate(StringRef ModuleFileName, |
| 5942 | unsigned int ClientLoadCapabilities) { |
| 5943 | return ClientLoadCapabilities & ARR_OutOfDate && |
| 5944 | !getModuleManager().getModuleCache().isPCMFinal(ModuleFileName); |
| 5945 | } |
| 5946 | |
| 5947 | llvm::iterator_range<ASTReader::ModuleDeclIterator> |
| 5948 | ASTReader::getModuleFileLevelDecls(ModuleFile &Mod) { |
| 5949 | return llvm::make_range( |
| 5950 | ModuleDeclIterator(this, &Mod, Mod.FileSortedDecls), |
| 5951 | ModuleDeclIterator(this, &Mod, |
| 5952 | Mod.FileSortedDecls + Mod.NumFileSortedDecls)); |
| 5953 | } |
| 5954 | |
| 5955 | SourceRange ASTReader::ReadSkippedRange(unsigned GlobalIndex) { |
| 5956 | auto I = GlobalSkippedRangeMap.find(GlobalIndex); |
| 5957 | assert(I != GlobalSkippedRangeMap.end() && |
| 5958 | "Corrupted global skipped range map"); |
| 5959 | ModuleFile *M = I->second; |
| 5960 | unsigned LocalIndex = GlobalIndex - M->BasePreprocessedSkippedRangeID; |
| 5961 | assert(LocalIndex < M->NumPreprocessedSkippedRanges); |
| 5962 | PPSkippedRange RawRange = M->PreprocessedSkippedRangeOffsets[LocalIndex]; |
| 5963 | SourceRange Range(TranslateSourceLocation(*M, RawRange.getBegin()), |
| 5964 | TranslateSourceLocation(*M, RawRange.getEnd())); |
| 5965 | assert(Range.isValid()); |
| 5966 | return Range; |
| 5967 | } |
| 5968 | |
| 5969 | PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { |
| 5970 | PreprocessedEntityID PPID = Index+1; |
| 5971 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 5972 | ModuleFile &M = *PPInfo.first; |
| 5973 | unsigned LocalIndex = PPInfo.second; |
| 5974 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 5975 | |
| 5976 | if (!PP.getPreprocessingRecord()) { |
| 5977 | Error("no preprocessing record"); |
| 5978 | return nullptr; |
| 5979 | } |
| 5980 | |
| 5981 | SavedStreamPosition SavedPosition(M.PreprocessorDetailCursor); |
| 5982 | if (llvm::Error Err = M.PreprocessorDetailCursor.JumpToBit( |
| 5983 | M.MacroOffsetsBase + PPOffs.BitOffset)) { |
| 5984 | Error(std::move(Err)); |
| 5985 | return nullptr; |
| 5986 | } |
| 5987 | |
| 5988 | Expected<llvm::BitstreamEntry> MaybeEntry = |
| 5989 | M.PreprocessorDetailCursor.advance(BitstreamCursor::AF_DontPopBlockAtEnd); |
| 5990 | if (!MaybeEntry) { |
| 5991 | Error(MaybeEntry.takeError()); |
| 5992 | return nullptr; |
| 5993 | } |
| 5994 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 5995 | |
| 5996 | if (Entry.Kind != llvm::BitstreamEntry::Record) |
| 5997 | return nullptr; |
| 5998 | |
| 5999 | |
| 6000 | SourceRange Range(TranslateSourceLocation(M, PPOffs.getBegin()), |
| 6001 | TranslateSourceLocation(M, PPOffs.getEnd())); |
| 6002 | PreprocessingRecord &PPRec = *PP.getPreprocessingRecord(); |
| 6003 | StringRef Blob; |
| 6004 | RecordData Record; |
| 6005 | Expected<unsigned> MaybeRecType = |
| 6006 | M.PreprocessorDetailCursor.readRecord(Entry.ID, Record, &Blob); |
| 6007 | if (!MaybeRecType) { |
| 6008 | Error(MaybeRecType.takeError()); |
| 6009 | return nullptr; |
| 6010 | } |
| 6011 | switch ((PreprocessorDetailRecordTypes)MaybeRecType.get()) { |
| 6012 | case PPD_MACRO_EXPANSION: { |
| 6013 | bool isBuiltin = Record[0]; |
| 6014 | IdentifierInfo *Name = nullptr; |
| 6015 | MacroDefinitionRecord *Def = nullptr; |
| 6016 | if (isBuiltin) |
| 6017 | Name = getLocalIdentifier(M, Record[1]); |
| 6018 | else { |
| 6019 | PreprocessedEntityID GlobalID = |
| 6020 | getGlobalPreprocessedEntityID(M, Record[1]); |
| 6021 | Def = cast<MacroDefinitionRecord>( |
| 6022 | PPRec.getLoadedPreprocessedEntity(GlobalID - 1)); |
| 6023 | } |
| 6024 | |
| 6025 | MacroExpansion *ME; |
| 6026 | if (isBuiltin) |
| 6027 | ME = new (PPRec) MacroExpansion(Name, Range); |
| 6028 | else |
| 6029 | ME = new (PPRec) MacroExpansion(Def, Range); |
| 6030 | |
| 6031 | return ME; |
| 6032 | } |
| 6033 | |
| 6034 | case PPD_MACRO_DEFINITION: { |
| 6035 | |
| 6036 | |
| 6037 | IdentifierInfo *II = getLocalIdentifier(M, Record[0]); |
| 6038 | MacroDefinitionRecord *MD = new (PPRec) MacroDefinitionRecord(II, Range); |
| 6039 | |
| 6040 | if (DeserializationListener) |
| 6041 | DeserializationListener->MacroDefinitionRead(PPID, MD); |
| 6042 | |
| 6043 | return MD; |
| 6044 | } |
| 6045 | |
| 6046 | case PPD_INCLUSION_DIRECTIVE: { |
| 6047 | const char *FullFileNameStart = Blob.data() + Record[0]; |
| 6048 | StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]); |
| 6049 | const FileEntry *File = nullptr; |
| 6050 | if (!FullFileName.empty()) |
| 6051 | if (auto FE = PP.getFileManager().getFile(FullFileName)) |
| 6052 | File = *FE; |
| 6053 | |
| 6054 | |
| 6055 | InclusionDirective::InclusionKind Kind |
| 6056 | = static_cast<InclusionDirective::InclusionKind>(Record[2]); |
| 6057 | InclusionDirective *ID |
| 6058 | = new (PPRec) InclusionDirective(PPRec, Kind, |
| 6059 | StringRef(Blob.data(), Record[0]), |
| 6060 | Record[1], Record[3], |
| 6061 | File, |
| 6062 | Range); |
| 6063 | return ID; |
| 6064 | } |
| 6065 | } |
| 6066 | |
| 6067 | llvm_unreachable("Invalid PreprocessorDetailRecordTypes"); |
| 6068 | } |
| 6069 | |
| 6070 | |
| 6071 | |
| 6072 | |
| 6073 | |
| 6074 | |
| 6075 | |
| 6076 | PreprocessedEntityID ASTReader::findNextPreprocessedEntity( |
| 6077 | GlobalSLocOffsetMapType::const_iterator SLocMapI) const { |
| 6078 | ++SLocMapI; |
| 6079 | for (GlobalSLocOffsetMapType::const_iterator |
| 6080 | EndI = GlobalSLocOffsetMap.end(); SLocMapI != EndI; ++SLocMapI) { |
| 6081 | ModuleFile &M = *SLocMapI->second; |
| 6082 | if (M.NumPreprocessedEntities) |
| 6083 | return M.BasePreprocessedEntityID; |
| 6084 | } |
| 6085 | |
| 6086 | return getTotalNumPreprocessedEntities(); |
| 6087 | } |
| 6088 | |
| 6089 | namespace { |
| 6090 | |
| 6091 | struct PPEntityComp { |
| 6092 | const ASTReader &Reader; |
| 6093 | ModuleFile &M; |
| 6094 | |
| 6095 | PPEntityComp(const ASTReader &Reader, ModuleFile &M) : Reader(Reader), M(M) {} |
| 6096 | |
| 6097 | bool operator()(const PPEntityOffset &L, const PPEntityOffset &R) const { |
| 6098 | SourceLocation LHS = getLoc(L); |
| 6099 | SourceLocation RHS = getLoc(R); |
| 6100 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 6101 | } |
| 6102 | |
| 6103 | bool operator()(const PPEntityOffset &L, SourceLocation RHS) const { |
| 6104 | SourceLocation LHS = getLoc(L); |
| 6105 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 6106 | } |
| 6107 | |
| 6108 | bool operator()(SourceLocation LHS, const PPEntityOffset &R) const { |
| 6109 | SourceLocation RHS = getLoc(R); |
| 6110 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 6111 | } |
| 6112 | |
| 6113 | SourceLocation getLoc(const PPEntityOffset &PPE) const { |
| 6114 | return Reader.TranslateSourceLocation(M, PPE.getBegin()); |
| 6115 | } |
| 6116 | }; |
| 6117 | |
| 6118 | } |
| 6119 | |
| 6120 | PreprocessedEntityID ASTReader::findPreprocessedEntity(SourceLocation Loc, |
| 6121 | bool EndsAfter) const { |
| 6122 | if (SourceMgr.isLocalSourceLocation(Loc)) |
| 6123 | return getTotalNumPreprocessedEntities(); |
| 6124 | |
| 6125 | GlobalSLocOffsetMapType::const_iterator SLocMapI = GlobalSLocOffsetMap.find( |
| 6126 | SourceManager::MaxLoadedOffset - Loc.getOffset() - 1); |
| 6127 | assert(SLocMapI != GlobalSLocOffsetMap.end() && |
| 6128 | "Corrupted global sloc offset map"); |
| 6129 | |
| 6130 | if (SLocMapI->second->NumPreprocessedEntities == 0) |
| 6131 | return findNextPreprocessedEntity(SLocMapI); |
| 6132 | |
| 6133 | ModuleFile &M = *SLocMapI->second; |
| 6134 | |
| 6135 | using pp_iterator = const PPEntityOffset *; |
| 6136 | |
| 6137 | pp_iterator pp_begin = M.PreprocessedEntityOffsets; |
| 6138 | pp_iterator pp_end = pp_begin + M.NumPreprocessedEntities; |
| 6139 | |
| 6140 | size_t Count = M.NumPreprocessedEntities; |
| 6141 | size_t Half; |
| 6142 | pp_iterator First = pp_begin; |
| 6143 | pp_iterator PPI; |
| 6144 | |
| 6145 | if (EndsAfter) { |
| 6146 | PPI = std::upper_bound(pp_begin, pp_end, Loc, |
| 6147 | PPEntityComp(*this, M)); |
| 6148 | } else { |
| 6149 | |
| 6150 | |
| 6151 | |
| 6152 | |
| 6153 | while (Count > 0) { |
| 6154 | Half = Count / 2; |
| 6155 | PPI = First; |
| 6156 | std::advance(PPI, Half); |
| 6157 | if (SourceMgr.isBeforeInTranslationUnit( |
| 6158 | TranslateSourceLocation(M, PPI->getEnd()), Loc)) { |
| 6159 | First = PPI; |
| 6160 | ++First; |
| 6161 | Count = Count - Half - 1; |
| 6162 | } else |
| 6163 | Count = Half; |
| 6164 | } |
| 6165 | } |
| 6166 | |
| 6167 | if (PPI == pp_end) |
| 6168 | return findNextPreprocessedEntity(SLocMapI); |
| 6169 | |
| 6170 | return M.BasePreprocessedEntityID + (PPI - pp_begin); |
| 6171 | } |
| 6172 | |
| 6173 | |
| 6174 | |
| 6175 | std::pair<unsigned, unsigned> |
| 6176 | ASTReader::findPreprocessedEntitiesInRange(SourceRange Range) { |
| 6177 | if (Range.isInvalid()) |
| 6178 | return std::make_pair(0,0); |
| 6179 | assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin())); |
| 6180 | |
| 6181 | PreprocessedEntityID BeginID = |
| 6182 | findPreprocessedEntity(Range.getBegin(), false); |
| 6183 | PreprocessedEntityID EndID = findPreprocessedEntity(Range.getEnd(), true); |
| 6184 | return std::make_pair(BeginID, EndID); |
| 6185 | } |
| 6186 | |
| 6187 | |
| 6188 | |
| 6189 | Optional<bool> ASTReader::isPreprocessedEntityInFileID(unsigned Index, |
| 6190 | FileID FID) { |
| 6191 | if (FID.isInvalid()) |
| 6192 | return false; |
| 6193 | |
| 6194 | std::pair<ModuleFile *, unsigned> PPInfo = getModulePreprocessedEntity(Index); |
| 6195 | ModuleFile &M = *PPInfo.first; |
| 6196 | unsigned LocalIndex = PPInfo.second; |
| 6197 | const PPEntityOffset &PPOffs = M.PreprocessedEntityOffsets[LocalIndex]; |
| 6198 | |
| 6199 | SourceLocation Loc = TranslateSourceLocation(M, PPOffs.getBegin()); |
| 6200 | if (Loc.isInvalid()) |
| 6201 | return false; |
| 6202 | |
| 6203 | if (SourceMgr.isInFileID(SourceMgr.getFileLoc(Loc), FID)) |
| 6204 | return true; |
| 6205 | else |
| 6206 | return false; |
| 6207 | } |
| 6208 | |
| 6209 | namespace { |
| 6210 | |
| 6211 | |
| 6212 | class HeaderFileInfoVisitor { |
| 6213 | const FileEntry *FE; |
| 6214 | Optional<HeaderFileInfo> HFI; |
| 6215 | |
| 6216 | public: |
| 6217 | explicit HeaderFileInfoVisitor(const FileEntry *FE) : FE(FE) {} |
| 6218 | |
| 6219 | bool operator()(ModuleFile &M) { |
| 6220 | HeaderFileInfoLookupTable *Table |
| 6221 | = static_cast<HeaderFileInfoLookupTable *>(M.HeaderFileInfoTable); |
| 6222 | if (!Table) |
| 6223 | return false; |
| 6224 | |
| 6225 | |
| 6226 | HeaderFileInfoLookupTable::iterator Pos = Table->find(FE); |
| 6227 | if (Pos == Table->end()) |
| 6228 | return false; |
| 6229 | |
| 6230 | HFI = *Pos; |
| 6231 | return true; |
| 6232 | } |
| 6233 | |
| 6234 | Optional<HeaderFileInfo> getHeaderFileInfo() const { return HFI; } |
| 6235 | }; |
| 6236 | |
| 6237 | } |
| 6238 | |
| 6239 | HeaderFileInfo ASTReader::GetHeaderFileInfo(const FileEntry *FE) { |
| 6240 | HeaderFileInfoVisitor Visitor(FE); |
| 6241 | ModuleMgr.visit(Visitor); |
| 6242 | if (Optional<HeaderFileInfo> HFI = Visitor.getHeaderFileInfo()) |
| 6243 | return *HFI; |
| 6244 | |
| 6245 | return HeaderFileInfo(); |
| 6246 | } |
| 6247 | |
| 6248 | void ASTReader::ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag) { |
| 6249 | using DiagState = DiagnosticsEngine::DiagState; |
| 6250 | SmallVector<DiagState *, 32> DiagStates; |
| 6251 | |
| 6252 | for (ModuleFile &F : ModuleMgr) { |
| 6253 | unsigned Idx = 0; |
| 6254 | auto &Record = F.PragmaDiagMappings; |
| 6255 | if (Record.empty()) |
| 6256 | continue; |
| 6257 | |
| 6258 | DiagStates.clear(); |
| 6259 | |
| 6260 | auto ReadDiagState = |
| 6261 | [&](const DiagState &BasedOn, SourceLocation Loc, |
| 6262 | bool IncludeNonPragmaStates) -> DiagnosticsEngine::DiagState * { |
| 6263 | unsigned BackrefID = Record[Idx++]; |
| 6264 | if (BackrefID != 0) |
| 6265 | return DiagStates[BackrefID - 1]; |
| 6266 | |
| 6267 | |
| 6268 | Diag.DiagStates.push_back(BasedOn); |
| 6269 | DiagState *NewState = &Diag.DiagStates.back(); |
| 6270 | DiagStates.push_back(NewState); |
| 6271 | unsigned Size = Record[Idx++]; |
| 6272 | assert(Idx + Size * 2 <= Record.size() && |
| 6273 | "Invalid data, not enough diag/map pairs"); |
| 6274 | while (Size--) { |
| 6275 | unsigned DiagID = Record[Idx++]; |
| 6276 | DiagnosticMapping NewMapping = |
| 6277 | DiagnosticMapping::deserialize(Record[Idx++]); |
| 6278 | if (!NewMapping.isPragma() && !IncludeNonPragmaStates) |
| 6279 | continue; |
| 6280 | |
| 6281 | DiagnosticMapping &Mapping = NewState->getOrAddMapping(DiagID); |
| 6282 | |
| 6283 | |
| 6284 | |
| 6285 | |
| 6286 | if (NewMapping.wasUpgradedFromWarning() && !Mapping.isErrorOrFatal()) { |
| 6287 | NewMapping.setSeverity(diag::Severity::Warning); |
| 6288 | NewMapping.setUpgradedFromWarning(false); |
| 6289 | } |
| 6290 | |
| 6291 | Mapping = NewMapping; |
| 6292 | } |
| 6293 | return NewState; |
| 6294 | }; |
| 6295 | |
| 6296 | |
| 6297 | DiagState *FirstState; |
| 6298 | if (F.Kind == MK_ImplicitModule) { |
| 6299 | |
| 6300 | |
| 6301 | |
| 6302 | FirstState = Diag.DiagStatesByLoc.FirstDiagState; |
| 6303 | DiagStates.push_back(FirstState); |
| 6304 | |
| 6305 | |
| 6306 | assert(Record[1] == 0 && |
| 6307 | "Invalid data, unexpected backref in initial state"); |
| 6308 | Idx = 3 + Record[2] * 2; |
| 6309 | assert(Idx < Record.size() && |
| 6310 | "Invalid data, not enough state change pairs in initial state"); |
| 6311 | } else if (F.isModule()) { |
| 6312 | |
| 6313 | |
| 6314 | |
| 6315 | unsigned Flags = Record[Idx++]; |
| 6316 | DiagState Initial; |
| 6317 | Initial.SuppressSystemWarnings = Flags & 1; Flags >>= 1; |
| 6318 | Initial.ErrorsAsFatal = Flags & 1; Flags >>= 1; |
| 6319 | Initial.WarningsAsErrors = Flags & 1; Flags >>= 1; |
| 6320 | Initial.EnableAllWarnings = Flags & 1; Flags >>= 1; |
| 6321 | Initial.IgnoreAllWarnings = Flags & 1; Flags >>= 1; |
| 6322 | Initial.ExtBehavior = (diag::Severity)Flags; |
| 6323 | FirstState = ReadDiagState(Initial, SourceLocation(), true); |
| 6324 | |
| 6325 | assert(F.OriginalSourceFileID.isValid()); |
| 6326 | |
| 6327 | |
| 6328 | |
| 6329 | |
| 6330 | Diag.DiagStatesByLoc.Files[F.OriginalSourceFileID] |
| 6331 | .StateTransitions.push_back({FirstState, 0}); |
| 6332 | } else { |
| 6333 | |
| 6334 | |
| 6335 | Idx++; |
| 6336 | FirstState = ReadDiagState(*Diag.DiagStatesByLoc.CurDiagState, |
| 6337 | SourceLocation(), false); |
| 6338 | } |
| 6339 | |
| 6340 | |
| 6341 | unsigned NumLocations = Record[Idx++]; |
| 6342 | while (NumLocations--) { |
| 6343 | assert(Idx < Record.size() && |
| 6344 | "Invalid data, missing pragma diagnostic states"); |
| 6345 | SourceLocation Loc = ReadSourceLocation(F, Record[Idx++]); |
| 6346 | auto IDAndOffset = SourceMgr.getDecomposedLoc(Loc); |
| 6347 | assert(IDAndOffset.first.isValid() && "invalid FileID for transition"); |
| 6348 | assert(IDAndOffset.second == 0 && "not a start location for a FileID"); |
| 6349 | unsigned Transitions = Record[Idx++]; |
| 6350 | |
| 6351 | |
| 6352 | |
| 6353 | |
| 6354 | |
| 6355 | auto &F = Diag.DiagStatesByLoc.Files[IDAndOffset.first]; |
| 6356 | F.StateTransitions.reserve(F.StateTransitions.size() + Transitions); |
| 6357 | for (unsigned I = 0; I != Transitions; ++I) { |
| 6358 | unsigned Offset = Record[Idx++]; |
| 6359 | auto *State = |
| 6360 | ReadDiagState(*FirstState, Loc.getLocWithOffset(Offset), false); |
| 6361 | F.StateTransitions.push_back({State, Offset}); |
| 6362 | } |
| 6363 | } |
| 6364 | |
| 6365 | |
| 6366 | assert(Idx < Record.size() && |
| 6367 | "Invalid data, missing final pragma diagnostic state"); |
| 6368 | SourceLocation CurStateLoc = |
| 6369 | ReadSourceLocation(F, F.PragmaDiagMappings[Idx++]); |
| 6370 | auto *CurState = ReadDiagState(*FirstState, CurStateLoc, false); |
| 6371 | |
| 6372 | if (!F.isModule()) { |
| 6373 | Diag.DiagStatesByLoc.CurDiagState = CurState; |
| 6374 | Diag.DiagStatesByLoc.CurDiagStateLoc = CurStateLoc; |
| 6375 | |
| 6376 | |
| 6377 | |
| 6378 | FileID NullFile; |
| 6379 | auto &T = Diag.DiagStatesByLoc.Files[NullFile].StateTransitions; |
| 6380 | if (T.empty()) |
| 6381 | T.push_back({CurState, 0}); |
| 6382 | else |
| 6383 | T[0].State = CurState; |
| 6384 | } |
| 6385 | |
| 6386 | |
| 6387 | Record.clear(); |
| 6388 | } |
| 6389 | } |
| 6390 | |
| 6391 | |
| 6392 | ASTReader::RecordLocation ASTReader::TypeCursorForIndex(unsigned Index) { |
| 6393 | GlobalTypeMapType::iterator I = GlobalTypeMap.find(Index); |
| 6394 | assert(I != GlobalTypeMap.end() && "Corrupted global type map"); |
| 6395 | ModuleFile *M = I->second; |
| 6396 | return RecordLocation( |
| 6397 | M, M->TypeOffsets[Index - M->BaseTypeIndex].getBitOffset() + |
| 6398 | M->DeclsBlockStartOffset); |
| 6399 | } |
| 6400 | |
| 6401 | static llvm::Optional<Type::TypeClass> getTypeClassForCode(TypeCode code) { |
| 6402 | switch (code) { |
| 6403 | #define TYPE_BIT_CODE(CLASS_ID, CODE_ID, CODE_VALUE) \ |
| 6404 | case TYPE_##CODE_ID: return Type::CLASS_ID; |
| 6405 | #include "clang/Serialization/TypeBitCodes.def" |
| 6406 | default: return llvm::None; |
| 6407 | } |
| 6408 | } |
| 6409 | |
| 6410 | |
| 6411 | |
| 6412 | |
| 6413 | |
| 6414 | |
| 6415 | |
| 6416 | QualType ASTReader::readTypeRecord(unsigned Index) { |
| 6417 | assert(ContextObj && "reading type with no AST context"); |
| 6418 | ASTContext &Context = *ContextObj; |
| 6419 | RecordLocation Loc = TypeCursorForIndex(Index); |
| 6420 | BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
| 6421 | |
| 6422 | |
| 6423 | |
| 6424 | SavedStreamPosition SavedPosition(DeclsCursor); |
| 6425 | |
| 6426 | ReadingKindTracker ReadingKind(Read_Type, *this); |
| 6427 | |
| 6428 | |
| 6429 | Deserializing AType(this); |
| 6430 | |
| 6431 | if (llvm::Error Err = DeclsCursor.JumpToBit(Loc.Offset)) { |
| 6432 | Error(std::move(Err)); |
| 6433 | return QualType(); |
| 6434 | } |
| 6435 | Expected<unsigned> RawCode = DeclsCursor.ReadCode(); |
| 6436 | if (!RawCode) { |
| 6437 | Error(RawCode.takeError()); |
| 6438 | return QualType(); |
| 6439 | } |
| 6440 | |
| 6441 | ASTRecordReader Record(*this, *Loc.F); |
| 6442 | Expected<unsigned> Code = Record.readRecord(DeclsCursor, RawCode.get()); |
| 6443 | if (!Code) { |
| 6444 | Error(Code.takeError()); |
| 6445 | return QualType(); |
| 6446 | } |
| 6447 | if (Code.get() == TYPE_EXT_QUAL) { |
| 6448 | QualType baseType = Record.readQualType(); |
| 6449 | Qualifiers quals = Record.readQualifiers(); |
| 6450 | return Context.getQualifiedType(baseType, quals); |
| 6451 | } |
| 6452 | |
| 6453 | auto maybeClass = getTypeClassForCode((TypeCode) Code.get()); |
| 6454 | if (!maybeClass) { |
| 6455 | Error("Unexpected code for type"); |
| 6456 | return QualType(); |
| 6457 | } |
| 6458 | |
| 6459 | serialization::AbstractTypeReader<ASTRecordReader> TypeReader(Record); |
| 6460 | return TypeReader.read(*maybeClass); |
| 6461 | } |
| 6462 | |
| 6463 | namespace clang { |
| 6464 | |
| 6465 | class TypeLocReader : public TypeLocVisitor<TypeLocReader> { |
| 6466 | ASTRecordReader &Reader; |
| 6467 | |
| 6468 | SourceLocation readSourceLocation() { |
| 6469 | return Reader.readSourceLocation(); |
| 6470 | } |
| 6471 | |
| 6472 | TypeSourceInfo *GetTypeSourceInfo() { |
| 6473 | return Reader.readTypeSourceInfo(); |
| 6474 | } |
| 6475 | |
| 6476 | NestedNameSpecifierLoc ReadNestedNameSpecifierLoc() { |
| 6477 | return Reader.readNestedNameSpecifierLoc(); |
| 6478 | } |
| 6479 | |
| 6480 | Attr *ReadAttr() { |
| 6481 | return Reader.readAttr(); |
| 6482 | } |
| 6483 | |
| 6484 | public: |
| 6485 | TypeLocReader(ASTRecordReader &Reader) : Reader(Reader) {} |
| 6486 | |
| 6487 | |
| 6488 | |
| 6489 | |
| 6490 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 6491 | #define TYPELOC(CLASS, PARENT) \ |
| 6492 | void Visit##CLASS##TypeLoc(CLASS##TypeLoc TyLoc); |
| 6493 | #include "clang/AST/TypeLocNodes.def" |
| 6494 | |
| 6495 | void VisitFunctionTypeLoc(FunctionTypeLoc); |
| 6496 | void VisitArrayTypeLoc(ArrayTypeLoc); |
| 6497 | }; |
| 6498 | |
| 6499 | } |
| 6500 | |
| 6501 | void TypeLocReader::VisitQualifiedTypeLoc(QualifiedTypeLoc TL) { |
| 6502 | |
| 6503 | } |
| 6504 | |
| 6505 | void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) { |
| 6506 | TL.setBuiltinLoc(readSourceLocation()); |
| 6507 | if (TL.needsExtraLocalData()) { |
| 6508 | TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Reader.readInt())); |
| 6509 | TL.setWrittenSignSpec(static_cast<TypeSpecifierSign>(Reader.readInt())); |
| 6510 | TL.setWrittenWidthSpec(static_cast<TypeSpecifierWidth>(Reader.readInt())); |
| 6511 | TL.setModeAttr(Reader.readInt()); |
| 6512 | } |
| 6513 | } |
| 6514 | |
| 6515 | void TypeLocReader::VisitComplexTypeLoc(ComplexTypeLoc TL) { |
| 6516 | TL.setNameLoc(readSourceLocation()); |
| 6517 | } |
| 6518 | |
| 6519 | void TypeLocReader::VisitPointerTypeLoc(PointerTypeLoc TL) { |
| 6520 | TL.setStarLoc(readSourceLocation()); |
| 6521 | } |
| 6522 | |
| 6523 | void TypeLocReader::VisitDecayedTypeLoc(DecayedTypeLoc TL) { |
| 6524 | |
| 6525 | } |
| 6526 | |
| 6527 | void TypeLocReader::VisitAdjustedTypeLoc(AdjustedTypeLoc TL) { |
| 6528 | |
| 6529 | } |
| 6530 | |
| 6531 | void TypeLocReader::VisitMacroQualifiedTypeLoc(MacroQualifiedTypeLoc TL) { |
| 6532 | TL.setExpansionLoc(readSourceLocation()); |
| 6533 | } |
| 6534 | |
| 6535 | void TypeLocReader::VisitBlockPointerTypeLoc(BlockPointerTypeLoc TL) { |
| 6536 | TL.setCaretLoc(readSourceLocation()); |
| 6537 | } |
| 6538 | |
| 6539 | void TypeLocReader::VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) { |
| 6540 | TL.setAmpLoc(readSourceLocation()); |
| 6541 | } |
| 6542 | |
| 6543 | void TypeLocReader::VisitRValueReferenceTypeLoc(RValueReferenceTypeLoc TL) { |
| 6544 | TL.setAmpAmpLoc(readSourceLocation()); |
| 6545 | } |
| 6546 | |
| 6547 | void TypeLocReader::VisitMemberPointerTypeLoc(MemberPointerTypeLoc TL) { |
| 6548 | TL.setStarLoc(readSourceLocation()); |
| 6549 | TL.setClassTInfo(GetTypeSourceInfo()); |
| 6550 | } |
| 6551 | |
| 6552 | void TypeLocReader::VisitArrayTypeLoc(ArrayTypeLoc TL) { |
| 6553 | TL.setLBracketLoc(readSourceLocation()); |
| 6554 | TL.setRBracketLoc(readSourceLocation()); |
| 6555 | if (Reader.readBool()) |
| 6556 | TL.setSizeExpr(Reader.readExpr()); |
| 6557 | else |
| 6558 | TL.setSizeExpr(nullptr); |
| 6559 | } |
| 6560 | |
| 6561 | void TypeLocReader::VisitConstantArrayTypeLoc(ConstantArrayTypeLoc TL) { |
| 6562 | VisitArrayTypeLoc(TL); |
| 6563 | } |
| 6564 | |
| 6565 | void TypeLocReader::VisitIncompleteArrayTypeLoc(IncompleteArrayTypeLoc TL) { |
| 6566 | VisitArrayTypeLoc(TL); |
| 6567 | } |
| 6568 | |
| 6569 | void TypeLocReader::VisitVariableArrayTypeLoc(VariableArrayTypeLoc TL) { |
| 6570 | VisitArrayTypeLoc(TL); |
| 6571 | } |
| 6572 | |
| 6573 | void TypeLocReader::VisitDependentSizedArrayTypeLoc( |
| 6574 | DependentSizedArrayTypeLoc TL) { |
| 6575 | VisitArrayTypeLoc(TL); |
| 6576 | } |
| 6577 | |
| 6578 | void TypeLocReader::VisitDependentAddressSpaceTypeLoc( |
| 6579 | DependentAddressSpaceTypeLoc TL) { |
| 6580 | |
| 6581 | TL.setAttrNameLoc(readSourceLocation()); |
| 6582 | TL.setAttrOperandParensRange(Reader.readSourceRange()); |
| 6583 | TL.setAttrExprOperand(Reader.readExpr()); |
| 6584 | } |
| 6585 | |
| 6586 | void TypeLocReader::VisitDependentSizedExtVectorTypeLoc( |
| 6587 | DependentSizedExtVectorTypeLoc TL) { |
| 6588 | TL.setNameLoc(readSourceLocation()); |
| 6589 | } |
| 6590 | |
| 6591 | void TypeLocReader::VisitVectorTypeLoc(VectorTypeLoc TL) { |
| 6592 | TL.setNameLoc(readSourceLocation()); |
| 6593 | } |
| 6594 | |
| 6595 | void TypeLocReader::VisitDependentVectorTypeLoc( |
| 6596 | DependentVectorTypeLoc TL) { |
| 6597 | TL.setNameLoc(readSourceLocation()); |
| 6598 | } |
| 6599 | |
| 6600 | void TypeLocReader::VisitExtVectorTypeLoc(ExtVectorTypeLoc TL) { |
| 6601 | TL.setNameLoc(readSourceLocation()); |
| 6602 | } |
| 6603 | |
| 6604 | void TypeLocReader::VisitConstantMatrixTypeLoc(ConstantMatrixTypeLoc TL) { |
| 6605 | TL.setAttrNameLoc(readSourceLocation()); |
| 6606 | TL.setAttrOperandParensRange(Reader.readSourceRange()); |
| 6607 | TL.setAttrRowOperand(Reader.readExpr()); |
| 6608 | TL.setAttrColumnOperand(Reader.readExpr()); |
| 6609 | } |
| 6610 | |
| 6611 | void TypeLocReader::VisitDependentSizedMatrixTypeLoc( |
| 6612 | DependentSizedMatrixTypeLoc TL) { |
| 6613 | TL.setAttrNameLoc(readSourceLocation()); |
| 6614 | TL.setAttrOperandParensRange(Reader.readSourceRange()); |
| 6615 | TL.setAttrRowOperand(Reader.readExpr()); |
| 6616 | TL.setAttrColumnOperand(Reader.readExpr()); |
| 6617 | } |
| 6618 | |
| 6619 | void TypeLocReader::VisitFunctionTypeLoc(FunctionTypeLoc TL) { |
| 6620 | TL.setLocalRangeBegin(readSourceLocation()); |
| 6621 | TL.setLParenLoc(readSourceLocation()); |
| 6622 | TL.setRParenLoc(readSourceLocation()); |
| 6623 | TL.setExceptionSpecRange(Reader.readSourceRange()); |
| 6624 | TL.setLocalRangeEnd(readSourceLocation()); |
| 6625 | for (unsigned i = 0, e = TL.getNumParams(); i != e; ++i) { |
| 6626 | TL.setParam(i, Reader.readDeclAs<ParmVarDecl>()); |
| 6627 | } |
| 6628 | } |
| 6629 | |
| 6630 | void TypeLocReader::VisitFunctionProtoTypeLoc(FunctionProtoTypeLoc TL) { |
| 6631 | VisitFunctionTypeLoc(TL); |
| 6632 | } |
| 6633 | |
| 6634 | void TypeLocReader::VisitFunctionNoProtoTypeLoc(FunctionNoProtoTypeLoc TL) { |
| 6635 | VisitFunctionTypeLoc(TL); |
| 6636 | } |
| 6637 | |
| 6638 | void TypeLocReader::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) { |
| 6639 | TL.setNameLoc(readSourceLocation()); |
| 6640 | } |
| 6641 | |
| 6642 | void TypeLocReader::VisitTypedefTypeLoc(TypedefTypeLoc TL) { |
| 6643 | TL.setNameLoc(readSourceLocation()); |
| 6644 | } |
| 6645 | |
| 6646 | void TypeLocReader::VisitTypeOfExprTypeLoc(TypeOfExprTypeLoc TL) { |
| 6647 | TL.setTypeofLoc(readSourceLocation()); |
| 6648 | TL.setLParenLoc(readSourceLocation()); |
| 6649 | TL.setRParenLoc(readSourceLocation()); |
| 6650 | } |
| 6651 | |
| 6652 | void TypeLocReader::VisitTypeOfTypeLoc(TypeOfTypeLoc TL) { |
| 6653 | TL.setTypeofLoc(readSourceLocation()); |
| 6654 | TL.setLParenLoc(readSourceLocation()); |
| 6655 | TL.setRParenLoc(readSourceLocation()); |
| 6656 | TL.setUnderlyingTInfo(GetTypeSourceInfo()); |
| 6657 | } |
| 6658 | |
| 6659 | void TypeLocReader::VisitDecltypeTypeLoc(DecltypeTypeLoc TL) { |
| 6660 | TL.setNameLoc(readSourceLocation()); |
| 6661 | } |
| 6662 | |
| 6663 | void TypeLocReader::VisitUnaryTransformTypeLoc(UnaryTransformTypeLoc TL) { |
| 6664 | TL.setKWLoc(readSourceLocation()); |
| 6665 | TL.setLParenLoc(readSourceLocation()); |
| 6666 | TL.setRParenLoc(readSourceLocation()); |
| 6667 | TL.setUnderlyingTInfo(GetTypeSourceInfo()); |
| 6668 | } |
| 6669 | |
| 6670 | void TypeLocReader::VisitAutoTypeLoc(AutoTypeLoc TL) { |
| 6671 | TL.setNameLoc(readSourceLocation()); |
| 6672 | if (Reader.readBool()) { |
| 6673 | TL.setNestedNameSpecifierLoc(ReadNestedNameSpecifierLoc()); |
| 6674 | TL.setTemplateKWLoc(readSourceLocation()); |
| 6675 | TL.setConceptNameLoc(readSourceLocation()); |
| 6676 | TL.setFoundDecl(Reader.readDeclAs<NamedDecl>()); |
| 6677 | TL.setLAngleLoc(readSourceLocation()); |
| 6678 | TL.setRAngleLoc(readSourceLocation()); |
| 6679 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 6680 | TL.setArgLocInfo(i, Reader.readTemplateArgumentLocInfo( |
| 6681 | TL.getTypePtr()->getArg(i).getKind())); |
| 6682 | } |
| 6683 | } |
| 6684 | |
| 6685 | void TypeLocReader::VisitDeducedTemplateSpecializationTypeLoc( |
| 6686 | DeducedTemplateSpecializationTypeLoc TL) { |
| 6687 | TL.setTemplateNameLoc(readSourceLocation()); |
| 6688 | } |
| 6689 | |
| 6690 | void TypeLocReader::VisitRecordTypeLoc(RecordTypeLoc TL) { |
| 6691 | TL.setNameLoc(readSourceLocation()); |
| 6692 | } |
| 6693 | |
| 6694 | void TypeLocReader::VisitEnumTypeLoc(EnumTypeLoc TL) { |
| 6695 | TL.setNameLoc(readSourceLocation()); |
| 6696 | } |
| 6697 | |
| 6698 | void TypeLocReader::VisitAttributedTypeLoc(AttributedTypeLoc TL) { |
| 6699 | TL.setAttr(ReadAttr()); |
| 6700 | } |
| 6701 | |
| 6702 | void TypeLocReader::VisitTemplateTypeParmTypeLoc(TemplateTypeParmTypeLoc TL) { |
| 6703 | TL.setNameLoc(readSourceLocation()); |
| 6704 | } |
| 6705 | |
| 6706 | void TypeLocReader::VisitSubstTemplateTypeParmTypeLoc( |
| 6707 | SubstTemplateTypeParmTypeLoc TL) { |
| 6708 | TL.setNameLoc(readSourceLocation()); |
| 6709 | } |
| 6710 | |
| 6711 | void TypeLocReader::VisitSubstTemplateTypeParmPackTypeLoc( |
| 6712 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 6713 | TL.setNameLoc(readSourceLocation()); |
| 6714 | } |
| 6715 | |
| 6716 | void TypeLocReader::VisitTemplateSpecializationTypeLoc( |
| 6717 | TemplateSpecializationTypeLoc TL) { |
| 6718 | TL.setTemplateKeywordLoc(readSourceLocation()); |
| 6719 | TL.setTemplateNameLoc(readSourceLocation()); |
| 6720 | TL.setLAngleLoc(readSourceLocation()); |
| 6721 | TL.setRAngleLoc(readSourceLocation()); |
| 6722 | for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) |
| 6723 | TL.setArgLocInfo( |
| 6724 | i, |
| 6725 | Reader.readTemplateArgumentLocInfo( |
| 6726 | TL.getTypePtr()->getArg(i).getKind())); |
| 6727 | } |
| 6728 | |
| 6729 | void TypeLocReader::VisitParenTypeLoc(ParenTypeLoc TL) { |
| 6730 | TL.setLParenLoc(readSourceLocation()); |
| 6731 | TL.setRParenLoc(readSourceLocation()); |
| 6732 | } |
| 6733 | |
| 6734 | void TypeLocReader::VisitElaboratedTypeLoc(ElaboratedTypeLoc TL) { |
| 6735 | TL.setElaboratedKeywordLoc(readSourceLocation()); |
| 6736 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
| 6737 | } |
| 6738 | |
| 6739 | void TypeLocReader::VisitInjectedClassNameTypeLoc(InjectedClassNameTypeLoc TL) { |
| 6740 | TL.setNameLoc(readSourceLocation()); |
| 6741 | } |
| 6742 | |
| 6743 | void TypeLocReader::VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { |
| 6744 | TL.setElaboratedKeywordLoc(readSourceLocation()); |
| 6745 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
| 6746 | TL.setNameLoc(readSourceLocation()); |
| 6747 | } |
| 6748 | |
| 6749 | void TypeLocReader::VisitDependentTemplateSpecializationTypeLoc( |
| 6750 | DependentTemplateSpecializationTypeLoc TL) { |
| 6751 | TL.setElaboratedKeywordLoc(readSourceLocation()); |
| 6752 | TL.setQualifierLoc(ReadNestedNameSpecifierLoc()); |
| 6753 | TL.setTemplateKeywordLoc(readSourceLocation()); |
| 6754 | TL.setTemplateNameLoc(readSourceLocation()); |
| 6755 | TL.setLAngleLoc(readSourceLocation()); |
| 6756 | TL.setRAngleLoc(readSourceLocation()); |
| 6757 | for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) |
| 6758 | TL.setArgLocInfo( |
| 6759 | I, |
| 6760 | Reader.readTemplateArgumentLocInfo( |
| 6761 | TL.getTypePtr()->getArg(I).getKind())); |
| 6762 | } |
| 6763 | |
| 6764 | void TypeLocReader::VisitPackExpansionTypeLoc(PackExpansionTypeLoc TL) { |
| 6765 | TL.setEllipsisLoc(readSourceLocation()); |
| 6766 | } |
| 6767 | |
| 6768 | void TypeLocReader::VisitObjCInterfaceTypeLoc(ObjCInterfaceTypeLoc TL) { |
| 6769 | TL.setNameLoc(readSourceLocation()); |
| 6770 | } |
| 6771 | |
| 6772 | void TypeLocReader::VisitObjCTypeParamTypeLoc(ObjCTypeParamTypeLoc TL) { |
| 6773 | if (TL.getNumProtocols()) { |
| 6774 | TL.setProtocolLAngleLoc(readSourceLocation()); |
| 6775 | TL.setProtocolRAngleLoc(readSourceLocation()); |
| 6776 | } |
| 6777 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 6778 | TL.setProtocolLoc(i, readSourceLocation()); |
| 6779 | } |
| 6780 | |
| 6781 | void TypeLocReader::VisitObjCObjectTypeLoc(ObjCObjectTypeLoc TL) { |
| 6782 | TL.setHasBaseTypeAsWritten(Reader.readBool()); |
| 6783 | TL.setTypeArgsLAngleLoc(readSourceLocation()); |
| 6784 | TL.setTypeArgsRAngleLoc(readSourceLocation()); |
| 6785 | for (unsigned i = 0, e = TL.getNumTypeArgs(); i != e; ++i) |
| 6786 | TL.setTypeArgTInfo(i, GetTypeSourceInfo()); |
| 6787 | TL.setProtocolLAngleLoc(readSourceLocation()); |
| 6788 | TL.setProtocolRAngleLoc(readSourceLocation()); |
| 6789 | for (unsigned i = 0, e = TL.getNumProtocols(); i != e; ++i) |
| 6790 | TL.setProtocolLoc(i, readSourceLocation()); |
| 6791 | } |
| 6792 | |
| 6793 | void TypeLocReader::VisitObjCObjectPointerTypeLoc(ObjCObjectPointerTypeLoc TL) { |
| 6794 | TL.setStarLoc(readSourceLocation()); |
| 6795 | } |
| 6796 | |
| 6797 | void TypeLocReader::VisitAtomicTypeLoc(AtomicTypeLoc TL) { |
| 6798 | TL.setKWLoc(readSourceLocation()); |
| 6799 | TL.setLParenLoc(readSourceLocation()); |
| 6800 | TL.setRParenLoc(readSourceLocation()); |
| 6801 | } |
| 6802 | |
| 6803 | void TypeLocReader::VisitPipeTypeLoc(PipeTypeLoc TL) { |
| 6804 | TL.setKWLoc(readSourceLocation()); |
| 6805 | } |
| 6806 | |
| 6807 | void TypeLocReader::VisitExtIntTypeLoc(clang::ExtIntTypeLoc TL) { |
| 6808 | TL.setNameLoc(readSourceLocation()); |
| 6809 | } |
| 6810 | void TypeLocReader::VisitDependentExtIntTypeLoc( |
| 6811 | clang::DependentExtIntTypeLoc TL) { |
| 6812 | TL.setNameLoc(readSourceLocation()); |
| 6813 | } |
| 6814 | |
| 6815 | |
| 6816 | void ASTRecordReader::readTypeLoc(TypeLoc TL) { |
| 6817 | TypeLocReader TLR(*this); |
| 6818 | for (; !TL.isNull(); TL = TL.getNextTypeLoc()) |
| 6819 | TLR.Visit(TL); |
| 6820 | } |
| 6821 | |
| 6822 | TypeSourceInfo *ASTRecordReader::readTypeSourceInfo() { |
| 6823 | QualType InfoTy = readType(); |
| 6824 | if (InfoTy.isNull()) |
| 6825 | return nullptr; |
| 6826 | |
| 6827 | TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy); |
| 6828 | readTypeLoc(TInfo->getTypeLoc()); |
| 6829 | return TInfo; |
| 6830 | } |
| 6831 | |
| 6832 | QualType ASTReader::GetType(TypeID ID) { |
| 6833 | assert(ContextObj && "reading type with no AST context"); |
| 6834 | ASTContext &Context = *ContextObj; |
| 6835 | |
| 6836 | unsigned FastQuals = ID & Qualifiers::FastMask; |
| 6837 | unsigned Index = ID >> Qualifiers::FastWidth; |
| 6838 | |
| 6839 | if (Index < NUM_PREDEF_TYPE_IDS) { |
| 6840 | QualType T; |
| 6841 | switch ((PredefinedTypeIDs)Index) { |
| 6842 | case PREDEF_TYPE_NULL_ID: |
| 6843 | return QualType(); |
| 6844 | case PREDEF_TYPE_VOID_ID: |
| 6845 | T = Context.VoidTy; |
| 6846 | break; |
| 6847 | case PREDEF_TYPE_BOOL_ID: |
| 6848 | T = Context.BoolTy; |
| 6849 | break; |
| 6850 | case PREDEF_TYPE_CHAR_U_ID: |
| 6851 | case PREDEF_TYPE_CHAR_S_ID: |
| 6852 | |
| 6853 | T = Context.CharTy; |
| 6854 | break; |
| 6855 | case PREDEF_TYPE_UCHAR_ID: |
| 6856 | T = Context.UnsignedCharTy; |
| 6857 | break; |
| 6858 | case PREDEF_TYPE_USHORT_ID: |
| 6859 | T = Context.UnsignedShortTy; |
| 6860 | break; |
| 6861 | case PREDEF_TYPE_UINT_ID: |
| 6862 | T = Context.UnsignedIntTy; |
| 6863 | break; |
| 6864 | case PREDEF_TYPE_ULONG_ID: |
| 6865 | T = Context.UnsignedLongTy; |
| 6866 | break; |
| 6867 | case PREDEF_TYPE_ULONGLONG_ID: |
| 6868 | T = Context.UnsignedLongLongTy; |
| 6869 | break; |
| 6870 | case PREDEF_TYPE_UINT128_ID: |
| 6871 | T = Context.UnsignedInt128Ty; |
| 6872 | break; |
| 6873 | case PREDEF_TYPE_SCHAR_ID: |
| 6874 | T = Context.SignedCharTy; |
| 6875 | break; |
| 6876 | case PREDEF_TYPE_WCHAR_ID: |
| 6877 | T = Context.WCharTy; |
| 6878 | break; |
| 6879 | case PREDEF_TYPE_SHORT_ID: |
| 6880 | T = Context.ShortTy; |
| 6881 | break; |
| 6882 | case PREDEF_TYPE_INT_ID: |
| 6883 | T = Context.IntTy; |
| 6884 | break; |
| 6885 | case PREDEF_TYPE_LONG_ID: |
| 6886 | T = Context.LongTy; |
| 6887 | break; |
| 6888 | case PREDEF_TYPE_LONGLONG_ID: |
| 6889 | T = Context.LongLongTy; |
| 6890 | break; |
| 6891 | case PREDEF_TYPE_INT128_ID: |
| 6892 | T = Context.Int128Ty; |
| 6893 | break; |
| 6894 | case PREDEF_TYPE_BFLOAT16_ID: |
| 6895 | T = Context.BFloat16Ty; |
| 6896 | break; |
| 6897 | case PREDEF_TYPE_HALF_ID: |
| 6898 | T = Context.HalfTy; |
| 6899 | break; |
| 6900 | case PREDEF_TYPE_FLOAT_ID: |
| 6901 | T = Context.FloatTy; |
| 6902 | break; |
| 6903 | case PREDEF_TYPE_DOUBLE_ID: |
| 6904 | T = Context.DoubleTy; |
| 6905 | break; |
| 6906 | case PREDEF_TYPE_LONGDOUBLE_ID: |
| 6907 | T = Context.LongDoubleTy; |
| 6908 | break; |
| 6909 | case PREDEF_TYPE_SHORT_ACCUM_ID: |
| 6910 | T = Context.ShortAccumTy; |
| 6911 | break; |
| 6912 | case PREDEF_TYPE_ACCUM_ID: |
| 6913 | T = Context.AccumTy; |
| 6914 | break; |
| 6915 | case PREDEF_TYPE_LONG_ACCUM_ID: |
| 6916 | T = Context.LongAccumTy; |
| 6917 | break; |
| 6918 | case PREDEF_TYPE_USHORT_ACCUM_ID: |
| 6919 | T = Context.UnsignedShortAccumTy; |
| 6920 | break; |
| 6921 | case PREDEF_TYPE_UACCUM_ID: |
| 6922 | T = Context.UnsignedAccumTy; |
| 6923 | break; |
| 6924 | case PREDEF_TYPE_ULONG_ACCUM_ID: |
| 6925 | T = Context.UnsignedLongAccumTy; |
| 6926 | break; |
| 6927 | case PREDEF_TYPE_SHORT_FRACT_ID: |
| 6928 | T = Context.ShortFractTy; |
| 6929 | break; |
| 6930 | case PREDEF_TYPE_FRACT_ID: |
| 6931 | T = Context.FractTy; |
| 6932 | break; |
| 6933 | case PREDEF_TYPE_LONG_FRACT_ID: |
| 6934 | T = Context.LongFractTy; |
| 6935 | break; |
| 6936 | case PREDEF_TYPE_USHORT_FRACT_ID: |
| 6937 | T = Context.UnsignedShortFractTy; |
| 6938 | break; |
| 6939 | case PREDEF_TYPE_UFRACT_ID: |
| 6940 | T = Context.UnsignedFractTy; |
| 6941 | break; |
| 6942 | case PREDEF_TYPE_ULONG_FRACT_ID: |
| 6943 | T = Context.UnsignedLongFractTy; |
| 6944 | break; |
| 6945 | case PREDEF_TYPE_SAT_SHORT_ACCUM_ID: |
| 6946 | T = Context.SatShortAccumTy; |
| 6947 | break; |
| 6948 | case PREDEF_TYPE_SAT_ACCUM_ID: |
| 6949 | T = Context.SatAccumTy; |
| 6950 | break; |
| 6951 | case PREDEF_TYPE_SAT_LONG_ACCUM_ID: |
| 6952 | T = Context.SatLongAccumTy; |
| 6953 | break; |
| 6954 | case PREDEF_TYPE_SAT_USHORT_ACCUM_ID: |
| 6955 | T = Context.SatUnsignedShortAccumTy; |
| 6956 | break; |
| 6957 | case PREDEF_TYPE_SAT_UACCUM_ID: |
| 6958 | T = Context.SatUnsignedAccumTy; |
| 6959 | break; |
| 6960 | case PREDEF_TYPE_SAT_ULONG_ACCUM_ID: |
| 6961 | T = Context.SatUnsignedLongAccumTy; |
| 6962 | break; |
| 6963 | case PREDEF_TYPE_SAT_SHORT_FRACT_ID: |
| 6964 | T = Context.SatShortFractTy; |
| 6965 | break; |
| 6966 | case PREDEF_TYPE_SAT_FRACT_ID: |
| 6967 | T = Context.SatFractTy; |
| 6968 | break; |
| 6969 | case PREDEF_TYPE_SAT_LONG_FRACT_ID: |
| 6970 | T = Context.SatLongFractTy; |
| 6971 | break; |
| 6972 | case PREDEF_TYPE_SAT_USHORT_FRACT_ID: |
| 6973 | T = Context.SatUnsignedShortFractTy; |
| 6974 | break; |
| 6975 | case PREDEF_TYPE_SAT_UFRACT_ID: |
| 6976 | T = Context.SatUnsignedFractTy; |
| 6977 | break; |
| 6978 | case PREDEF_TYPE_SAT_ULONG_FRACT_ID: |
| 6979 | T = Context.SatUnsignedLongFractTy; |
| 6980 | break; |
| 6981 | case PREDEF_TYPE_FLOAT16_ID: |
| 6982 | T = Context.Float16Ty; |
| 6983 | break; |
| 6984 | case PREDEF_TYPE_FLOAT128_ID: |
| 6985 | T = Context.Float128Ty; |
| 6986 | break; |
| 6987 | case PREDEF_TYPE_OVERLOAD_ID: |
| 6988 | T = Context.OverloadTy; |
| 6989 | break; |
| 6990 | case PREDEF_TYPE_BOUND_MEMBER: |
| 6991 | T = Context.BoundMemberTy; |
| 6992 | break; |
| 6993 | case PREDEF_TYPE_PSEUDO_OBJECT: |
| 6994 | T = Context.PseudoObjectTy; |
| 6995 | break; |
| 6996 | case PREDEF_TYPE_DEPENDENT_ID: |
| 6997 | T = Context.DependentTy; |
| 6998 | break; |
| 6999 | case PREDEF_TYPE_UNKNOWN_ANY: |
| 7000 | T = Context.UnknownAnyTy; |
| 7001 | break; |
| 7002 | case PREDEF_TYPE_NULLPTR_ID: |
| 7003 | T = Context.NullPtrTy; |
| 7004 | break; |
| 7005 | case PREDEF_TYPE_CHAR8_ID: |
| 7006 | T = Context.Char8Ty; |
| 7007 | break; |
| 7008 | case PREDEF_TYPE_CHAR16_ID: |
| 7009 | T = Context.Char16Ty; |
| 7010 | break; |
| 7011 | case PREDEF_TYPE_CHAR32_ID: |
| 7012 | T = Context.Char32Ty; |
| 7013 | break; |
| 7014 | case PREDEF_TYPE_OBJC_ID: |
| 7015 | T = Context.ObjCBuiltinIdTy; |
| 7016 | break; |
| 7017 | case PREDEF_TYPE_OBJC_CLASS: |
| 7018 | T = Context.ObjCBuiltinClassTy; |
| 7019 | break; |
| 7020 | case PREDEF_TYPE_OBJC_SEL: |
| 7021 | T = Context.ObjCBuiltinSelTy; |
| 7022 | break; |
| 7023 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 7024 | case PREDEF_TYPE_##Id##_ID: \ |
| 7025 | T = Context.SingletonId; \ |
| 7026 | break; |
| 7027 | #include "clang/Basic/OpenCLImageTypes.def" |
| 7028 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 7029 | case PREDEF_TYPE_##Id##_ID: \ |
| 7030 | T = Context.Id##Ty; \ |
| 7031 | break; |
| 7032 | #include "clang/Basic/OpenCLExtensionTypes.def" |
| 7033 | case PREDEF_TYPE_SAMPLER_ID: |
| 7034 | T = Context.OCLSamplerTy; |
| 7035 | break; |
| 7036 | case PREDEF_TYPE_EVENT_ID: |
| 7037 | T = Context.OCLEventTy; |
| 7038 | break; |
| 7039 | case PREDEF_TYPE_CLK_EVENT_ID: |
| 7040 | T = Context.OCLClkEventTy; |
| 7041 | break; |
| 7042 | case PREDEF_TYPE_QUEUE_ID: |
| 7043 | T = Context.OCLQueueTy; |
| 7044 | break; |
| 7045 | case PREDEF_TYPE_RESERVE_ID_ID: |
| 7046 | T = Context.OCLReserveIDTy; |
| 7047 | break; |
| 7048 | case PREDEF_TYPE_AUTO_DEDUCT: |
| 7049 | T = Context.getAutoDeductType(); |
| 7050 | break; |
| 7051 | case PREDEF_TYPE_AUTO_RREF_DEDUCT: |
| 7052 | T = Context.getAutoRRefDeductType(); |
| 7053 | break; |
| 7054 | case PREDEF_TYPE_ARC_UNBRIDGED_CAST: |
| 7055 | T = Context.ARCUnbridgedCastTy; |
| 7056 | break; |
| 7057 | case PREDEF_TYPE_BUILTIN_FN: |
| 7058 | T = Context.BuiltinFnTy; |
| 7059 | break; |
| 7060 | case PREDEF_TYPE_INCOMPLETE_MATRIX_IDX: |
| 7061 | T = Context.IncompleteMatrixIdxTy; |
| 7062 | break; |
| 7063 | case PREDEF_TYPE_OMP_ARRAY_SECTION: |
| 7064 | T = Context.OMPArraySectionTy; |
| 7065 | break; |
| 7066 | case PREDEF_TYPE_OMP_ARRAY_SHAPING: |
| 7067 | T = Context.OMPArraySectionTy; |
| 7068 | break; |
| 7069 | case PREDEF_TYPE_OMP_ITERATOR: |
| 7070 | T = Context.OMPIteratorTy; |
| 7071 | break; |
| 7072 | #define SVE_TYPE(Name, Id, SingletonId) \ |
| 7073 | case PREDEF_TYPE_##Id##_ID: \ |
| 7074 | T = Context.SingletonId; \ |
| 7075 | break; |
| 7076 | #include "clang/Basic/AArch64SVEACLETypes.def" |
| 7077 | #define PPC_VECTOR_TYPE(Name, Id, Size) \ |
| 7078 | case PREDEF_TYPE_##Id##_ID: \ |
| 7079 | T = Context.Id##Ty; \ |
| 7080 | break; |
| 7081 | #include "clang/Basic/PPCTypes.def" |
| 7082 | #define RVV_TYPE(Name, Id, SingletonId) \ |
| 7083 | case PREDEF_TYPE_##Id##_ID: \ |
| 7084 | T = Context.SingletonId; \ |
| 7085 | break; |
| 7086 | #include "clang/Basic/RISCVVTypes.def" |
| 7087 | } |
| 7088 | |
| 7089 | assert(!T.isNull() && "Unknown predefined type"); |
| 7090 | return T.withFastQualifiers(FastQuals); |
| 7091 | } |
| 7092 | |
| 7093 | Index -= NUM_PREDEF_TYPE_IDS; |
| 7094 | assert(Index < TypesLoaded.size() && "Type index out-of-range"); |
| 7095 | if (TypesLoaded[Index].isNull()) { |
| 7096 | TypesLoaded[Index] = readTypeRecord(Index); |
| 7097 | if (TypesLoaded[Index].isNull()) |
| 7098 | return QualType(); |
| 7099 | |
| 7100 | TypesLoaded[Index]->setFromAST(); |
| 7101 | if (DeserializationListener) |
| 7102 | DeserializationListener->TypeRead(TypeIdx::fromTypeID(ID), |
| 7103 | TypesLoaded[Index]); |
| 7104 | } |
| 7105 | |
| 7106 | return TypesLoaded[Index].withFastQualifiers(FastQuals); |
| 7107 | } |
| 7108 | |
| 7109 | QualType ASTReader::getLocalType(ModuleFile &F, unsigned LocalID) { |
| 7110 | return GetType(getGlobalTypeID(F, LocalID)); |
| 7111 | } |
| 7112 | |
| 7113 | serialization::TypeID |
| 7114 | ASTReader::getGlobalTypeID(ModuleFile &F, unsigned LocalID) const { |
| 7115 | unsigned FastQuals = LocalID & Qualifiers::FastMask; |
| 7116 | unsigned LocalIndex = LocalID >> Qualifiers::FastWidth; |
| 7117 | |
| 7118 | if (LocalIndex < NUM_PREDEF_TYPE_IDS) |
| 7119 | return LocalID; |
| 7120 | |
| 7121 | if (!F.ModuleOffsetMap.empty()) |
| 7122 | ReadModuleOffsetMap(F); |
| 7123 | |
| 7124 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 7125 | = F.TypeRemap.find(LocalIndex - NUM_PREDEF_TYPE_IDS); |
| 7126 | assert(I != F.TypeRemap.end() && "Invalid index into type index remap"); |
| 7127 | |
| 7128 | unsigned GlobalIndex = LocalIndex + I->second; |
| 7129 | return (GlobalIndex << Qualifiers::FastWidth) | FastQuals; |
| 7130 | } |
| 7131 | |
| 7132 | TemplateArgumentLocInfo |
| 7133 | ASTRecordReader::readTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind) { |
| 7134 | switch (Kind) { |
| 7135 | case TemplateArgument::Expression: |
| 7136 | return readExpr(); |
| 7137 | case TemplateArgument::Type: |
| 7138 | return readTypeSourceInfo(); |
| 7139 | case TemplateArgument::Template: { |
| 7140 | NestedNameSpecifierLoc QualifierLoc = |
| 7141 | readNestedNameSpecifierLoc(); |
| 7142 | SourceLocation TemplateNameLoc = readSourceLocation(); |
| 7143 | return TemplateArgumentLocInfo(getASTContext(), QualifierLoc, |
| 7144 | TemplateNameLoc, SourceLocation()); |
| 7145 | } |
| 7146 | case TemplateArgument::TemplateExpansion: { |
| 7147 | NestedNameSpecifierLoc QualifierLoc = readNestedNameSpecifierLoc(); |
| 7148 | SourceLocation TemplateNameLoc = readSourceLocation(); |
| 7149 | SourceLocation EllipsisLoc = readSourceLocation(); |
| 7150 | return TemplateArgumentLocInfo(getASTContext(), QualifierLoc, |
| 7151 | TemplateNameLoc, EllipsisLoc); |
| 7152 | } |
| 7153 | case TemplateArgument::Null: |
| 7154 | case TemplateArgument::Integral: |
| 7155 | case TemplateArgument::Declaration: |
| 7156 | case TemplateArgument::NullPtr: |
| 7157 | case TemplateArgument::Pack: |
| 7158 | |
| 7159 | return TemplateArgumentLocInfo(); |
| 7160 | } |
| 7161 | llvm_unreachable("unexpected template argument loc"); |
| 7162 | } |
| 7163 | |
| 7164 | TemplateArgumentLoc ASTRecordReader::readTemplateArgumentLoc() { |
| 7165 | TemplateArgument Arg = readTemplateArgument(); |
| 7166 | |
| 7167 | if (Arg.getKind() == TemplateArgument::Expression) { |
| 7168 | if (readBool()) |
| 7169 | return TemplateArgumentLoc(Arg, TemplateArgumentLocInfo(Arg.getAsExpr())); |
| 7170 | } |
| 7171 | return TemplateArgumentLoc(Arg, readTemplateArgumentLocInfo(Arg.getKind())); |
| 7172 | } |
| 7173 | |
| 7174 | const ASTTemplateArgumentListInfo * |
| 7175 | ASTRecordReader::readASTTemplateArgumentListInfo() { |
| 7176 | SourceLocation LAngleLoc = readSourceLocation(); |
| 7177 | SourceLocation RAngleLoc = readSourceLocation(); |
| 7178 | unsigned NumArgsAsWritten = readInt(); |
| 7179 | TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); |
| 7180 | for (unsigned i = 0; i != NumArgsAsWritten; ++i) |
| 7181 | TemplArgsInfo.addArgument(readTemplateArgumentLoc()); |
| 7182 | return ASTTemplateArgumentListInfo::Create(getContext(), TemplArgsInfo); |
| 7183 | } |
| 7184 | |
| 7185 | Decl *ASTReader::GetExternalDecl(uint32_t ID) { |
| 7186 | return GetDecl(ID); |
| 7187 | } |
| 7188 | |
| 7189 | void ASTReader::CompleteRedeclChain(const Decl *D) { |
| 7190 | if (NumCurrentElementsDeserializing) { |
| 7191 | |
| 7192 | |
| 7193 | |
| 7194 | |
| 7195 | PendingIncompleteDeclChains.push_back(const_cast<Decl*>(D)); |
| 7196 | return; |
| 7197 | } |
| 7198 | |
| 7199 | if (!D->getDeclContext()) { |
| 7200 | assert(isa<TranslationUnitDecl>(D) && "Not a TU?"); |
| 7201 | return; |
| 7202 | } |
| 7203 | |
| 7204 | const DeclContext *DC = D->getDeclContext()->getRedeclContext(); |
| 7205 | |
| 7206 | |
| 7207 | |
| 7208 | |
| 7209 | |
| 7210 | |
| 7211 | if (isa<TranslationUnitDecl>(DC) || isa<NamespaceDecl>(DC) || |
| 7212 | isa<CXXRecordDecl>(DC) || isa<EnumDecl>(DC)) { |
| 7213 | if (DeclarationName Name = cast<NamedDecl>(D)->getDeclName()) { |
| 7214 | if (!getContext().getLangOpts().CPlusPlus && |
| 7215 | isa<TranslationUnitDecl>(DC)) { |
| 7216 | |
| 7217 | |
| 7218 | |
| 7219 | auto *II = Name.getAsIdentifierInfo(); |
| 7220 | assert(II && "non-identifier name in C?"); |
| 7221 | if (II->isOutOfDate()) |
| 7222 | updateOutOfDateIdentifier(*II); |
| 7223 | } else |
| 7224 | DC->lookup(Name); |
| 7225 | } else if (needsAnonymousDeclarationNumber(cast<NamedDecl>(D))) { |
| 7226 | |
| 7227 | for (auto *DCDecl : cast<Decl>(D->getLexicalDeclContext())->redecls()) { |
| 7228 | auto *DC = cast<DeclContext>(DCDecl); |
| 7229 | SmallVector<Decl*, 8> Decls; |
| 7230 | FindExternalLexicalDecls( |
| 7231 | DC, [&](Decl::Kind K) { return K == D->getKind(); }, Decls); |
| 7232 | } |
| 7233 | } |
| 7234 | } |
| 7235 | |
| 7236 | if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D)) |
| 7237 | CTSD->getSpecializedTemplate()->LoadLazySpecializations(); |
| 7238 | if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) |
| 7239 | VTSD->getSpecializedTemplate()->LoadLazySpecializations(); |
| 7240 | if (auto *FD = dyn_cast<FunctionDecl>(D)) { |
| 7241 | if (auto *Template = FD->getPrimaryTemplate()) |
| 7242 | Template->LoadLazySpecializations(); |
| 7243 | } |
| 7244 | } |
| 7245 | |
| 7246 | CXXCtorInitializer ** |
| 7247 | ASTReader::GetExternalCXXCtorInitializers(uint64_t Offset) { |
| 7248 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 7249 | BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
| 7250 | SavedStreamPosition SavedPosition(Cursor); |
| 7251 | if (llvm::Error Err = Cursor.JumpToBit(Loc.Offset)) { |
| 7252 | Error(std::move(Err)); |
| 7253 | return nullptr; |
| 7254 | } |
| 7255 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 7256 | |
| 7257 | Expected<unsigned> MaybeCode = Cursor.ReadCode(); |
| 7258 | if (!MaybeCode) { |
| 7259 | Error(MaybeCode.takeError()); |
| 7260 | return nullptr; |
| 7261 | } |
| 7262 | unsigned Code = MaybeCode.get(); |
| 7263 | |
| 7264 | ASTRecordReader Record(*this, *Loc.F); |
| 7265 | Expected<unsigned> MaybeRecCode = Record.readRecord(Cursor, Code); |
| 7266 | if (!MaybeRecCode) { |
| 7267 | Error(MaybeRecCode.takeError()); |
| 7268 | return nullptr; |
| 7269 | } |
| 7270 | if (MaybeRecCode.get() != DECL_CXX_CTOR_INITIALIZERS) { |
| 7271 | Error("malformed AST file: missing C++ ctor initializers"); |
| 7272 | return nullptr; |
| 7273 | } |
| 7274 | |
| 7275 | return Record.readCXXCtorInitializers(); |
| 7276 | } |
| 7277 | |
| 7278 | CXXBaseSpecifier *ASTReader::GetExternalCXXBaseSpecifiers(uint64_t Offset) { |
| 7279 | assert(ContextObj && "reading base specifiers with no AST context"); |
| 7280 | ASTContext &Context = *ContextObj; |
| 7281 | |
| 7282 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 7283 | BitstreamCursor &Cursor = Loc.F->DeclsCursor; |
| 7284 | SavedStreamPosition SavedPosition(Cursor); |
| 7285 | if (llvm::Error Err = Cursor.JumpToBit(Loc.Offset)) { |
| 7286 | Error(std::move(Err)); |
| 7287 | return nullptr; |
| 7288 | } |
| 7289 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 7290 | |
| 7291 | Expected<unsigned> MaybeCode = Cursor.ReadCode(); |
| 7292 | if (!MaybeCode) { |
| 7293 | Error(MaybeCode.takeError()); |
| 7294 | return nullptr; |
| 7295 | } |
| 7296 | unsigned Code = MaybeCode.get(); |
| 7297 | |
| 7298 | ASTRecordReader Record(*this, *Loc.F); |
| 7299 | Expected<unsigned> MaybeRecCode = Record.readRecord(Cursor, Code); |
| 7300 | if (!MaybeRecCode) { |
| 7301 | Error(MaybeCode.takeError()); |
| 7302 | return nullptr; |
| 7303 | } |
| 7304 | unsigned RecCode = MaybeRecCode.get(); |
| 7305 | |
| 7306 | if (RecCode != DECL_CXX_BASE_SPECIFIERS) { |
| 7307 | Error("malformed AST file: missing C++ base specifiers"); |
| 7308 | return nullptr; |
| 7309 | } |
| 7310 | |
| 7311 | unsigned NumBases = Record.readInt(); |
| 7312 | void *Mem = Context.Allocate(sizeof(CXXBaseSpecifier) * NumBases); |
| 7313 | CXXBaseSpecifier *Bases = new (Mem) CXXBaseSpecifier [NumBases]; |
| 7314 | for (unsigned I = 0; I != NumBases; ++I) |
| 7315 | Bases[I] = Record.readCXXBaseSpecifier(); |
| 7316 | return Bases; |
| 7317 | } |
| 7318 | |
| 7319 | serialization::DeclID |
| 7320 | ASTReader::getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const { |
| 7321 | if (LocalID < NUM_PREDEF_DECL_IDS) |
| 7322 | return LocalID; |
| 7323 | |
| 7324 | if (!F.ModuleOffsetMap.empty()) |
| 7325 | ReadModuleOffsetMap(F); |
| 7326 | |
| 7327 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 7328 | = F.DeclRemap.find(LocalID - NUM_PREDEF_DECL_IDS); |
| 7329 | assert(I != F.DeclRemap.end() && "Invalid index into decl index remap"); |
| 7330 | |
| 7331 | return LocalID + I->second; |
| 7332 | } |
| 7333 | |
| 7334 | bool ASTReader::isDeclIDFromModule(serialization::GlobalDeclID ID, |
| 7335 | ModuleFile &M) const { |
| 7336 | |
| 7337 | if (ID < NUM_PREDEF_DECL_IDS) |
| 7338 | return false; |
| 7339 | |
| 7340 | return ID - NUM_PREDEF_DECL_IDS >= M.BaseDeclID && |
| 7341 | ID - NUM_PREDEF_DECL_IDS < M.BaseDeclID + M.LocalNumDecls; |
| 7342 | } |
| 7343 | |
| 7344 | ModuleFile *ASTReader::getOwningModuleFile(const Decl *D) { |
| 7345 | if (!D->isFromASTFile()) |
| 7346 | return nullptr; |
| 7347 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(D->getGlobalID()); |
| 7348 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 7349 | return I->second; |
| 7350 | } |
| 7351 | |
| 7352 | SourceLocation ASTReader::getSourceLocationForDeclID(GlobalDeclID ID) { |
| 7353 | if (ID < NUM_PREDEF_DECL_IDS) |
| 7354 | return SourceLocation(); |
| 7355 | |
| 7356 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 7357 | |
| 7358 | if (Index > DeclsLoaded.size()) { |
| 7359 | Error("declaration ID out-of-range for AST file"); |
| 7360 | return SourceLocation(); |
| 7361 | } |
| 7362 | |
| 7363 | if (Decl *D = DeclsLoaded[Index]) |
| 7364 | return D->getLocation(); |
| 7365 | |
| 7366 | SourceLocation Loc; |
| 7367 | DeclCursorForID(ID, Loc); |
| 7368 | return Loc; |
| 7369 | } |
| 7370 | |
| 7371 | static Decl *getPredefinedDecl(ASTContext &Context, PredefinedDeclIDs ID) { |
| 7372 | switch (ID) { |
| 7373 | case PREDEF_DECL_NULL_ID: |
| 7374 | return nullptr; |
| 7375 | |
| 7376 | case PREDEF_DECL_TRANSLATION_UNIT_ID: |
| 7377 | return Context.getTranslationUnitDecl(); |
| 7378 | |
| 7379 | case PREDEF_DECL_OBJC_ID_ID: |
| 7380 | return Context.getObjCIdDecl(); |
| 7381 | |
| 7382 | case PREDEF_DECL_OBJC_SEL_ID: |
| 7383 | return Context.getObjCSelDecl(); |
| 7384 | |
| 7385 | case PREDEF_DECL_OBJC_CLASS_ID: |
| 7386 | return Context.getObjCClassDecl(); |
| 7387 | |
| 7388 | case PREDEF_DECL_OBJC_PROTOCOL_ID: |
| 7389 | return Context.getObjCProtocolDecl(); |
| 7390 | |
| 7391 | case PREDEF_DECL_INT_128_ID: |
| 7392 | return Context.getInt128Decl(); |
| 7393 | |
| 7394 | case PREDEF_DECL_UNSIGNED_INT_128_ID: |
| 7395 | return Context.getUInt128Decl(); |
| 7396 | |
| 7397 | case PREDEF_DECL_OBJC_INSTANCETYPE_ID: |
| 7398 | return Context.getObjCInstanceTypeDecl(); |
| 7399 | |
| 7400 | case PREDEF_DECL_BUILTIN_VA_LIST_ID: |
| 7401 | return Context.getBuiltinVaListDecl(); |
| 7402 | |
| 7403 | case PREDEF_DECL_VA_LIST_TAG: |
| 7404 | return Context.getVaListTagDecl(); |
| 7405 | |
| 7406 | case PREDEF_DECL_BUILTIN_MS_VA_LIST_ID: |
| 7407 | return Context.getBuiltinMSVaListDecl(); |
| 7408 | |
| 7409 | case PREDEF_DECL_BUILTIN_MS_GUID_ID: |
| 7410 | return Context.getMSGuidTagDecl(); |
| 7411 | |
| 7412 | case PREDEF_DECL_EXTERN_C_CONTEXT_ID: |
| 7413 | return Context.getExternCContextDecl(); |
| 7414 | |
| 7415 | case PREDEF_DECL_MAKE_INTEGER_SEQ_ID: |
| 7416 | return Context.getMakeIntegerSeqDecl(); |
| 7417 | |
| 7418 | case PREDEF_DECL_CF_CONSTANT_STRING_ID: |
| 7419 | return Context.getCFConstantStringDecl(); |
| 7420 | |
| 7421 | case PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID: |
| 7422 | return Context.getCFConstantStringTagDecl(); |
| 7423 | |
| 7424 | case PREDEF_DECL_TYPE_PACK_ELEMENT_ID: |
| 7425 | return Context.getTypePackElementDecl(); |
| 7426 | } |
| 7427 | llvm_unreachable("PredefinedDeclIDs unknown enum value"); |
| 7428 | } |
| 7429 | |
| 7430 | Decl *ASTReader::GetExistingDecl(DeclID ID) { |
| 7431 | assert(ContextObj && "reading decl with no AST context"); |
| 7432 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 7433 | Decl *D = getPredefinedDecl(*ContextObj, (PredefinedDeclIDs)ID); |
| 7434 | if (D) { |
| 7435 | |
| 7436 | |
| 7437 | auto &Merged = KeyDecls[D->getCanonicalDecl()]; |
| 7438 | if (Merged.empty()) |
| 7439 | Merged.push_back(ID); |
| 7440 | } |
| 7441 | return D; |
| 7442 | } |
| 7443 | |
| 7444 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 7445 | |
| 7446 | if (Index >= DeclsLoaded.size()) { |
| 7447 | assert(0 && "declaration ID out-of-range for AST file"); |
| 7448 | Error("declaration ID out-of-range for AST file"); |
| 7449 | return nullptr; |
| 7450 | } |
| 7451 | |
| 7452 | return DeclsLoaded[Index]; |
| 7453 | } |
| 7454 | |
| 7455 | Decl *ASTReader::GetDecl(DeclID ID) { |
| 7456 | if (ID < NUM_PREDEF_DECL_IDS) |
| 7457 | return GetExistingDecl(ID); |
| 7458 | |
| 7459 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
| 7460 | |
| 7461 | if (Index >= DeclsLoaded.size()) { |
| 7462 | assert(0 && "declaration ID out-of-range for AST file"); |
| 7463 | Error("declaration ID out-of-range for AST file"); |
| 7464 | return nullptr; |
| 7465 | } |
| 7466 | |
| 7467 | if (!DeclsLoaded[Index]) { |
| 7468 | ReadDeclRecord(ID); |
| 7469 | if (DeserializationListener) |
| 7470 | DeserializationListener->DeclRead(ID, DeclsLoaded[Index]); |
| 7471 | } |
| 7472 | |
| 7473 | return DeclsLoaded[Index]; |
| 7474 | } |
| 7475 | |
| 7476 | DeclID ASTReader::mapGlobalIDToModuleFileGlobalID(ModuleFile &M, |
| 7477 | DeclID GlobalID) { |
| 7478 | if (GlobalID < NUM_PREDEF_DECL_IDS) |
| 7479 | return GlobalID; |
| 7480 | |
| 7481 | GlobalDeclMapType::const_iterator I = GlobalDeclMap.find(GlobalID); |
| 7482 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
| 7483 | ModuleFile *Owner = I->second; |
| 7484 | |
| 7485 | llvm::DenseMap<ModuleFile *, serialization::DeclID>::iterator Pos |
| 7486 | = M.GlobalToLocalDeclIDs.find(Owner); |
| 7487 | if (Pos == M.GlobalToLocalDeclIDs.end()) |
| 7488 | return 0; |
| 7489 | |
| 7490 | return GlobalID - Owner->BaseDeclID + Pos->second; |
| 7491 | } |
| 7492 | |
| 7493 | serialization::DeclID ASTReader::ReadDeclID(ModuleFile &F, |
| 7494 | const RecordData &Record, |
| 7495 | unsigned &Idx) { |
| 7496 | if (Idx >= Record.size()) { |
| 7497 | Error("Corrupted AST file"); |
| 7498 | return 0; |
| 7499 | } |
| 7500 | |
| 7501 | return getGlobalDeclID(F, Record[Idx++]); |
| 7502 | } |
| 7503 | |
| 7504 | |
| 7505 | |
| 7506 | |
| 7507 | |
| 7508 | |
| 7509 | Stmt *ASTReader::GetExternalDeclStmt(uint64_t Offset) { |
| 7510 | |
| 7511 | ClearSwitchCaseIDs(); |
| 7512 | |
| 7513 | |
| 7514 | RecordLocation Loc = getLocalBitOffset(Offset); |
| 7515 | if (llvm::Error Err = Loc.F->DeclsCursor.JumpToBit(Loc.Offset)) { |
| 7516 | Error(std::move(Err)); |
| 7517 | return nullptr; |
| 7518 | } |
| 7519 | assert(NumCurrentElementsDeserializing == 0 && |
| 7520 | "should not be called while already deserializing"); |
| 7521 | Deserializing D(this); |
| 7522 | return ReadStmtFromStream(*Loc.F); |
| 7523 | } |
| 7524 | |
| 7525 | void ASTReader::FindExternalLexicalDecls( |
| 7526 | const DeclContext *DC, llvm::function_ref<bool(Decl::Kind)> IsKindWeWant, |
| 7527 | SmallVectorImpl<Decl *> &Decls) { |
| 7528 | bool PredefsVisited[NUM_PREDEF_DECL_IDS] = {}; |
| 7529 | |
| 7530 | auto Visit = [&] (ModuleFile *M, LexicalContents LexicalDecls) { |
| 7531 | assert(LexicalDecls.size() % 2 == 0 && "expected an even number of entries"); |
| 7532 | for (int I = 0, N = LexicalDecls.size(); I != N; I += 2) { |
| 7533 | auto K = (Decl::Kind)+LexicalDecls[I]; |
| 7534 | if (!IsKindWeWant(K)) |
| 7535 | continue; |
| 7536 | |
| 7537 | auto ID = (serialization::DeclID)+LexicalDecls[I + 1]; |
| 7538 | |
| 7539 | |
| 7540 | |
| 7541 | if (ID < NUM_PREDEF_DECL_IDS) { |
| 7542 | if (PredefsVisited[ID]) |
| 7543 | continue; |
| 7544 | |
| 7545 | PredefsVisited[ID] = true; |
| 7546 | } |
| 7547 | |
| 7548 | if (Decl *D = GetLocalDecl(*M, ID)) { |
| 7549 | assert(D->getKind() == K && "wrong kind for lexical decl"); |
| 7550 | if (!DC->isDeclInLexicalTraversal(D)) |
| 7551 | Decls.push_back(D); |
| 7552 | } |
| 7553 | } |
| 7554 | }; |
| 7555 | |
| 7556 | if (isa<TranslationUnitDecl>(DC)) { |
| 7557 | for (auto Lexical : TULexicalDecls) |
| 7558 | Visit(Lexical.first, Lexical.second); |
| 7559 | } else { |
| 7560 | auto I = LexicalDecls.find(DC); |
| 7561 | if (I != LexicalDecls.end()) |
| 7562 | Visit(I->second.first, I->second.second); |
| 7563 | } |
| 7564 | |
| 7565 | ++NumLexicalDeclContextsRead; |
| 7566 | } |
| 7567 | |
| 7568 | namespace { |
| 7569 | |
| 7570 | class DeclIDComp { |
| 7571 | ASTReader &Reader; |
| 7572 | ModuleFile &Mod; |
| 7573 | |
| 7574 | public: |
| 7575 | DeclIDComp(ASTReader &Reader, ModuleFile &M) : Reader(Reader), Mod(M) {} |
| 7576 | |
| 7577 | bool operator()(LocalDeclID L, LocalDeclID R) const { |
| 7578 | SourceLocation LHS = getLocation(L); |
| 7579 | SourceLocation RHS = getLocation(R); |
| 7580 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7581 | } |
| 7582 | |
| 7583 | bool operator()(SourceLocation LHS, LocalDeclID R) const { |
| 7584 | SourceLocation RHS = getLocation(R); |
| 7585 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7586 | } |
| 7587 | |
| 7588 | bool operator()(LocalDeclID L, SourceLocation RHS) const { |
| 7589 | SourceLocation LHS = getLocation(L); |
| 7590 | return Reader.getSourceManager().isBeforeInTranslationUnit(LHS, RHS); |
| 7591 | } |
| 7592 | |
| 7593 | SourceLocation getLocation(LocalDeclID ID) const { |
| 7594 | return Reader.getSourceManager().getFileLoc( |
| 7595 | Reader.getSourceLocationForDeclID(Reader.getGlobalDeclID(Mod, ID))); |
| 7596 | } |
| 7597 | }; |
| 7598 | |
| 7599 | } |
| 7600 | |
| 7601 | void ASTReader::FindFileRegionDecls(FileID File, |
| 7602 | unsigned Offset, unsigned Length, |
| 7603 | SmallVectorImpl<Decl *> &Decls) { |
| 7604 | SourceManager &SM = getSourceManager(); |
| 7605 | |
| 7606 | llvm::DenseMap<FileID, FileDeclsInfo>::iterator I = FileDeclIDs.find(File); |
| 7607 | if (I == FileDeclIDs.end()) |
| 7608 | return; |
| 7609 | |
| 7610 | FileDeclsInfo &DInfo = I->second; |
| 7611 | if (DInfo.Decls.empty()) |
| 7612 | return; |
| 7613 | |
| 7614 | SourceLocation |
| 7615 | BeginLoc = SM.getLocForStartOfFile(File).getLocWithOffset(Offset); |
| 7616 | SourceLocation EndLoc = BeginLoc.getLocWithOffset(Length); |
| 7617 | |
| 7618 | DeclIDComp DIDComp(*this, *DInfo.Mod); |
| 7619 | ArrayRef<serialization::LocalDeclID>::iterator BeginIt = |
| 7620 | llvm::lower_bound(DInfo.Decls, BeginLoc, DIDComp); |
| 7621 | if (BeginIt != DInfo.Decls.begin()) |
| 7622 | --BeginIt; |
| 7623 | |
| 7624 | |
| 7625 | |
| 7626 | |
| 7627 | while (BeginIt != DInfo.Decls.begin() && |
| 7628 | GetDecl(getGlobalDeclID(*DInfo.Mod, *BeginIt)) |
| 7629 | ->isTopLevelDeclInObjCContainer()) |
| 7630 | --BeginIt; |
| 7631 | |
| 7632 | ArrayRef<serialization::LocalDeclID>::iterator EndIt = |
| 7633 | llvm::upper_bound(DInfo.Decls, EndLoc, DIDComp); |
| 7634 | if (EndIt != DInfo.Decls.end()) |
| 7635 | ++EndIt; |
| 7636 | |
| 7637 | for (ArrayRef<serialization::LocalDeclID>::iterator |
| 7638 | DIt = BeginIt; DIt != EndIt; ++DIt) |
| 7639 | Decls.push_back(GetDecl(getGlobalDeclID(*DInfo.Mod, *DIt))); |
| 7640 | } |
| 7641 | |
| 7642 | bool |
| 7643 | ASTReader::FindExternalVisibleDeclsByName(const DeclContext *DC, |
| 7644 | DeclarationName Name) { |
| 7645 | assert(DC->hasExternalVisibleStorage() && DC == DC->getPrimaryContext() && |
| 7646 | "DeclContext has no visible decls in storage"); |
| 7647 | if (!Name) |
| 7648 | return false; |
| 7649 | |
| 7650 | auto It = Lookups.find(DC); |
| 7651 | if (It == Lookups.end()) |
| 7652 | return false; |
| 7653 | |
| 7654 | Deserializing LookupResults(this); |
| 7655 | |
| 7656 | |
| 7657 | SmallVector<NamedDecl *, 64> Decls; |
| 7658 | llvm::SmallPtrSet<NamedDecl *, 8> Found; |
| 7659 | for (DeclID ID : It->second.Table.find(Name)) { |
| 7660 | NamedDecl *ND = cast<NamedDecl>(GetDecl(ID)); |
| 7661 | if (ND->getDeclName() == Name && Found.insert(ND).second) |
| 7662 | Decls.push_back(ND); |
| 7663 | } |
| 7664 | |
| 7665 | ++NumVisibleDeclContextsRead; |
| 7666 | SetExternalVisibleDeclsForName(DC, Name, Decls); |
| 7667 | return !Decls.empty(); |
| 7668 | } |
| 7669 | |
| 7670 | void ASTReader::completeVisibleDeclsMap(const DeclContext *DC) { |
| 7671 | if (!DC->hasExternalVisibleStorage()) |
| 7672 | return; |
| 7673 | |
| 7674 | auto It = Lookups.find(DC); |
| 7675 | assert(It != Lookups.end() && |
| 7676 | "have external visible storage but no lookup tables"); |
| 7677 | |
| 7678 | DeclsMap Decls; |
| 7679 | |
| 7680 | for (DeclID ID : It->second.Table.findAll()) { |
| 7681 | NamedDecl *ND = cast<NamedDecl>(GetDecl(ID)); |
| 7682 | Decls[ND->getDeclName()].push_back(ND); |
| 7683 | } |
| 7684 | |
| 7685 | ++NumVisibleDeclContextsRead; |
| 7686 | |
| 7687 | for (DeclsMap::iterator I = Decls.begin(), E = Decls.end(); I != E; ++I) { |
| 7688 | SetExternalVisibleDeclsForName(DC, I->first, I->second); |
| 7689 | } |
| 7690 | const_cast<DeclContext *>(DC)->setHasExternalVisibleStorage(false); |
| 7691 | } |
| 7692 | |
| 7693 | const serialization::reader::DeclContextLookupTable * |
| 7694 | ASTReader::getLoadedLookupTables(DeclContext *Primary) const { |
| 7695 | auto I = Lookups.find(Primary); |
| 7696 | return I == Lookups.end() ? nullptr : &I->second; |
| 7697 | } |
| 7698 | |
| 7699 | |
| 7700 | |
| 7701 | |
| 7702 | |
| 7703 | static void PassObjCImplDeclToConsumer(ObjCImplDecl *ImplD, |
| 7704 | ASTConsumer *Consumer) { |
| 7705 | assert(ImplD && Consumer); |
| 7706 | |
| 7707 | for (auto *I : ImplD->methods()) |
| 7708 | Consumer->HandleInterestingDecl(DeclGroupRef(I)); |
| 7709 | |
| 7710 | Consumer->HandleInterestingDecl(DeclGroupRef(ImplD)); |
| 7711 | } |
| 7712 | |
| 7713 | void ASTReader::PassInterestingDeclToConsumer(Decl *D) { |
| 7714 | if (ObjCImplDecl *ImplD = dyn_cast<ObjCImplDecl>(D)) |
| 7715 | PassObjCImplDeclToConsumer(ImplD, Consumer); |
| 7716 | else |
| 7717 | Consumer->HandleInterestingDecl(DeclGroupRef(D)); |
| 7718 | } |
| 7719 | |
| 7720 | void ASTReader::StartTranslationUnit(ASTConsumer *Consumer) { |
| 7721 | this->Consumer = Consumer; |
| 7722 | |
| 7723 | if (Consumer) |
| 7724 | PassInterestingDeclsToConsumer(); |
| 7725 | |
| 7726 | if (DeserializationListener) |
| 7727 | DeserializationListener->ReaderInitialized(this); |
| 7728 | } |
| 7729 | |
| 7730 | void ASTReader::PrintStats() { |
| 7731 | std::fprintf(stderr, "*** AST File Statistics:\n"); |
| 7732 | |
| 7733 | unsigned NumTypesLoaded |
| 7734 | = TypesLoaded.size() - std::count(TypesLoaded.begin(), TypesLoaded.end(), |
| 7735 | QualType()); |
| 7736 | unsigned NumDeclsLoaded |
| 7737 | = DeclsLoaded.size() - std::count(DeclsLoaded.begin(), DeclsLoaded.end(), |
| 7738 | (Decl *)nullptr); |
| 7739 | unsigned NumIdentifiersLoaded |
| 7740 | = IdentifiersLoaded.size() - std::count(IdentifiersLoaded.begin(), |
| 7741 | IdentifiersLoaded.end(), |
| 7742 | (IdentifierInfo *)nullptr); |
| 7743 | unsigned NumMacrosLoaded |
| 7744 | = MacrosLoaded.size() - std::count(MacrosLoaded.begin(), |
| 7745 | MacrosLoaded.end(), |
| 7746 | (MacroInfo *)nullptr); |
| 7747 | unsigned NumSelectorsLoaded |
| 7748 | = SelectorsLoaded.size() - std::count(SelectorsLoaded.begin(), |
| 7749 | SelectorsLoaded.end(), |
| 7750 | Selector()); |
| 7751 | |
| 7752 | if (unsigned TotalNumSLocEntries = getTotalNumSLocs()) |
| 7753 | std::fprintf(stderr, " %u/%u source location entries read (%f%%)\n", |
| 7754 | NumSLocEntriesRead, TotalNumSLocEntries, |
| 7755 | ((float)NumSLocEntriesRead/TotalNumSLocEntries * 100)); |
| 7756 | if (!TypesLoaded.empty()) |
| 7757 | std::fprintf(stderr, " %u/%u types read (%f%%)\n", |
| 7758 | NumTypesLoaded, (unsigned)TypesLoaded.size(), |
| 7759 | ((float)NumTypesLoaded/TypesLoaded.size() * 100)); |
| 7760 | if (!DeclsLoaded.empty()) |
| 7761 | std::fprintf(stderr, " %u/%u declarations read (%f%%)\n", |
| 7762 | NumDeclsLoaded, (unsigned)DeclsLoaded.size(), |
| 7763 | ((float)NumDeclsLoaded/DeclsLoaded.size() * 100)); |
| 7764 | if (!IdentifiersLoaded.empty()) |
| 7765 | std::fprintf(stderr, " %u/%u identifiers read (%f%%)\n", |
| 7766 | NumIdentifiersLoaded, (unsigned)IdentifiersLoaded.size(), |
| 7767 | ((float)NumIdentifiersLoaded/IdentifiersLoaded.size() * 100)); |
| 7768 | if (!MacrosLoaded.empty()) |
| 7769 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 7770 | NumMacrosLoaded, (unsigned)MacrosLoaded.size(), |
| 7771 | ((float)NumMacrosLoaded/MacrosLoaded.size() * 100)); |
| 7772 | if (!SelectorsLoaded.empty()) |
| 7773 | std::fprintf(stderr, " %u/%u selectors read (%f%%)\n", |
| 7774 | NumSelectorsLoaded, (unsigned)SelectorsLoaded.size(), |
| 7775 | ((float)NumSelectorsLoaded/SelectorsLoaded.size() * 100)); |
| 7776 | if (TotalNumStatements) |
| 7777 | std::fprintf(stderr, " %u/%u statements read (%f%%)\n", |
| 7778 | NumStatementsRead, TotalNumStatements, |
| 7779 | ((float)NumStatementsRead/TotalNumStatements * 100)); |
| 7780 | if (TotalNumMacros) |
| 7781 | std::fprintf(stderr, " %u/%u macros read (%f%%)\n", |
| 7782 | NumMacrosRead, TotalNumMacros, |
| 7783 | ((float)NumMacrosRead/TotalNumMacros * 100)); |
| 7784 | if (TotalLexicalDeclContexts) |
| 7785 | std::fprintf(stderr, " %u/%u lexical declcontexts read (%f%%)\n", |
| 7786 | NumLexicalDeclContextsRead, TotalLexicalDeclContexts, |
| 7787 | ((float)NumLexicalDeclContextsRead/TotalLexicalDeclContexts |
| 7788 | * 100)); |
| 7789 | if (TotalVisibleDeclContexts) |
| 7790 | std::fprintf(stderr, " %u/%u visible declcontexts read (%f%%)\n", |
| 7791 | NumVisibleDeclContextsRead, TotalVisibleDeclContexts, |
| 7792 | ((float)NumVisibleDeclContextsRead/TotalVisibleDeclContexts |
| 7793 | * 100)); |
| 7794 | if (TotalNumMethodPoolEntries) |
| 7795 | std::fprintf(stderr, " %u/%u method pool entries read (%f%%)\n", |
| 7796 | NumMethodPoolEntriesRead, TotalNumMethodPoolEntries, |
| 7797 | ((float)NumMethodPoolEntriesRead/TotalNumMethodPoolEntries |
| 7798 | * 100)); |
| 7799 | if (NumMethodPoolLookups) |
| 7800 | std::fprintf(stderr, " %u/%u method pool lookups succeeded (%f%%)\n", |
| 7801 | NumMethodPoolHits, NumMethodPoolLookups, |
| 7802 | ((float)NumMethodPoolHits/NumMethodPoolLookups * 100.0)); |
| 7803 | if (NumMethodPoolTableLookups) |
| 7804 | std::fprintf(stderr, " %u/%u method pool table lookups succeeded (%f%%)\n", |
| 7805 | NumMethodPoolTableHits, NumMethodPoolTableLookups, |
| 7806 | ((float)NumMethodPoolTableHits/NumMethodPoolTableLookups |
| 7807 | * 100.0)); |
| 7808 | if (NumIdentifierLookupHits) |
| 7809 | std::fprintf(stderr, |
| 7810 | " %u / %u identifier table lookups succeeded (%f%%)\n", |
| 7811 | NumIdentifierLookupHits, NumIdentifierLookups, |
| 7812 | (double)NumIdentifierLookupHits*100.0/NumIdentifierLookups); |
| 7813 | |
| 7814 | if (GlobalIndex) { |
| 7815 | std::fprintf(stderr, "\n"); |
| 7816 | GlobalIndex->printStats(); |
| 7817 | } |
| 7818 | |
| 7819 | std::fprintf(stderr, "\n"); |
| 7820 | dump(); |
| 7821 | std::fprintf(stderr, "\n"); |
| 7822 | } |
| 7823 | |
| 7824 | template<typename Key, typename ModuleFile, unsigned InitialCapacity> |
| 7825 | LLVM_DUMP_METHOD static void |
| 7826 | dumpModuleIDMap(StringRef Name, |
| 7827 | const ContinuousRangeMap<Key, ModuleFile *, |
| 7828 | InitialCapacity> &Map) { |
| 7829 | if (Map.begin() == Map.end()) |
| 7830 | return; |
| 7831 | |
| 7832 | using MapType = ContinuousRangeMap<Key, ModuleFile *, InitialCapacity>; |
| 7833 | |
| 7834 | llvm::errs() << Name << ":\n"; |
| 7835 | for (typename MapType::const_iterator I = Map.begin(), IEnd = Map.end(); |
| 7836 | I != IEnd; ++I) { |
| 7837 | llvm::errs() << " " << I->first << " -> " << I->second->FileName |
| 7838 | << "\n"; |
| 7839 | } |
| 7840 | } |
| 7841 | |
| 7842 | LLVM_DUMP_METHOD void ASTReader::dump() { |
| 7843 | llvm::errs() << "*** PCH/ModuleFile Remappings:\n"; |
| 7844 | dumpModuleIDMap("Global bit offset map", GlobalBitOffsetsMap); |
| 7845 | dumpModuleIDMap("Global source location entry map", GlobalSLocEntryMap); |
| 7846 | dumpModuleIDMap("Global type map", GlobalTypeMap); |
| 7847 | dumpModuleIDMap("Global declaration map", GlobalDeclMap); |
| 7848 | dumpModuleIDMap("Global identifier map", GlobalIdentifierMap); |
| 7849 | dumpModuleIDMap("Global macro map", GlobalMacroMap); |
| 7850 | dumpModuleIDMap("Global submodule map", GlobalSubmoduleMap); |
| 7851 | dumpModuleIDMap("Global selector map", GlobalSelectorMap); |
| 7852 | dumpModuleIDMap("Global preprocessed entity map", |
| 7853 | GlobalPreprocessedEntityMap); |
| 7854 | |
| 7855 | llvm::errs() << "\n*** PCH/Modules Loaded:"; |
| 7856 | for (ModuleFile &M : ModuleMgr) |
| 7857 | M.dump(); |
| 7858 | } |
| 7859 | |
| 7860 | |
| 7861 | |
| 7862 | void ASTReader::getMemoryBufferSizes(MemoryBufferSizes &sizes) const { |
| 7863 | for (ModuleFile &I : ModuleMgr) { |
| 7864 | if (llvm::MemoryBuffer *buf = I.Buffer) { |
| 7865 | size_t bytes = buf->getBufferSize(); |
| 7866 | switch (buf->getBufferKind()) { |
| 7867 | case llvm::MemoryBuffer::MemoryBuffer_Malloc: |
| 7868 | sizes.malloc_bytes += bytes; |
| 7869 | break; |
| 7870 | case llvm::MemoryBuffer::MemoryBuffer_MMap: |
| 7871 | sizes.mmap_bytes += bytes; |
| 7872 | break; |
| 7873 | } |
| 7874 | } |
| 7875 | } |
| 7876 | } |
| 7877 | |
| 7878 | void ASTReader::InitializeSema(Sema &S) { |
| 7879 | SemaObj = &S; |
| 7880 | S.addExternalSource(this); |
| 7881 | |
| 7882 | |
| 7883 | |
| 7884 | for (uint64_t ID : PreloadedDeclIDs) { |
| 7885 | NamedDecl *D = cast<NamedDecl>(GetDecl(ID)); |
| 7886 | pushExternalDeclIntoScope(D, D->getDeclName()); |
| 7887 | } |
| 7888 | PreloadedDeclIDs.clear(); |
| 7889 | |
| 7890 | |
| 7891 | if (!FPPragmaOptions.empty()) { |
| 7892 | assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS"); |
| 7893 | FPOptionsOverride NewOverrides = |
| 7894 | FPOptionsOverride::getFromOpaqueInt(FPPragmaOptions[0]); |
| 7895 | SemaObj->CurFPFeatures = |
| 7896 | NewOverrides.applyOverrides(SemaObj->getLangOpts()); |
| 7897 | } |
| 7898 | |
| 7899 | SemaObj->OpenCLFeatures = OpenCLExtensions; |
| 7900 | |
| 7901 | UpdateSema(); |
| 7902 | } |
| 7903 | |
| 7904 | void ASTReader::UpdateSema() { |
| 7905 | assert(SemaObj && "no Sema to update"); |
| 7906 | |
| 7907 | |
| 7908 | |
| 7909 | if (!SemaDeclRefs.empty()) { |
| 7910 | assert(SemaDeclRefs.size() % 3 == 0); |
| 7911 | for (unsigned I = 0; I != SemaDeclRefs.size(); I += 3) { |
| 7912 | if (!SemaObj->StdNamespace) |
| 7913 | SemaObj->StdNamespace = SemaDeclRefs[I]; |
| 7914 | if (!SemaObj->StdBadAlloc) |
| 7915 | SemaObj->StdBadAlloc = SemaDeclRefs[I+1]; |
| 7916 | if (!SemaObj->StdAlignValT) |
| 7917 | SemaObj->StdAlignValT = SemaDeclRefs[I+2]; |
| 7918 | } |
| 7919 | SemaDeclRefs.clear(); |
| 7920 | } |
| 7921 | |
| 7922 | |
| 7923 | |
| 7924 | if(OptimizeOffPragmaLocation.isValid()) |
| 7925 | SemaObj->ActOnPragmaOptimize( false, OptimizeOffPragmaLocation); |
| 7926 | if (PragmaMSStructState != -1) |
| 7927 | SemaObj->ActOnPragmaMSStruct((PragmaMSStructKind)PragmaMSStructState); |
| 7928 | if (PointersToMembersPragmaLocation.isValid()) { |
| 7929 | SemaObj->ActOnPragmaMSPointersToMembers( |
| 7930 | (LangOptions::PragmaMSPointersToMembersKind) |
| 7931 | PragmaMSPointersToMembersState, |
| 7932 | PointersToMembersPragmaLocation); |
| 7933 | } |
| 7934 | SemaObj->ForceCUDAHostDeviceDepth = ForceCUDAHostDeviceDepth; |
| 7935 | |
| 7936 | if (PragmaAlignPackCurrentValue) { |
| 7937 | |
| 7938 | |
| 7939 | |
| 7940 | bool DropFirst = false; |
| 7941 | if (!PragmaAlignPackStack.empty() && |
| 7942 | PragmaAlignPackStack.front().Location.isInvalid()) { |
| 7943 | assert(PragmaAlignPackStack.front().Value == |
| 7944 | SemaObj->AlignPackStack.DefaultValue && |
| 7945 | "Expected a default alignment value"); |
| 7946 | SemaObj->AlignPackStack.Stack.emplace_back( |
| 7947 | PragmaAlignPackStack.front().SlotLabel, |
| 7948 | SemaObj->AlignPackStack.CurrentValue, |
| 7949 | SemaObj->AlignPackStack.CurrentPragmaLocation, |
| 7950 | PragmaAlignPackStack.front().PushLocation); |
| 7951 | DropFirst = true; |
| 7952 | } |
| 7953 | for (const auto &Entry : llvm::makeArrayRef(PragmaAlignPackStack) |
| 7954 | .drop_front(DropFirst ? 1 : 0)) { |
| 7955 | SemaObj->AlignPackStack.Stack.emplace_back( |
| 7956 | Entry.SlotLabel, Entry.Value, Entry.Location, Entry.PushLocation); |
| 7957 | } |
| 7958 | if (PragmaAlignPackCurrentLocation.isInvalid()) { |
| 7959 | assert(*PragmaAlignPackCurrentValue == |
| 7960 | SemaObj->AlignPackStack.DefaultValue && |
| 7961 | "Expected a default align and pack value"); |
| 7962 | |
| 7963 | } else { |
| 7964 | SemaObj->AlignPackStack.CurrentValue = *PragmaAlignPackCurrentValue; |
| 7965 | SemaObj->AlignPackStack.CurrentPragmaLocation = |
| 7966 | PragmaAlignPackCurrentLocation; |
| 7967 | } |
| 7968 | } |
| 7969 | if (FpPragmaCurrentValue) { |
| 7970 | |
| 7971 | |
| 7972 | |
| 7973 | bool DropFirst = false; |
| 7974 | if (!FpPragmaStack.empty() && FpPragmaStack.front().Location.isInvalid()) { |
| 7975 | assert(FpPragmaStack.front().Value == |
| 7976 | SemaObj->FpPragmaStack.DefaultValue && |
| 7977 | "Expected a default pragma float_control value"); |
| 7978 | SemaObj->FpPragmaStack.Stack.emplace_back( |
| 7979 | FpPragmaStack.front().SlotLabel, SemaObj->FpPragmaStack.CurrentValue, |
| 7980 | SemaObj->FpPragmaStack.CurrentPragmaLocation, |
| 7981 | FpPragmaStack.front().PushLocation); |
| 7982 | DropFirst = true; |
| 7983 | } |
| 7984 | for (const auto &Entry : |
| 7985 | llvm::makeArrayRef(FpPragmaStack).drop_front(DropFirst ? 1 : 0)) |
| 7986 | SemaObj->FpPragmaStack.Stack.emplace_back( |
| 7987 | Entry.SlotLabel, Entry.Value, Entry.Location, Entry.PushLocation); |
| 7988 | if (FpPragmaCurrentLocation.isInvalid()) { |
| 7989 | assert(*FpPragmaCurrentValue == SemaObj->FpPragmaStack.DefaultValue && |
| 7990 | "Expected a default pragma float_control value"); |
| 7991 | |
| 7992 | } else { |
| 7993 | SemaObj->FpPragmaStack.CurrentValue = *FpPragmaCurrentValue; |
| 7994 | SemaObj->FpPragmaStack.CurrentPragmaLocation = FpPragmaCurrentLocation; |
| 7995 | } |
| 7996 | } |
| 7997 | |
| 7998 | |
| 7999 | for (auto &Import : ImportedModules) { |
| 8000 | if (Import.ImportLoc.isInvalid()) |
| 8001 | continue; |
| 8002 | if (Module *Imported = getSubmodule(Import.ID)) { |
| 8003 | SemaObj->makeModuleVisible(Imported, Import.ImportLoc); |
| 8004 | } |
| 8005 | } |
| 8006 | } |
| 8007 | |
| 8008 | IdentifierInfo *ASTReader::get(StringRef Name) { |
| 8009 | |
| 8010 | Deserializing AnIdentifier(this); |
| 8011 | |
| 8012 | IdentifierLookupVisitor Visitor(Name, 0, |
| 8013 | NumIdentifierLookups, |
| 8014 | NumIdentifierLookupHits); |
| 8015 | |
| 8016 | |
| 8017 | |
| 8018 | |
| 8019 | |
| 8020 | if (PP.getLangOpts().CPlusPlus) { |
| 8021 | for (auto F : ModuleMgr.pch_modules()) |
| 8022 | if (Visitor(*F)) |
| 8023 | break; |
| 8024 | } else { |
| 8025 | |
| 8026 | |
| 8027 | GlobalModuleIndex::HitSet Hits; |
| 8028 | GlobalModuleIndex::HitSet *HitsPtr = nullptr; |
| 8029 | if (!loadGlobalIndex()) { |
| 8030 | if (GlobalIndex->lookupIdentifier(Name, Hits)) { |
| 8031 | HitsPtr = &Hits; |
| 8032 | } |
| 8033 | } |
| 8034 | |
| 8035 | ModuleMgr.visit(Visitor, HitsPtr); |
| 8036 | } |
| 8037 | |
| 8038 | IdentifierInfo *II = Visitor.getIdentifierInfo(); |
| 8039 | markIdentifierUpToDate(II); |
| 8040 | return II; |
| 8041 | } |
| 8042 | |
| 8043 | namespace clang { |
| 8044 | |
| 8045 | |
| 8046 | |
| 8047 | class ASTIdentifierIterator : public IdentifierIterator { |
| 8048 | |
| 8049 | const ASTReader &Reader; |
| 8050 | |
| 8051 | |
| 8052 | |
| 8053 | unsigned Index; |
| 8054 | |
| 8055 | |
| 8056 | |
| 8057 | ASTIdentifierLookupTable::key_iterator Current; |
| 8058 | |
| 8059 | |
| 8060 | |
| 8061 | ASTIdentifierLookupTable::key_iterator End; |
| 8062 | |
| 8063 | |
| 8064 | bool SkipModules; |
| 8065 | |
| 8066 | public: |
| 8067 | explicit ASTIdentifierIterator(const ASTReader &Reader, |
| 8068 | bool SkipModules = false); |
| 8069 | |
| 8070 | StringRef Next() override; |
| 8071 | }; |
| 8072 | |
| 8073 | } |
| 8074 | |
| 8075 | ASTIdentifierIterator::ASTIdentifierIterator(const ASTReader &Reader, |
| 8076 | bool SkipModules) |
| 8077 | : Reader(Reader), Index(Reader.ModuleMgr.size()), SkipModules(SkipModules) { |
| 8078 | } |
| 8079 | |
| 8080 | StringRef ASTIdentifierIterator::Next() { |
| 8081 | while (Current == End) { |
| 8082 | |
| 8083 | if (Index == 0) |
| 8084 | return StringRef(); |
| 8085 | |
| 8086 | --Index; |
| 8087 | ModuleFile &F = Reader.ModuleMgr[Index]; |
| 8088 | if (SkipModules && F.isModule()) |
| 8089 | continue; |
| 8090 | |
| 8091 | ASTIdentifierLookupTable *IdTable = |
| 8092 | (ASTIdentifierLookupTable *)F.IdentifierLookupTable; |
| 8093 | Current = IdTable->key_begin(); |
| 8094 | End = IdTable->key_end(); |
| 8095 | } |
| 8096 | |
| 8097 | |
| 8098 | |
| 8099 | StringRef Result = *Current; |
| 8100 | ++Current; |
| 8101 | return Result; |
| 8102 | } |
| 8103 | |
| 8104 | namespace { |
| 8105 | |
| 8106 | |
| 8107 | class ChainedIdentifierIterator : public IdentifierIterator { |
| 8108 | std::unique_ptr<IdentifierIterator> Current; |
| 8109 | std::unique_ptr<IdentifierIterator> Queued; |
| 8110 | |
| 8111 | public: |
| 8112 | ChainedIdentifierIterator(std::unique_ptr<IdentifierIterator> First, |
| 8113 | std::unique_ptr<IdentifierIterator> Second) |
| 8114 | : Current(std::move(First)), Queued(std::move(Second)) {} |
| 8115 | |
| 8116 | StringRef Next() override { |
| 8117 | if (!Current) |
| 8118 | return StringRef(); |
| 8119 | |
| 8120 | StringRef result = Current->Next(); |
| 8121 | if (!result.empty()) |
| 8122 | return result; |
| 8123 | |
| 8124 | |
| 8125 | Current.reset(); |
| 8126 | std::swap(Current, Queued); |
| 8127 | return Next(); |
| 8128 | } |
| 8129 | }; |
| 8130 | |
| 8131 | } |
| 8132 | |
| 8133 | IdentifierIterator *ASTReader::getIdentifiers() { |
| 8134 | if (!loadGlobalIndex()) { |
| 8135 | std::unique_ptr<IdentifierIterator> ReaderIter( |
| 8136 | new ASTIdentifierIterator(*this, true)); |
| 8137 | std::unique_ptr<IdentifierIterator> ModulesIter( |
| 8138 | GlobalIndex->createIdentifierIterator()); |
| 8139 | return new ChainedIdentifierIterator(std::move(ReaderIter), |
| 8140 | std::move(ModulesIter)); |
| 8141 | } |
| 8142 | |
| 8143 | return new ASTIdentifierIterator(*this); |
| 8144 | } |
| 8145 | |
| 8146 | namespace clang { |
| 8147 | namespace serialization { |
| 8148 | |
| 8149 | class ReadMethodPoolVisitor { |
| 8150 | ASTReader &Reader; |
| 8151 | Selector Sel; |
| 8152 | unsigned PriorGeneration; |
| 8153 | unsigned InstanceBits = 0; |
| 8154 | unsigned FactoryBits = 0; |
| 8155 | bool InstanceHasMoreThanOneDecl = false; |
| 8156 | bool FactoryHasMoreThanOneDecl = false; |
| 8157 | SmallVector<ObjCMethodDecl *, 4> InstanceMethods; |
| 8158 | SmallVector<ObjCMethodDecl *, 4> FactoryMethods; |
| 8159 | |
| 8160 | public: |
| 8161 | ReadMethodPoolVisitor(ASTReader &Reader, Selector Sel, |
| 8162 | unsigned PriorGeneration) |
| 8163 | : Reader(Reader), Sel(Sel), PriorGeneration(PriorGeneration) {} |
| 8164 | |
| 8165 | bool operator()(ModuleFile &M) { |
| 8166 | if (!M.SelectorLookupTable) |
| 8167 | return false; |
| 8168 | |
| 8169 | |
| 8170 | if (M.Generation <= PriorGeneration) |
| 8171 | return true; |
| 8172 | |
| 8173 | ++Reader.NumMethodPoolTableLookups; |
| 8174 | ASTSelectorLookupTable *PoolTable |
| 8175 | = (ASTSelectorLookupTable*)M.SelectorLookupTable; |
| 8176 | ASTSelectorLookupTable::iterator Pos = PoolTable->find(Sel); |
| 8177 | if (Pos == PoolTable->end()) |
| 8178 | return false; |
| 8179 | |
| 8180 | ++Reader.NumMethodPoolTableHits; |
| 8181 | ++Reader.NumSelectorsRead; |
| 8182 | |
| 8183 | |
| 8184 | |
| 8185 | ++Reader.NumMethodPoolEntriesRead; |
| 8186 | ASTSelectorLookupTrait::data_type Data = *Pos; |
| 8187 | if (Reader.DeserializationListener) |
| 8188 | Reader.DeserializationListener->SelectorRead(Data.ID, Sel); |
| 8189 | |
| 8190 | InstanceMethods.append(Data.Instance.begin(), Data.Instance.end()); |
| 8191 | FactoryMethods.append(Data.Factory.begin(), Data.Factory.end()); |
| 8192 | InstanceBits = Data.InstanceBits; |
| 8193 | FactoryBits = Data.FactoryBits; |
| 8194 | InstanceHasMoreThanOneDecl = Data.InstanceHasMoreThanOneDecl; |
| 8195 | FactoryHasMoreThanOneDecl = Data.FactoryHasMoreThanOneDecl; |
| 8196 | return true; |
| 8197 | } |
| 8198 | |
| 8199 | |
| 8200 | ArrayRef<ObjCMethodDecl *> getInstanceMethods() const { |
| 8201 | return InstanceMethods; |
| 8202 | } |
| 8203 | |
| 8204 | |
| 8205 | ArrayRef<ObjCMethodDecl *> getFactoryMethods() const { |
| 8206 | return FactoryMethods; |
| 8207 | } |
| 8208 | |
| 8209 | unsigned getInstanceBits() const { return InstanceBits; } |
| 8210 | unsigned getFactoryBits() const { return FactoryBits; } |
| 8211 | |
| 8212 | bool instanceHasMoreThanOneDecl() const { |
| 8213 | return InstanceHasMoreThanOneDecl; |
| 8214 | } |
| 8215 | |
| 8216 | bool factoryHasMoreThanOneDecl() const { return FactoryHasMoreThanOneDecl; } |
| 8217 | }; |
| 8218 | |
| 8219 | } |
| 8220 | } |
| 8221 | |
| 8222 | |
| 8223 | static void addMethodsToPool(Sema &S, ArrayRef<ObjCMethodDecl *> Methods, |
| 8224 | ObjCMethodList &List) { |
| 8225 | for (unsigned I = 0, N = Methods.size(); I != N; ++I) { |
| 8226 | S.addMethodToGlobalList(&List, Methods[I]); |
| 8227 | } |
| 8228 | } |
| 8229 | |
| 8230 | void ASTReader::ReadMethodPool(Selector Sel) { |
| 8231 | |
| 8232 | unsigned &Generation = SelectorGeneration[Sel]; |
| 8233 | unsigned PriorGeneration = Generation; |
| 8234 | Generation = getGeneration(); |
| 8235 | SelectorOutOfDate[Sel] = false; |
| 8236 | |
| 8237 | |
| 8238 | ++NumMethodPoolLookups; |
| 8239 | ReadMethodPoolVisitor Visitor(*this, Sel, PriorGeneration); |
| 8240 | ModuleMgr.visit(Visitor); |
| 8241 | |
| 8242 | if (Visitor.getInstanceMethods().empty() && |
| 8243 | Visitor.getFactoryMethods().empty()) |
| 8244 | return; |
| 8245 | |
| 8246 | ++NumMethodPoolHits; |
| 8247 | |
| 8248 | if (!getSema()) |
| 8249 | return; |
| 8250 | |
| 8251 | Sema &S = *getSema(); |
| 8252 | Sema::GlobalMethodPool::iterator Pos |
| 8253 | = S.MethodPool.insert(std::make_pair(Sel, Sema::GlobalMethods())).first; |
| 8254 | |
| 8255 | Pos->second.first.setBits(Visitor.getInstanceBits()); |
| 8256 | Pos->second.first.setHasMoreThanOneDecl(Visitor.instanceHasMoreThanOneDecl()); |
| 8257 | Pos->second.second.setBits(Visitor.getFactoryBits()); |
| 8258 | Pos->second.second.setHasMoreThanOneDecl(Visitor.factoryHasMoreThanOneDecl()); |
| 8259 | |
| 8260 | |
| 8261 | |
| 8262 | |
| 8263 | addMethodsToPool(S, Visitor.getInstanceMethods(), Pos->second.first); |
| 8264 | addMethodsToPool(S, Visitor.getFactoryMethods(), Pos->second.second); |
| 8265 | } |
| 8266 | |
| 8267 | void ASTReader::updateOutOfDateSelector(Selector Sel) { |
| 8268 | if (SelectorOutOfDate[Sel]) |
| 8269 | ReadMethodPool(Sel); |
| 8270 | } |
| 8271 | |
| 8272 | void ASTReader::ReadKnownNamespaces( |
| 8273 | SmallVectorImpl<NamespaceDecl *> &Namespaces) { |
| 8274 | Namespaces.clear(); |
| 8275 | |
| 8276 | for (unsigned I = 0, N = KnownNamespaces.size(); I != N; ++I) { |
| 8277 | if (NamespaceDecl *Namespace |
| 8278 | = dyn_cast_or_null<NamespaceDecl>(GetDecl(KnownNamespaces[I]))) |
| 8279 | Namespaces.push_back(Namespace); |
| 8280 | } |
| 8281 | } |
| 8282 | |
| 8283 | void ASTReader::ReadUndefinedButUsed( |
| 8284 | llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) { |
| 8285 | for (unsigned Idx = 0, N = UndefinedButUsed.size(); Idx != N;) { |
| 8286 | NamedDecl *D = cast<NamedDecl>(GetDecl(UndefinedButUsed[Idx++])); |
| 8287 | SourceLocation Loc = |
| 8288 | SourceLocation::getFromRawEncoding(UndefinedButUsed[Idx++]); |
| 8289 | Undefined.insert(std::make_pair(D, Loc)); |
| 8290 | } |
| 8291 | } |
| 8292 | |
| 8293 | void ASTReader::ReadMismatchingDeleteExpressions(llvm::MapVector< |
| 8294 | FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> & |
| 8295 | Exprs) { |
| 8296 | for (unsigned Idx = 0, N = DelayedDeleteExprs.size(); Idx != N;) { |
| 8297 | FieldDecl *FD = cast<FieldDecl>(GetDecl(DelayedDeleteExprs[Idx++])); |
| 8298 | uint64_t Count = DelayedDeleteExprs[Idx++]; |
| 8299 | for (uint64_t C = 0; C < Count; ++C) { |
| 8300 | SourceLocation DeleteLoc = |
| 8301 | SourceLocation::getFromRawEncoding(DelayedDeleteExprs[Idx++]); |
| 8302 | const bool IsArrayForm = DelayedDeleteExprs[Idx++]; |
| 8303 | Exprs[FD].push_back(std::make_pair(DeleteLoc, IsArrayForm)); |
| 8304 | } |
| 8305 | } |
| 8306 | } |
| 8307 | |
| 8308 | void ASTReader::ReadTentativeDefinitions( |
| 8309 | SmallVectorImpl<VarDecl *> &TentativeDefs) { |
| 8310 | for (unsigned I = 0, N = TentativeDefinitions.size(); I != N; ++I) { |
| 8311 | VarDecl *Var = dyn_cast_or_null<VarDecl>(GetDecl(TentativeDefinitions[I])); |
| 8312 | if (Var) |
| 8313 | TentativeDefs.push_back(Var); |
| 8314 | } |
| 8315 | TentativeDefinitions.clear(); |
| 8316 | } |
| 8317 | |
| 8318 | void ASTReader::ReadUnusedFileScopedDecls( |
| 8319 | SmallVectorImpl<const DeclaratorDecl *> &Decls) { |
| 8320 | for (unsigned I = 0, N = UnusedFileScopedDecls.size(); I != N; ++I) { |
| 8321 | DeclaratorDecl *D |
| 8322 | = dyn_cast_or_null<DeclaratorDecl>(GetDecl(UnusedFileScopedDecls[I])); |
| 8323 | if (D) |
| 8324 | Decls.push_back(D); |
| 8325 | } |
| 8326 | UnusedFileScopedDecls.clear(); |
| 8327 | } |
| 8328 | |
| 8329 | void ASTReader::ReadDelegatingConstructors( |
| 8330 | SmallVectorImpl<CXXConstructorDecl *> &Decls) { |
| 8331 | for (unsigned I = 0, N = DelegatingCtorDecls.size(); I != N; ++I) { |
| 8332 | CXXConstructorDecl *D |
| 8333 | = dyn_cast_or_null<CXXConstructorDecl>(GetDecl(DelegatingCtorDecls[I])); |
| 8334 | if (D) |
| 8335 | Decls.push_back(D); |
| 8336 | } |
| 8337 | DelegatingCtorDecls.clear(); |
| 8338 | } |
| 8339 | |
| 8340 | void ASTReader::ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) { |
| 8341 | for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I) { |
| 8342 | TypedefNameDecl *D |
| 8343 | = dyn_cast_or_null<TypedefNameDecl>(GetDecl(ExtVectorDecls[I])); |
| 8344 | if (D) |
| 8345 | Decls.push_back(D); |
| 8346 | } |
| 8347 | ExtVectorDecls.clear(); |
| 8348 | } |
| 8349 | |
| 8350 | void ASTReader::ReadUnusedLocalTypedefNameCandidates( |
| 8351 | llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) { |
| 8352 | for (unsigned I = 0, N = UnusedLocalTypedefNameCandidates.size(); I != N; |
| 8353 | ++I) { |
| 8354 | TypedefNameDecl *D = dyn_cast_or_null<TypedefNameDecl>( |
| 8355 | GetDecl(UnusedLocalTypedefNameCandidates[I])); |
| 8356 | if (D) |
| 8357 | Decls.insert(D); |
| 8358 | } |
| 8359 | UnusedLocalTypedefNameCandidates.clear(); |
| 8360 | } |
| 8361 | |
| 8362 | void ASTReader::ReadDeclsToCheckForDeferredDiags( |
| 8363 | llvm::SmallSetVector<Decl *, 4> &Decls) { |
| 8364 | for (auto I : DeclsToCheckForDeferredDiags) { |
| 8365 | auto *D = dyn_cast_or_null<Decl>(GetDecl(I)); |
| 8366 | if (D) |
| 8367 | Decls.insert(D); |
| 8368 | } |
| 8369 | DeclsToCheckForDeferredDiags.clear(); |
| 8370 | } |
| 8371 | |
| 8372 | void ASTReader::ReadReferencedSelectors( |
| 8373 | SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) { |
| 8374 | if (ReferencedSelectorsData.empty()) |
| 8375 | return; |
| 8376 | |
| 8377 | |
| 8378 | |
| 8379 | unsigned int DataSize = ReferencedSelectorsData.size()-1; |
| 8380 | unsigned I = 0; |
| 8381 | while (I < DataSize) { |
| 8382 | Selector Sel = DecodeSelector(ReferencedSelectorsData[I++]); |
| 8383 | SourceLocation SelLoc |
| 8384 | = SourceLocation::getFromRawEncoding(ReferencedSelectorsData[I++]); |
| 8385 | Sels.push_back(std::make_pair(Sel, SelLoc)); |
| 8386 | } |
| 8387 | ReferencedSelectorsData.clear(); |
| 8388 | } |
| 8389 | |
| 8390 | void ASTReader::ReadWeakUndeclaredIdentifiers( |
| 8391 | SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WeakIDs) { |
| 8392 | if (WeakUndeclaredIdentifiers.empty()) |
| 8393 | return; |
| 8394 | |
| 8395 | for (unsigned I = 0, N = WeakUndeclaredIdentifiers.size(); I < N; ) { |
| 8396 | IdentifierInfo *WeakId |
| 8397 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 8398 | IdentifierInfo *AliasId |
| 8399 | = DecodeIdentifierInfo(WeakUndeclaredIdentifiers[I++]); |
| 8400 | SourceLocation Loc |
| 8401 | = SourceLocation::getFromRawEncoding(WeakUndeclaredIdentifiers[I++]); |
| 8402 | bool Used = WeakUndeclaredIdentifiers[I++]; |
| 8403 | WeakInfo WI(AliasId, Loc); |
| 8404 | WI.setUsed(Used); |
| 8405 | WeakIDs.push_back(std::make_pair(WeakId, WI)); |
| 8406 | } |
| 8407 | WeakUndeclaredIdentifiers.clear(); |
| 8408 | } |
| 8409 | |
| 8410 | void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) { |
| 8411 | for (unsigned Idx = 0, N = VTableUses.size(); Idx < N; ) { |
| 8412 | ExternalVTableUse VT; |
| 8413 | VT.Record = dyn_cast_or_null<CXXRecordDecl>(GetDecl(VTableUses[Idx++])); |
| 8414 | VT.Location = SourceLocation::getFromRawEncoding(VTableUses[Idx++]); |
| 8415 | VT.DefinitionRequired = VTableUses[Idx++]; |
| 8416 | VTables.push_back(VT); |
| 8417 | } |
| 8418 | |
| 8419 | VTableUses.clear(); |
| 8420 | } |
| 8421 | |
| 8422 | void ASTReader::ReadPendingInstantiations( |
| 8423 | SmallVectorImpl<std::pair<ValueDecl *, SourceLocation>> &Pending) { |
| 8424 | for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) { |
| 8425 | ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++])); |
| 8426 | SourceLocation Loc |
| 8427 | = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]); |
| 8428 | |
| 8429 | Pending.push_back(std::make_pair(D, Loc)); |
| 8430 | } |
| 8431 | PendingInstantiations.clear(); |
| 8432 | } |
| 8433 | |
| 8434 | void ASTReader::ReadLateParsedTemplates( |
| 8435 | llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> |
| 8436 | &LPTMap) { |
| 8437 | for (auto &LPT : LateParsedTemplates) { |
| 8438 | ModuleFile *FMod = LPT.first; |
| 8439 | RecordDataImpl &LateParsed = LPT.second; |
| 8440 | for (unsigned Idx = 0, N = LateParsed.size(); Idx < N; |
| 8441 | ) { |
| 8442 | FunctionDecl *FD = |
| 8443 | cast<FunctionDecl>(GetLocalDecl(*FMod, LateParsed[Idx++])); |
| 8444 | |
| 8445 | auto LT = std::make_unique<LateParsedTemplate>(); |
| 8446 | LT->D = GetLocalDecl(*FMod, LateParsed[Idx++]); |
| 8447 | |
| 8448 | ModuleFile *F = getOwningModuleFile(LT->D); |
| 8449 | assert(F && "No module"); |
| 8450 | |
| 8451 | unsigned TokN = LateParsed[Idx++]; |
| 8452 | LT->Toks.reserve(TokN); |
| 8453 | for (unsigned T = 0; T < TokN; ++T) |
| 8454 | LT->Toks.push_back(ReadToken(*F, LateParsed, Idx)); |
| 8455 | |
| 8456 | LPTMap.insert(std::make_pair(FD, std::move(LT))); |
| 8457 | } |
| 8458 | } |
| 8459 | |
| 8460 | LateParsedTemplates.clear(); |
| 8461 | } |
| 8462 | |
| 8463 | void ASTReader::LoadSelector(Selector Sel) { |
| 8464 | |
| 8465 | ReadMethodPool(Sel); |
| 8466 | } |
| 8467 | |
| 8468 | void ASTReader::SetIdentifierInfo(IdentifierID ID, IdentifierInfo *II) { |
| 8469 | assert(ID && "Non-zero identifier ID required"); |
| 8470 | assert(ID <= IdentifiersLoaded.size() && "identifier ID out of range"); |
| 8471 | IdentifiersLoaded[ID - 1] = II; |
| 8472 | if (DeserializationListener) |
| 8473 | DeserializationListener->IdentifierRead(ID, II); |
| 8474 | } |
| 8475 | |
| 8476 | |
| 8477 | |
| 8478 | |
| 8479 | |
| 8480 | |
| 8481 | |
| 8482 | |
| 8483 | |
| 8484 | |
| 8485 | |
| 8486 | |
| 8487 | |
| 8488 | |
| 8489 | |
| 8490 | |
| 8491 | |
| 8492 | void |
| 8493 | ASTReader::SetGloballyVisibleDecls(IdentifierInfo *II, |
| 8494 | const SmallVectorImpl<uint32_t> &DeclIDs, |
| 8495 | SmallVectorImpl<Decl *> *Decls) { |
| 8496 | if (NumCurrentElementsDeserializing && !Decls) { |
| 8497 | PendingIdentifierInfos[II].append(DeclIDs.begin(), DeclIDs.end()); |
| 8498 | return; |
| 8499 | } |
| 8500 | |
| 8501 | for (unsigned I = 0, N = DeclIDs.size(); I != N; ++I) { |
| 8502 | if (!SemaObj) { |
| 8503 | |
| 8504 | |
| 8505 | |
| 8506 | PreloadedDeclIDs.push_back(DeclIDs[I]); |
| 8507 | continue; |
| 8508 | } |
| 8509 | |
| 8510 | NamedDecl *D = cast<NamedDecl>(GetDecl(DeclIDs[I])); |
| 8511 | |
| 8512 | |
| 8513 | if (Decls) { |
| 8514 | Decls->push_back(D); |
| 8515 | continue; |
| 8516 | } |
| 8517 | |
| 8518 | |
| 8519 | |
| 8520 | |
| 8521 | pushExternalDeclIntoScope(D, II); |
| 8522 | } |
| 8523 | } |
| 8524 | |
| 8525 | IdentifierInfo *ASTReader::DecodeIdentifierInfo(IdentifierID ID) { |
| 8526 | if (ID == 0) |
| 8527 | return nullptr; |
| 8528 | |
| 8529 | if (IdentifiersLoaded.empty()) { |
| 8530 | Error("no identifier table in AST file"); |
| 8531 | return nullptr; |
| 8532 | } |
| 8533 | |
| 8534 | ID -= 1; |
| 8535 | if (!IdentifiersLoaded[ID]) { |
| 8536 | GlobalIdentifierMapType::iterator I = GlobalIdentifierMap.find(ID + 1); |
| 8537 | assert(I != GlobalIdentifierMap.end() && "Corrupted global identifier map"); |
| 8538 | ModuleFile *M = I->second; |
| 8539 | unsigned Index = ID - M->BaseIdentifierID; |
| 8540 | const unsigned char *Data = |
| 8541 | M->IdentifierTableData + M->IdentifierOffsets[Index]; |
| 8542 | |
| 8543 | ASTIdentifierLookupTrait Trait(*this, *M); |
| 8544 | auto KeyDataLen = Trait.ReadKeyDataLength(Data); |
| 8545 | auto Key = Trait.ReadKey(Data, KeyDataLen.first); |
| 8546 | auto &II = PP.getIdentifierTable().get(Key); |
| 8547 | IdentifiersLoaded[ID] = &II; |
| 8548 | markIdentifierFromAST(*this, II); |
| 8549 | if (DeserializationListener) |
| 8550 | DeserializationListener->IdentifierRead(ID + 1, &II); |
| 8551 | } |
| 8552 | |
| 8553 | return IdentifiersLoaded[ID]; |
| 8554 | } |
| 8555 | |
| 8556 | IdentifierInfo *ASTReader::getLocalIdentifier(ModuleFile &M, unsigned LocalID) { |
| 8557 | return DecodeIdentifierInfo(getGlobalIdentifierID(M, LocalID)); |
| 8558 | } |
| 8559 | |
| 8560 | IdentifierID ASTReader::getGlobalIdentifierID(ModuleFile &M, unsigned LocalID) { |
| 8561 | if (LocalID < NUM_PREDEF_IDENT_IDS) |
| 8562 | return LocalID; |
| 8563 | |
| 8564 | if (!M.ModuleOffsetMap.empty()) |
| 8565 | ReadModuleOffsetMap(M); |
| 8566 | |
| 8567 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8568 | = M.IdentifierRemap.find(LocalID - NUM_PREDEF_IDENT_IDS); |
| 8569 | assert(I != M.IdentifierRemap.end() |
| 8570 | && "Invalid index into identifier index remap"); |
| 8571 | |
| 8572 | return LocalID + I->second; |
| 8573 | } |
| 8574 | |
| 8575 | MacroInfo *ASTReader::getMacro(MacroID ID) { |
| 8576 | if (ID == 0) |
| 8577 | return nullptr; |
| 8578 | |
| 8579 | if (MacrosLoaded.empty()) { |
| 8580 | Error("no macro table in AST file"); |
| 8581 | return nullptr; |
| 8582 | } |
| 8583 | |
| 8584 | ID -= NUM_PREDEF_MACRO_IDS; |
| 8585 | if (!MacrosLoaded[ID]) { |
| 8586 | GlobalMacroMapType::iterator I |
| 8587 | = GlobalMacroMap.find(ID + NUM_PREDEF_MACRO_IDS); |
| 8588 | assert(I != GlobalMacroMap.end() && "Corrupted global macro map"); |
| 8589 | ModuleFile *M = I->second; |
| 8590 | unsigned Index = ID - M->BaseMacroID; |
| 8591 | MacrosLoaded[ID] = |
| 8592 | ReadMacroRecord(*M, M->MacroOffsetsBase + M->MacroOffsets[Index]); |
| 8593 | |
| 8594 | if (DeserializationListener) |
| 8595 | DeserializationListener->MacroRead(ID + NUM_PREDEF_MACRO_IDS, |
| 8596 | MacrosLoaded[ID]); |
| 8597 | } |
| 8598 | |
| 8599 | return MacrosLoaded[ID]; |
| 8600 | } |
| 8601 | |
| 8602 | MacroID ASTReader::getGlobalMacroID(ModuleFile &M, unsigned LocalID) { |
| 8603 | if (LocalID < NUM_PREDEF_MACRO_IDS) |
| 8604 | return LocalID; |
| 8605 | |
| 8606 | if (!M.ModuleOffsetMap.empty()) |
| 8607 | ReadModuleOffsetMap(M); |
| 8608 | |
| 8609 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8610 | = M.MacroRemap.find(LocalID - NUM_PREDEF_MACRO_IDS); |
| 8611 | assert(I != M.MacroRemap.end() && "Invalid index into macro index remap"); |
| 8612 | |
| 8613 | return LocalID + I->second; |
| 8614 | } |
| 8615 | |
| 8616 | serialization::SubmoduleID |
| 8617 | ASTReader::getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) { |
| 8618 | if (LocalID < NUM_PREDEF_SUBMODULE_IDS) |
| 8619 | return LocalID; |
| 8620 | |
| 8621 | if (!M.ModuleOffsetMap.empty()) |
| 8622 | ReadModuleOffsetMap(M); |
| 8623 | |
| 8624 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8625 | = M.SubmoduleRemap.find(LocalID - NUM_PREDEF_SUBMODULE_IDS); |
| 8626 | assert(I != M.SubmoduleRemap.end() |
| 8627 | && "Invalid index into submodule index remap"); |
| 8628 | |
| 8629 | return LocalID + I->second; |
| 8630 | } |
| 8631 | |
| 8632 | Module *ASTReader::getSubmodule(SubmoduleID GlobalID) { |
| 8633 | if (GlobalID < NUM_PREDEF_SUBMODULE_IDS) { |
| 8634 | assert(GlobalID == 0 && "Unhandled global submodule ID"); |
| 8635 | return nullptr; |
| 8636 | } |
| 8637 | |
| 8638 | if (GlobalID > SubmodulesLoaded.size()) { |
| 8639 | Error("submodule ID out of range in AST file"); |
| 8640 | return nullptr; |
| 8641 | } |
| 8642 | |
| 8643 | return SubmodulesLoaded[GlobalID - NUM_PREDEF_SUBMODULE_IDS]; |
| 8644 | } |
| 8645 | |
| 8646 | Module *ASTReader::getModule(unsigned ID) { |
| 8647 | return getSubmodule(ID); |
| 8648 | } |
| 8649 | |
| 8650 | ModuleFile *ASTReader::getLocalModuleFile(ModuleFile &F, unsigned ID) { |
| 8651 | if (ID & 1) { |
| 8652 | |
| 8653 | auto I = GlobalSubmoduleMap.find(getGlobalSubmoduleID(F, ID >> 1)); |
| 8654 | return I == GlobalSubmoduleMap.end() ? nullptr : I->second; |
| 8655 | } else { |
| 8656 | |
| 8657 | unsigned IndexFromEnd = ID >> 1; |
| 8658 | assert(IndexFromEnd && "got reference to unknown module file"); |
| 8659 | return getModuleManager().pch_modules().end()[-IndexFromEnd]; |
| 8660 | } |
| 8661 | } |
| 8662 | |
| 8663 | unsigned ASTReader::getModuleFileID(ModuleFile *F) { |
| 8664 | if (!F) |
| 8665 | return 1; |
| 8666 | |
| 8667 | |
| 8668 | |
| 8669 | |
| 8670 | |
| 8671 | if (F->isModule()) |
| 8672 | return ((F->BaseSubmoduleID + NUM_PREDEF_SUBMODULE_IDS) << 1) | 1; |
| 8673 | |
| 8674 | auto PCHModules = getModuleManager().pch_modules(); |
| 8675 | auto I = llvm::find(PCHModules, F); |
| 8676 | assert(I != PCHModules.end() && "emitting reference to unknown file"); |
| 8677 | return (I - PCHModules.end()) << 1; |
| 8678 | } |
| 8679 | |
| 8680 | llvm::Optional<ASTSourceDescriptor> |
| 8681 | ASTReader::getSourceDescriptor(unsigned ID) { |
| 8682 | if (Module *M = getSubmodule(ID)) |
| 8683 | return ASTSourceDescriptor(*M); |
| 8684 | |
| 8685 | |
| 8686 | |
| 8687 | const auto &PCHChain = ModuleMgr.pch_modules(); |
| 8688 | if (std::distance(std::begin(PCHChain), std::end(PCHChain))) { |
| 8689 | ModuleFile &MF = ModuleMgr.getPrimaryModule(); |
| 8690 | StringRef ModuleName = llvm::sys::path::filename(MF.OriginalSourceFileName); |
| 8691 | StringRef FileName = llvm::sys::path::filename(MF.FileName); |
| 8692 | return ASTSourceDescriptor(ModuleName, MF.OriginalDir, FileName, |
| 8693 | MF.Signature); |
| 8694 | } |
| 8695 | return None; |
| 8696 | } |
| 8697 | |
| 8698 | ExternalASTSource::ExtKind ASTReader::hasExternalDefinitions(const Decl *FD) { |
| 8699 | auto I = DefinitionSource.find(FD); |
| 8700 | if (I == DefinitionSource.end()) |
| 8701 | return EK_ReplyHazy; |
| 8702 | return I->second ? EK_Never : EK_Always; |
| 8703 | } |
| 8704 | |
| 8705 | Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) { |
| 8706 | return DecodeSelector(getGlobalSelectorID(M, LocalID)); |
| 8707 | } |
| 8708 | |
| 8709 | Selector ASTReader::DecodeSelector(serialization::SelectorID ID) { |
| 8710 | if (ID == 0) |
| 8711 | return Selector(); |
| 8712 | |
| 8713 | if (ID > SelectorsLoaded.size()) { |
| 8714 | Error("selector ID out of range in AST file"); |
| 8715 | return Selector(); |
| 8716 | } |
| 8717 | |
| 8718 | if (SelectorsLoaded[ID - 1].getAsOpaquePtr() == nullptr) { |
| 8719 | |
| 8720 | GlobalSelectorMapType::iterator I = GlobalSelectorMap.find(ID); |
| 8721 | assert(I != GlobalSelectorMap.end() && "Corrupted global selector map"); |
| 8722 | ModuleFile &M = *I->second; |
| 8723 | ASTSelectorLookupTrait Trait(*this, M); |
| 8724 | unsigned Idx = ID - M.BaseSelectorID - NUM_PREDEF_SELECTOR_IDS; |
| 8725 | SelectorsLoaded[ID - 1] = |
| 8726 | Trait.ReadKey(M.SelectorLookupTableData + M.SelectorOffsets[Idx], 0); |
| 8727 | if (DeserializationListener) |
| 8728 | DeserializationListener->SelectorRead(ID, SelectorsLoaded[ID - 1]); |
| 8729 | } |
| 8730 | |
| 8731 | return SelectorsLoaded[ID - 1]; |
| 8732 | } |
| 8733 | |
| 8734 | Selector ASTReader::GetExternalSelector(serialization::SelectorID ID) { |
| 8735 | return DecodeSelector(ID); |
| 8736 | } |
| 8737 | |
| 8738 | uint32_t ASTReader::GetNumExternalSelectors() { |
| 8739 | |
| 8740 | return getTotalNumSelectors() + 1; |
| 8741 | } |
| 8742 | |
| 8743 | serialization::SelectorID |
| 8744 | ASTReader::getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const { |
| 8745 | if (LocalID < NUM_PREDEF_SELECTOR_IDS) |
| 8746 | return LocalID; |
| 8747 | |
| 8748 | if (!M.ModuleOffsetMap.empty()) |
| 8749 | ReadModuleOffsetMap(M); |
| 8750 | |
| 8751 | ContinuousRangeMap<uint32_t, int, 2>::iterator I |
| 8752 | = M.SelectorRemap.find(LocalID - NUM_PREDEF_SELECTOR_IDS); |
| 8753 | assert(I != M.SelectorRemap.end() |
| 8754 | && "Invalid index into selector index remap"); |
| 8755 | |
| 8756 | return LocalID + I->second; |
| 8757 | } |
| 8758 | |
| 8759 | DeclarationNameLoc |
| 8760 | ASTRecordReader::readDeclarationNameLoc(DeclarationName Name) { |
| 8761 | switch (Name.getNameKind()) { |
| 8762 | case DeclarationName::CXXConstructorName: |
| 8763 | case DeclarationName::CXXDestructorName: |
| 8764 | case DeclarationName::CXXConversionFunctionName: |
| 8765 | return DeclarationNameLoc::makeNamedTypeLoc(readTypeSourceInfo()); |
| 8766 | |
| 8767 | case DeclarationName::CXXOperatorName: |
| 8768 | return DeclarationNameLoc::makeCXXOperatorNameLoc(readSourceRange()); |
| 8769 | |
| 8770 | case DeclarationName::CXXLiteralOperatorName: |
| 8771 | return DeclarationNameLoc::makeCXXLiteralOperatorNameLoc( |
| 8772 | readSourceLocation()); |
| 8773 | |
| 8774 | case DeclarationName::Identifier: |
| 8775 | case DeclarationName::ObjCZeroArgSelector: |
| 8776 | case DeclarationName::ObjCOneArgSelector: |
| 8777 | case DeclarationName::ObjCMultiArgSelector: |
| 8778 | case DeclarationName::CXXUsingDirective: |
| 8779 | case DeclarationName::CXXDeductionGuideName: |
| 8780 | break; |
| 8781 | } |
| 8782 | return DeclarationNameLoc(); |
| 8783 | } |
| 8784 | |
| 8785 | DeclarationNameInfo ASTRecordReader::readDeclarationNameInfo() { |
| 8786 | DeclarationNameInfo NameInfo; |
| 8787 | NameInfo.setName(readDeclarationName()); |
| 8788 | NameInfo.setLoc(readSourceLocation()); |
| 8789 | NameInfo.setInfo(readDeclarationNameLoc(NameInfo.getName())); |
| 8790 | return NameInfo; |
| 8791 | } |
| 8792 | |
| 8793 | void ASTRecordReader::readQualifierInfo(QualifierInfo &Info) { |
| 8794 | Info.QualifierLoc = readNestedNameSpecifierLoc(); |
| 8795 | unsigned NumTPLists = readInt(); |
| 8796 | Info.NumTemplParamLists = NumTPLists; |
| 8797 | if (NumTPLists) { |
| 8798 | Info.TemplParamLists = |
| 8799 | new (getContext()) TemplateParameterList *[NumTPLists]; |
| 8800 | for (unsigned i = 0; i != NumTPLists; ++i) |
| 8801 | Info.TemplParamLists[i] = readTemplateParameterList(); |
| 8802 | } |
| 8803 | } |
| 8804 | |
| 8805 | TemplateParameterList * |
| 8806 | ASTRecordReader::readTemplateParameterList() { |
| 8807 | SourceLocation TemplateLoc = readSourceLocation(); |
| 8808 | SourceLocation LAngleLoc = readSourceLocation(); |
| 8809 | SourceLocation RAngleLoc = readSourceLocation(); |
| 8810 | |
| 8811 | unsigned NumParams = readInt(); |
| 8812 | SmallVector<NamedDecl *, 16> Params; |
| 8813 | Params.reserve(NumParams); |
| 8814 | while (NumParams--) |
| 8815 | Params.push_back(readDeclAs<NamedDecl>()); |
| 8816 | |
| 8817 | bool HasRequiresClause = readBool(); |
| 8818 | Expr *RequiresClause = HasRequiresClause ? readExpr() : nullptr; |
| 8819 | |
| 8820 | TemplateParameterList *TemplateParams = TemplateParameterList::Create( |
| 8821 | getContext(), TemplateLoc, LAngleLoc, Params, RAngleLoc, RequiresClause); |
| 8822 | return TemplateParams; |
| 8823 | } |
| 8824 | |
| 8825 | void ASTRecordReader::readTemplateArgumentList( |
| 8826 | SmallVectorImpl<TemplateArgument> &TemplArgs, |
| 8827 | bool Canonicalize) { |
| 8828 | unsigned NumTemplateArgs = readInt(); |
| 8829 | TemplArgs.reserve(NumTemplateArgs); |
| 8830 | while (NumTemplateArgs--) |
| 8831 | TemplArgs.push_back(readTemplateArgument(Canonicalize)); |
| 8832 | } |
| 8833 | |
| 8834 | |
| 8835 | void ASTRecordReader::readUnresolvedSet(LazyASTUnresolvedSet &Set) { |
| 8836 | unsigned NumDecls = readInt(); |
| 8837 | Set.reserve(getContext(), NumDecls); |
| 8838 | while (NumDecls--) { |
| 8839 | DeclID ID = readDeclID(); |
| 8840 | AccessSpecifier AS = (AccessSpecifier) readInt(); |
| 8841 | Set.addLazyDecl(getContext(), ID, AS); |
| 8842 | } |
| 8843 | } |
| 8844 | |
| 8845 | CXXBaseSpecifier |
| 8846 | ASTRecordReader::readCXXBaseSpecifier() { |
| 8847 | bool isVirtual = readBool(); |
| 8848 | bool isBaseOfClass = readBool(); |
| 8849 | AccessSpecifier AS = static_cast<AccessSpecifier>(readInt()); |
| 8850 | bool inheritConstructors = readBool(); |
| 8851 | TypeSourceInfo *TInfo = readTypeSourceInfo(); |
| 8852 | SourceRange Range = readSourceRange(); |
| 8853 | SourceLocation EllipsisLoc = readSourceLocation(); |
| 8854 | CXXBaseSpecifier Result(Range, isVirtual, isBaseOfClass, AS, TInfo, |
| 8855 | EllipsisLoc); |
| 8856 | Result.setInheritConstructors(inheritConstructors); |
| 8857 | return Result; |
| 8858 | } |
| 8859 | |
| 8860 | CXXCtorInitializer ** |
| 8861 | ASTRecordReader::readCXXCtorInitializers() { |
| 8862 | ASTContext &Context = getContext(); |
| 8863 | unsigned NumInitializers = readInt(); |
| 8864 | assert(NumInitializers && "wrote ctor initializers but have no inits"); |
| 8865 | auto **CtorInitializers = new (Context) CXXCtorInitializer*[NumInitializers]; |
| 8866 | for (unsigned i = 0; i != NumInitializers; ++i) { |
| 8867 | TypeSourceInfo *TInfo = nullptr; |
| 8868 | bool IsBaseVirtual = false; |
| 8869 | FieldDecl *Member = nullptr; |
| 8870 | IndirectFieldDecl *IndirectMember = nullptr; |
| 8871 | |
| 8872 | CtorInitializerType Type = (CtorInitializerType) readInt(); |
| 8873 | switch (Type) { |
| 8874 | case CTOR_INITIALIZER_BASE: |
| 8875 | TInfo = readTypeSourceInfo(); |
| 8876 | IsBaseVirtual = readBool(); |
| 8877 | break; |
| 8878 | |
| 8879 | case CTOR_INITIALIZER_DELEGATING: |
| 8880 | TInfo = readTypeSourceInfo(); |
| 8881 | break; |
| 8882 | |
| 8883 | case CTOR_INITIALIZER_MEMBER: |
| 8884 | Member = readDeclAs<FieldDecl>(); |
| 8885 | break; |
| 8886 | |
| 8887 | case CTOR_INITIALIZER_INDIRECT_MEMBER: |
| 8888 | IndirectMember = readDeclAs<IndirectFieldDecl>(); |
| 8889 | break; |
| 8890 | } |
| 8891 | |
| 8892 | SourceLocation MemberOrEllipsisLoc = readSourceLocation(); |
| 8893 | Expr *Init = readExpr(); |
| 8894 | SourceLocation LParenLoc = readSourceLocation(); |
| 8895 | SourceLocation RParenLoc = readSourceLocation(); |
| 8896 | |
| 8897 | CXXCtorInitializer *BOMInit; |
| 8898 | if (Type == CTOR_INITIALIZER_BASE) |
| 8899 | BOMInit = new (Context) |
| 8900 | CXXCtorInitializer(Context, TInfo, IsBaseVirtual, LParenLoc, Init, |
| 8901 | RParenLoc, MemberOrEllipsisLoc); |
| 8902 | else if (Type == CTOR_INITIALIZER_DELEGATING) |
| 8903 | BOMInit = new (Context) |
| 8904 | CXXCtorInitializer(Context, TInfo, LParenLoc, Init, RParenLoc); |
| 8905 | else if (Member) |
| 8906 | BOMInit = new (Context) |
| 8907 | CXXCtorInitializer(Context, Member, MemberOrEllipsisLoc, LParenLoc, |
| 8908 | Init, RParenLoc); |
| 8909 | else |
| 8910 | BOMInit = new (Context) |
| 8911 | CXXCtorInitializer(Context, IndirectMember, MemberOrEllipsisLoc, |
| 8912 | LParenLoc, Init, RParenLoc); |
| 8913 | |
| 8914 | if (readBool()) { |
| 8915 | unsigned SourceOrder = readInt(); |
| 8916 | BOMInit->setSourceOrder(SourceOrder); |
| 8917 | } |
| 8918 | |
| 8919 | CtorInitializers[i] = BOMInit; |
| 8920 | } |
| 8921 | |
| 8922 | return CtorInitializers; |
| 8923 | } |
| 8924 | |
| 8925 | NestedNameSpecifierLoc |
| 8926 | ASTRecordReader::readNestedNameSpecifierLoc() { |
| 8927 | ASTContext &Context = getContext(); |
| 8928 | unsigned N = readInt(); |
| 8929 | NestedNameSpecifierLocBuilder Builder; |
| 8930 | for (unsigned I = 0; I != N; ++I) { |
| 8931 | auto Kind = readNestedNameSpecifierKind(); |
| 8932 | switch (Kind) { |
| 8933 | case NestedNameSpecifier::Identifier: { |
| 8934 | IdentifierInfo *II = readIdentifier(); |
| 8935 | SourceRange Range = readSourceRange(); |
| 8936 | Builder.Extend(Context, II, Range.getBegin(), Range.getEnd()); |
| 8937 | break; |
| 8938 | } |
| 8939 | |
| 8940 | case NestedNameSpecifier::Namespace: { |
| 8941 | NamespaceDecl *NS = readDeclAs<NamespaceDecl>(); |
| 8942 | SourceRange Range = readSourceRange(); |
| 8943 | Builder.Extend(Context, NS, Range.getBegin(), Range.getEnd()); |
| 8944 | break; |
| 8945 | } |
| 8946 | |
| 8947 | case NestedNameSpecifier::NamespaceAlias: { |
| 8948 | NamespaceAliasDecl *Alias = readDeclAs<NamespaceAliasDecl>(); |
| 8949 | SourceRange Range = readSourceRange(); |
| 8950 | Builder.Extend(Context, Alias, Range.getBegin(), Range.getEnd()); |
| 8951 | break; |
| 8952 | } |
| 8953 | |
| 8954 | case NestedNameSpecifier::TypeSpec: |
| 8955 | case NestedNameSpecifier::TypeSpecWithTemplate: { |
| 8956 | bool Template = readBool(); |
| 8957 | TypeSourceInfo *T = readTypeSourceInfo(); |
| 8958 | if (!T) |
| 8959 | return NestedNameSpecifierLoc(); |
| 8960 | SourceLocation ColonColonLoc = readSourceLocation(); |
| 8961 | |
| 8962 | |
| 8963 | Builder.Extend(Context, |
| 8964 | Template? T->getTypeLoc().getBeginLoc() : SourceLocation(), |
| 8965 | T->getTypeLoc(), ColonColonLoc); |
| 8966 | break; |
| 8967 | } |
| 8968 | |
| 8969 | case NestedNameSpecifier::Global: { |
| 8970 | SourceLocation ColonColonLoc = readSourceLocation(); |
| 8971 | Builder.MakeGlobal(Context, ColonColonLoc); |
| 8972 | break; |
| 8973 | } |
| 8974 | |
| 8975 | case NestedNameSpecifier::Super: { |
| 8976 | CXXRecordDecl *RD = readDeclAs<CXXRecordDecl>(); |
| 8977 | SourceRange Range = readSourceRange(); |
| 8978 | Builder.MakeSuper(Context, RD, Range.getBegin(), Range.getEnd()); |
| 8979 | break; |
| 8980 | } |
| 8981 | } |
| 8982 | } |
| 8983 | |
| 8984 | return Builder.getWithLocInContext(Context); |
| 8985 | } |
| 8986 | |
| 8987 | SourceRange |
| 8988 | ASTReader::ReadSourceRange(ModuleFile &F, const RecordData &Record, |
| 8989 | unsigned &Idx) { |
| 8990 | SourceLocation beg = ReadSourceLocation(F, Record, Idx); |
| 8991 | SourceLocation end = ReadSourceLocation(F, Record, Idx); |
| 8992 | return SourceRange(beg, end); |
| 8993 | } |
| 8994 | |
| 8995 | |
| 8996 | llvm::APFloat ASTRecordReader::readAPFloat(const llvm::fltSemantics &Sem) { |
| 8997 | return llvm::APFloat(Sem, readAPInt()); |
| 8998 | } |
| 8999 | |
| 9000 | |
| 9001 | std::string ASTReader::ReadString(const RecordData &Record, unsigned &Idx) { |
| 9002 | unsigned Len = Record[Idx++]; |
| 9003 | std::string Result(Record.data() + Idx, Record.data() + Idx + Len); |
| 9004 | Idx += Len; |
| 9005 | return Result; |
| 9006 | } |
| 9007 | |
| 9008 | std::string ASTReader::ReadPath(ModuleFile &F, const RecordData &Record, |
| 9009 | unsigned &Idx) { |
| 9010 | std::string Filename = ReadString(Record, Idx); |
| 9011 | ResolveImportedPath(F, Filename); |
| 9012 | return Filename; |
| 9013 | } |
| 9014 | |
| 9015 | std::string ASTReader::ReadPath(StringRef BaseDirectory, |
| 9016 | const RecordData &Record, unsigned &Idx) { |
| 9017 | std::string Filename = ReadString(Record, Idx); |
| 9018 | if (!BaseDirectory.empty()) |
| 9019 | ResolveImportedPath(Filename, BaseDirectory); |
| 9020 | return Filename; |
| 9021 | } |
| 9022 | |
| 9023 | VersionTuple ASTReader::ReadVersionTuple(const RecordData &Record, |
| 9024 | unsigned &Idx) { |
| 9025 | unsigned Major = Record[Idx++]; |
| 9026 | unsigned Minor = Record[Idx++]; |
| 9027 | unsigned Subminor = Record[Idx++]; |
| 9028 | if (Minor == 0) |
| 9029 | return VersionTuple(Major); |
| 9030 | if (Subminor == 0) |
| 9031 | return VersionTuple(Major, Minor - 1); |
| 9032 | return VersionTuple(Major, Minor - 1, Subminor - 1); |
| 9033 | } |
| 9034 | |
| 9035 | CXXTemporary *ASTReader::ReadCXXTemporary(ModuleFile &F, |
| 9036 | const RecordData &Record, |
| 9037 | unsigned &Idx) { |
| 9038 | CXXDestructorDecl *Decl = ReadDeclAs<CXXDestructorDecl>(F, Record, Idx); |
| 9039 | return CXXTemporary::Create(getContext(), Decl); |
| 9040 | } |
| 9041 | |
| 9042 | DiagnosticBuilder ASTReader::Diag(unsigned DiagID) const { |
| 9043 | return Diag(CurrentImportLoc, DiagID); |
| 9044 | } |
| 9045 | |
| 9046 | DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) const { |
| 9047 | return Diags.Report(Loc, DiagID); |
| 9048 | } |
| 9049 | |
| 9050 | |
| 9051 | |
| 9052 | IdentifierTable &ASTReader::getIdentifierTable() { |
| 9053 | return PP.getIdentifierTable(); |
| 9054 | } |
| 9055 | |
| 9056 | |
| 9057 | |
| 9058 | void ASTReader::RecordSwitchCaseID(SwitchCase *SC, unsigned ID) { |
| 9059 | assert((*CurrSwitchCaseStmts)[ID] == nullptr && |
| 9060 | "Already have a SwitchCase with this ID"); |
| 9061 | (*CurrSwitchCaseStmts)[ID] = SC; |
| 9062 | } |
| 9063 | |
| 9064 | |
| 9065 | SwitchCase *ASTReader::getSwitchCaseWithID(unsigned ID) { |
| 9066 | assert((*CurrSwitchCaseStmts)[ID] != nullptr && "No SwitchCase with this ID"); |
| 9067 | return (*CurrSwitchCaseStmts)[ID]; |
| 9068 | } |
| 9069 | |
| 9070 | void ASTReader::ClearSwitchCaseIDs() { |
| 9071 | CurrSwitchCaseStmts->clear(); |
| 9072 | } |
| 9073 | |
| 9074 | void ASTReader::ReadComments() { |
| 9075 | ASTContext &Context = getContext(); |
| 9076 | std::vector<RawComment *> Comments; |
| 9077 | for (SmallVectorImpl<std::pair<BitstreamCursor, |
| 9078 | serialization::ModuleFile *>>::iterator |
| 9079 | I = CommentsCursors.begin(), |
| 9080 | E = CommentsCursors.end(); |
| 9081 | I != E; ++I) { |
| 9082 | Comments.clear(); |
| 9083 | BitstreamCursor &Cursor = I->first; |
| 9084 | serialization::ModuleFile &F = *I->second; |
| 9085 | SavedStreamPosition SavedPosition(Cursor); |
| 9086 | |
| 9087 | RecordData Record; |
| 9088 | while (true) { |
| 9089 | Expected<llvm::BitstreamEntry> MaybeEntry = |
| 9090 | Cursor.advanceSkippingSubblocks( |
| 9091 | BitstreamCursor::AF_DontPopBlockAtEnd); |
| 9092 | if (!MaybeEntry) { |
| 9093 | Error(MaybeEntry.takeError()); |
| 9094 | return; |
| 9095 | } |
| 9096 | llvm::BitstreamEntry Entry = MaybeEntry.get(); |
| 9097 | |
| 9098 | switch (Entry.Kind) { |
| 9099 | case llvm::BitstreamEntry::SubBlock: |
| 9100 | case llvm::BitstreamEntry::Error: |
| 9101 | Error("malformed block record in AST file"); |
| 9102 | return; |
| 9103 | case llvm::BitstreamEntry::EndBlock: |
| 9104 | goto NextCursor; |
| 9105 | case llvm::BitstreamEntry::Record: |
| 9106 | |
| 9107 | break; |
| 9108 | } |
| 9109 | |
| 9110 | |
| 9111 | Record.clear(); |
| 9112 | Expected<unsigned> MaybeComment = Cursor.readRecord(Entry.ID, Record); |
| 9113 | if (!MaybeComment) { |
| 9114 | Error(MaybeComment.takeError()); |
| 9115 | return; |
| 9116 | } |
| 9117 | switch ((CommentRecordTypes)MaybeComment.get()) { |
| 9118 | case COMMENTS_RAW_COMMENT: { |
| 9119 | unsigned Idx = 0; |
| 9120 | SourceRange SR = ReadSourceRange(F, Record, Idx); |
| 9121 | RawComment::CommentKind Kind = |
| 9122 | (RawComment::CommentKind) Record[Idx++]; |
| 9123 | bool IsTrailingComment = Record[Idx++]; |
| 9124 | bool IsAlmostTrailingComment = Record[Idx++]; |
| 9125 | Comments.push_back(new (Context) RawComment( |
| 9126 | SR, Kind, IsTrailingComment, IsAlmostTrailingComment)); |
| 9127 | break; |
| 9128 | } |
| 9129 | } |
| 9130 | } |
| 9131 | NextCursor: |
| 9132 | llvm::DenseMap<FileID, std::map<unsigned, RawComment *>> |
| 9133 | FileToOffsetToComment; |
| 9134 | for (RawComment *C : Comments) { |
| 9135 | SourceLocation CommentLoc = C->getBeginLoc(); |
| 9136 | if (CommentLoc.isValid()) { |
| 9137 | std::pair<FileID, unsigned> Loc = |
| 9138 | SourceMgr.getDecomposedLoc(CommentLoc); |
| 9139 | if (Loc.first.isValid()) |
| 9140 | Context.Comments.OrderedComments[Loc.first].emplace(Loc.second, C); |
| 9141 | } |
| 9142 | } |
| 9143 | } |
| 9144 | } |
| 9145 | |
| 9146 | void ASTReader::visitInputFiles(serialization::ModuleFile &MF, |
| 9147 | bool IncludeSystem, bool Complain, |
| 9148 | llvm::function_ref<void(const serialization::InputFile &IF, |
| 9149 | bool isSystem)> Visitor) { |
| 9150 | unsigned NumUserInputs = MF.NumUserInputFiles; |
| 9151 | unsigned NumInputs = MF.InputFilesLoaded.size(); |
| 9152 | assert(NumUserInputs <= NumInputs); |
| 9153 | unsigned N = IncludeSystem ? NumInputs : NumUserInputs; |
| 9154 | for (unsigned I = 0; I < N; ++I) { |
| 9155 | bool IsSystem = I >= NumUserInputs; |
| 9156 | InputFile IF = getInputFile(MF, I+1, Complain); |
| 9157 | Visitor(IF, IsSystem); |
| 9158 | } |
| 9159 | } |
| 9160 | |
| 9161 | void ASTReader::visitTopLevelModuleMaps( |
| 9162 | serialization::ModuleFile &MF, |
| 9163 | llvm::function_ref<void(const FileEntry *FE)> Visitor) { |
| 9164 | unsigned NumInputs = MF.InputFilesLoaded.size(); |
| 9165 | for (unsigned I = 0; I < NumInputs; ++I) { |
| 9166 | InputFileInfo IFI = readInputFileInfo(MF, I + 1); |
| 9167 | if (IFI.TopLevelModuleMap) |
| 9168 | |
| 9169 | if (auto FE = getInputFile(MF, I + 1).getFile()) |
| 9170 | Visitor(FE); |
| 9171 | } |
| 9172 | } |
| 9173 | |
| 9174 | std::string ASTReader::getOwningModuleNameForDiagnostic(const Decl *D) { |
| 9175 | |
| 9176 | if (Module *M = D->getImportedOwningModule()) |
| 9177 | return M->getFullModuleName(); |
| 9178 | |
| 9179 | |
| 9180 | if (ModuleFile *M = getOwningModuleFile(D)) |
| 9181 | return M->ModuleName; |
| 9182 | |
| 9183 | |
| 9184 | return {}; |
| 9185 | } |
| 9186 | |
| 9187 | void ASTReader::finishPendingActions() { |
| 9188 | while (!PendingIdentifierInfos.empty() || !PendingFunctionTypes.empty() || |
| 9189 | !PendingIncompleteDeclChains.empty() || !PendingDeclChains.empty() || |
| 9190 | !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() || |
| 9191 | !PendingUpdateRecords.empty()) { |
| 9192 | |
| 9193 | |
| 9194 | using TopLevelDeclsMap = |
| 9195 | llvm::DenseMap<IdentifierInfo *, SmallVector<Decl *, 2>>; |
| 9196 | TopLevelDeclsMap TopLevelDecls; |
| 9197 | |
| 9198 | while (!PendingIdentifierInfos.empty()) { |
| 9199 | IdentifierInfo *II = PendingIdentifierInfos.back().first; |
| 9200 | SmallVector<uint32_t, 4> DeclIDs = |
| 9201 | std::move(PendingIdentifierInfos.back().second); |
| 9202 | PendingIdentifierInfos.pop_back(); |
| 9203 | |
| 9204 | SetGloballyVisibleDecls(II, DeclIDs, &TopLevelDecls[II]); |
| 9205 | } |
| 9206 | |
| 9207 | |
| 9208 | |
| 9209 | for (unsigned I = 0; I != PendingFunctionTypes.size(); ++I) { |
| 9210 | auto *FD = PendingFunctionTypes[I].first; |
| 9211 | FD->setType(GetType(PendingFunctionTypes[I].second)); |
| 9212 | |
| 9213 | |
| 9214 | |
| 9215 | auto *DT = FD->getReturnType()->getContainedDeducedType(); |
| 9216 | if (DT && DT->isDeduced()) |
| 9217 | PendingDeducedTypeUpdates.insert( |
| 9218 | {FD->getCanonicalDecl(), FD->getReturnType()}); |
| 9219 | } |
| 9220 | PendingFunctionTypes.clear(); |
| 9221 | |
| 9222 | |
| 9223 | |
| 9224 | for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) { |
| 9225 | markIncompleteDeclChain(PendingIncompleteDeclChains[I]); |
| 9226 | } |
| 9227 | PendingIncompleteDeclChains.clear(); |
| 9228 | |
| 9229 | |
| 9230 | for (unsigned I = 0; I != PendingDeclChains.size(); ++I) |
| 9231 | loadPendingDeclChain(PendingDeclChains[I].first, |
| 9232 | PendingDeclChains[I].second); |
| 9233 | PendingDeclChains.clear(); |
| 9234 | |
| 9235 | |
| 9236 | for (TopLevelDeclsMap::iterator TLD = TopLevelDecls.begin(), |
| 9237 | TLDEnd = TopLevelDecls.end(); TLD != TLDEnd; ++TLD) { |
| 9238 | IdentifierInfo *II = TLD->first; |
| 9239 | for (unsigned I = 0, N = TLD->second.size(); I != N; ++I) { |
| 9240 | pushExternalDeclIntoScope(cast<NamedDecl>(TLD->second[I]), II); |
| 9241 | } |
| 9242 | } |
| 9243 | |
| 9244 | |
| 9245 | for (unsigned I = 0; I != PendingMacroIDs.size(); ++I) { |
| 9246 | IdentifierInfo *II = PendingMacroIDs.begin()[I].first; |
| 9247 | SmallVector<PendingMacroInfo, 2> GlobalIDs; |
| 9248 | GlobalIDs.swap(PendingMacroIDs.begin()[I].second); |
| 9249 | |
| 9250 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
| 9251 | ++IDIdx) { |
| 9252 | const PendingMacroInfo &Info = GlobalIDs[IDIdx]; |
| 9253 | if (!Info.M->isModule()) |
| 9254 | resolvePendingMacro(II, Info); |
| 9255 | } |
| 9256 | |
| 9257 | for (unsigned IDIdx = 0, NumIDs = GlobalIDs.size(); IDIdx != NumIDs; |
| 9258 | ++IDIdx) { |
| 9259 | const PendingMacroInfo &Info = GlobalIDs[IDIdx]; |
| 9260 | if (Info.M->isModule()) |
| 9261 | resolvePendingMacro(II, Info); |
| 9262 | } |
| 9263 | } |
| 9264 | PendingMacroIDs.clear(); |
| 9265 | |
| 9266 | |
| 9267 | |
| 9268 | while (!PendingDeclContextInfos.empty()) { |
| 9269 | PendingDeclContextInfo Info = PendingDeclContextInfos.front(); |
| 9270 | PendingDeclContextInfos.pop_front(); |
| 9271 | DeclContext *SemaDC = cast<DeclContext>(GetDecl(Info.SemaDC)); |
| 9272 | DeclContext *LexicalDC = cast<DeclContext>(GetDecl(Info.LexicalDC)); |
| 9273 | Info.D->setDeclContextsImpl(SemaDC, LexicalDC, getContext()); |
| 9274 | } |
| 9275 | |
| 9276 | |
| 9277 | while (!PendingUpdateRecords.empty()) { |
| 9278 | auto Update = PendingUpdateRecords.pop_back_val(); |
| 9279 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 9280 | loadDeclUpdateRecords(Update); |
| 9281 | } |
| 9282 | } |
| 9283 | |
| 9284 | |
| 9285 | |
| 9286 | assert(PendingFakeDefinitionData.empty() && |
| 9287 | "faked up a class definition but never saw the real one"); |
| 9288 | |
| 9289 | |
| 9290 | |
| 9291 | |
| 9292 | |
| 9293 | for (Decl *D : PendingDefinitions) { |
| 9294 | if (TagDecl *TD = dyn_cast<TagDecl>(D)) { |
| 9295 | if (const TagType *TagT = dyn_cast<TagType>(TD->getTypeForDecl())) { |
| 9296 | |
| 9297 | const_cast<TagType*>(TagT)->decl = TD; |
| 9298 | } |
| 9299 | |
| 9300 | if (auto RD = dyn_cast<CXXRecordDecl>(D)) { |
| 9301 | for (auto *R = getMostRecentExistingDecl(RD); R; |
| 9302 | R = R->getPreviousDecl()) { |
| 9303 | assert((R == D) == |
| 9304 | cast<CXXRecordDecl>(R)->isThisDeclarationADefinition() && |
| 9305 | "declaration thinks it's the definition but it isn't"); |
| 9306 | cast<CXXRecordDecl>(R)->DefinitionData = RD->DefinitionData; |
| 9307 | } |
| 9308 | } |
| 9309 | |
| 9310 | continue; |
| 9311 | } |
| 9312 | |
| 9313 | if (auto ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
| 9314 | |
| 9315 | const_cast<ObjCInterfaceType *>(cast<ObjCInterfaceType>(ID->TypeForDecl)) |
| 9316 | ->Decl = ID; |
| 9317 | |
| 9318 | for (auto *R = getMostRecentExistingDecl(ID); R; R = R->getPreviousDecl()) |
| 9319 | cast<ObjCInterfaceDecl>(R)->Data = ID->Data; |
| 9320 | |
| 9321 | continue; |
| 9322 | } |
| 9323 | |
| 9324 | if (auto PD = dyn_cast<ObjCProtocolDecl>(D)) { |
| 9325 | for (auto *R = getMostRecentExistingDecl(PD); R; R = R->getPreviousDecl()) |
| 9326 | cast<ObjCProtocolDecl>(R)->Data = PD->Data; |
| 9327 | |
| 9328 | continue; |
| 9329 | } |
| 9330 | |
| 9331 | auto RTD = cast<RedeclarableTemplateDecl>(D)->getCanonicalDecl(); |
| 9332 | for (auto *R = getMostRecentExistingDecl(RTD); R; R = R->getPreviousDecl()) |
| 9333 | cast<RedeclarableTemplateDecl>(R)->Common = RTD->Common; |
| 9334 | } |
| 9335 | PendingDefinitions.clear(); |
| 9336 | |
| 9337 | |
| 9338 | |
| 9339 | |
| 9340 | |
| 9341 | for (PendingBodiesMap::iterator PB = PendingBodies.begin(), |
| 9342 | PBEnd = PendingBodies.end(); |
| 9343 | PB != PBEnd; ++PB) { |
| 9344 | if (FunctionDecl *FD = dyn_cast<FunctionDecl>(PB->first)) { |
| 9345 | |
| 9346 | |
| 9347 | |
| 9348 | |
| 9349 | |
| 9350 | |
| 9351 | |
| 9352 | |
| 9353 | |
| 9354 | if (auto *RD = dyn_cast<CXXRecordDecl>(FD->getLexicalParent())) |
| 9355 | if (RD->isDependentContext() && !RD->isThisDeclarationADefinition()) |
| 9356 | continue; |
| 9357 | |
| 9358 | |
| 9359 | |
| 9360 | const FunctionDecl *Defn = nullptr; |
| 9361 | if (!getContext().getLangOpts().Modules || !FD->hasBody(Defn)) { |
| 9362 | FD->setLazyBody(PB->second); |
| 9363 | } else { |
| 9364 | auto *NonConstDefn = const_cast<FunctionDecl*>(Defn); |
| 9365 | mergeDefinitionVisibility(NonConstDefn, FD); |
| 9366 | |
| 9367 | if (!FD->isLateTemplateParsed() && |
| 9368 | !NonConstDefn->isLateTemplateParsed() && |
| 9369 | FD->getODRHash() != NonConstDefn->getODRHash()) { |
| 9370 | if (!isa<CXXMethodDecl>(FD)) { |
| 9371 | PendingFunctionOdrMergeFailures[FD].push_back(NonConstDefn); |
| 9372 | } else if (FD->getLexicalParent()->isFileContext() && |
| 9373 | NonConstDefn->getLexicalParent()->isFileContext()) { |
| 9374 | |
| 9375 | |
| 9376 | |
| 9377 | PendingFunctionOdrMergeFailures[FD].push_back(NonConstDefn); |
| 9378 | } |
| 9379 | } |
| 9380 | } |
| 9381 | continue; |
| 9382 | } |
| 9383 | |
| 9384 | ObjCMethodDecl *MD = cast<ObjCMethodDecl>(PB->first); |
| 9385 | if (!getContext().getLangOpts().Modules || !MD->hasBody()) |
| 9386 | MD->setLazyBody(PB->second); |
| 9387 | } |
| 9388 | PendingBodies.clear(); |
| 9389 | |
| 9390 | |
| 9391 | for (auto *ND : PendingMergedDefinitionsToDeduplicate) |
| 9392 | getContext().deduplicateMergedDefinitonsFor(ND); |
| 9393 | PendingMergedDefinitionsToDeduplicate.clear(); |
| 9394 | } |
| 9395 | |
| 9396 | void ASTReader::diagnoseOdrViolations() { |
| 9397 | if (PendingOdrMergeFailures.empty() && PendingOdrMergeChecks.empty() && |
| 9398 | PendingFunctionOdrMergeFailures.empty() && |
| 9399 | PendingEnumOdrMergeFailures.empty()) |
| 9400 | return; |
| 9401 | |
| 9402 | |
| 9403 | |
| 9404 | |
| 9405 | |
| 9406 | auto OdrMergeFailures = std::move(PendingOdrMergeFailures); |
| 9407 | PendingOdrMergeFailures.clear(); |
| 9408 | for (auto &Merge : OdrMergeFailures) { |
| 9409 | Merge.first->buildLookup(); |
| 9410 | Merge.first->decls_begin(); |
| 9411 | Merge.first->bases_begin(); |
| 9412 | Merge.first->vbases_begin(); |
| 9413 | for (auto &RecordPair : Merge.second) { |
| 9414 | auto *RD = RecordPair.first; |
| 9415 | RD->decls_begin(); |
| 9416 | RD->bases_begin(); |
| 9417 | RD->vbases_begin(); |
| 9418 | } |
| 9419 | } |
| 9420 | |
| 9421 | |
| 9422 | auto FunctionOdrMergeFailures = std::move(PendingFunctionOdrMergeFailures); |
| 9423 | PendingFunctionOdrMergeFailures.clear(); |
| 9424 | for (auto &Merge : FunctionOdrMergeFailures) { |
| 9425 | Merge.first->buildLookup(); |
| 9426 | Merge.first->decls_begin(); |
| 9427 | Merge.first->getBody(); |
| 9428 | for (auto &FD : Merge.second) { |
| 9429 | FD->buildLookup(); |
| 9430 | FD->decls_begin(); |
| 9431 | FD->getBody(); |
| 9432 | } |
| 9433 | } |
| 9434 | |
| 9435 | |
| 9436 | auto EnumOdrMergeFailures = std::move(PendingEnumOdrMergeFailures); |
| 9437 | PendingEnumOdrMergeFailures.clear(); |
| 9438 | for (auto &Merge : EnumOdrMergeFailures) { |
| 9439 | Merge.first->decls_begin(); |
| 9440 | for (auto &Enum : Merge.second) { |
| 9441 | Enum->decls_begin(); |
| 9442 | } |
| 9443 | } |
| 9444 | |
| 9445 | |
| 9446 | |
| 9447 | |
| 9448 | |
| 9449 | |
| 9450 | |
| 9451 | while (!PendingOdrMergeChecks.empty()) { |
| 9452 | NamedDecl *D = PendingOdrMergeChecks.pop_back_val(); |
| 9453 | |
| 9454 | |
| 9455 | |
| 9456 | |
| 9457 | |
| 9458 | if (D->isImplicit()) |
| 9459 | continue; |
| 9460 | |
| 9461 | DeclContext *CanonDef = D->getDeclContext(); |
| 9462 | |
| 9463 | bool Found = false; |
| 9464 | const Decl *DCanon = D->getCanonicalDecl(); |
| 9465 | |
| 9466 | for (auto RI : D->redecls()) { |
| 9467 | if (RI->getLexicalDeclContext() == CanonDef) { |
| 9468 | Found = true; |
| 9469 | break; |
| 9470 | } |
| 9471 | } |
| 9472 | if (Found) |
| 9473 | continue; |
| 9474 | |
| 9475 | |
| 9476 | |
| 9477 | |
| 9478 | |
| 9479 | |
| 9480 | |
| 9481 | llvm::SmallVector<const NamedDecl*, 4> Candidates; |
| 9482 | for (auto *CanonMember : CanonDef->decls()) { |
| 9483 | if (CanonMember->getCanonicalDecl() == DCanon) { |
| 9484 | |
| 9485 | |
| 9486 | |
| 9487 | |
| 9488 | |
| 9489 | Found = true; |
| 9490 | break; |
| 9491 | } |
| 9492 | if (auto *ND = dyn_cast<NamedDecl>(CanonMember)) |
| 9493 | if (ND->getDeclName() == D->getDeclName()) |
| 9494 | Candidates.push_back(ND); |
| 9495 | } |
| 9496 | |
| 9497 | if (!Found) { |
| 9498 | |
| 9499 | |
| 9500 | if (!isa<TagDecl>(D)) |
| 9501 | D->setInvalidDecl(); |
| 9502 | |
| 9503 | |
| 9504 | |
| 9505 | Deserializing RecursionGuard(this); |
| 9506 | |
| 9507 | std::string CanonDefModule = |
| 9508 | getOwningModuleNameForDiagnostic(cast<Decl>(CanonDef)); |
| 9509 | Diag(D->getLocation(), diag::err_module_odr_violation_missing_decl) |
| 9510 | << D << getOwningModuleNameForDiagnostic(D) |
| 9511 | << CanonDef << CanonDefModule.empty() << CanonDefModule; |
| 9512 | |
| 9513 | if (Candidates.empty()) |
| 9514 | Diag(cast<Decl>(CanonDef)->getLocation(), |
| 9515 | diag::note_module_odr_violation_no_possible_decls) << D; |
| 9516 | else { |
| 9517 | for (unsigned I = 0, N = Candidates.size(); I != N; ++I) |
| 9518 | Diag(Candidates[I]->getLocation(), |
| 9519 | diag::note_module_odr_violation_possible_decl) |
| 9520 | << Candidates[I]; |
| 9521 | } |
| 9522 | |
| 9523 | DiagnosedOdrMergeFailures.insert(CanonDef); |
| 9524 | } |
| 9525 | } |
| 9526 | |
| 9527 | if (OdrMergeFailures.empty() && FunctionOdrMergeFailures.empty() && |
| 9528 | EnumOdrMergeFailures.empty()) |
| 9529 | return; |
| 9530 | |
| 9531 | |
| 9532 | |
| 9533 | Deserializing RecursionGuard(this); |
| 9534 | |
| 9535 | |
| 9536 | ODRHash Hash; |
| 9537 | auto ComputeQualTypeODRHash = [&Hash](QualType Ty) { |
| 9538 | Hash.clear(); |
| 9539 | Hash.AddQualType(Ty); |
| 9540 | return Hash.CalculateHash(); |
| 9541 | }; |
| 9542 | |
| 9543 | auto ComputeODRHash = [&Hash](const Stmt *S) { |
| 9544 | assert(S); |
| 9545 | Hash.clear(); |
| 9546 | Hash.AddStmt(S); |
| 9547 | return Hash.CalculateHash(); |
| 9548 | }; |
| 9549 | |
| 9550 | auto ComputeSubDeclODRHash = [&Hash](const Decl *D) { |
| 9551 | assert(D); |
| 9552 | Hash.clear(); |
| 9553 | Hash.AddSubDecl(D); |
| 9554 | return Hash.CalculateHash(); |
| 9555 | }; |
| 9556 | |
| 9557 | auto ComputeTemplateArgumentODRHash = [&Hash](const TemplateArgument &TA) { |
| 9558 | Hash.clear(); |
| 9559 | Hash.AddTemplateArgument(TA); |
| 9560 | return Hash.CalculateHash(); |
| 9561 | }; |
| 9562 | |
| 9563 | auto ComputeTemplateParameterListODRHash = |
| 9564 | [&Hash](const TemplateParameterList *TPL) { |
| 9565 | assert(TPL); |
| 9566 | Hash.clear(); |
| 9567 | Hash.AddTemplateParameterList(TPL); |
| 9568 | return Hash.CalculateHash(); |
| 9569 | }; |
| 9570 | |
| 9571 | |
| 9572 | |
| 9573 | |
| 9574 | enum ODRMismatchDecl { |
| 9575 | EndOfClass, |
| 9576 | PublicSpecifer, |
| 9577 | PrivateSpecifer, |
| 9578 | ProtectedSpecifer, |
| 9579 | StaticAssert, |
| 9580 | Field, |
| 9581 | CXXMethod, |
| 9582 | TypeAlias, |
| 9583 | TypeDef, |
| 9584 | Var, |
| 9585 | Friend, |
| 9586 | FunctionTemplate, |
| 9587 | Other |
| 9588 | }; |
| 9589 | |
| 9590 | |
| 9591 | |
| 9592 | enum ODRMismatchDeclDifference { |
| 9593 | StaticAssertCondition, |
| 9594 | StaticAssertMessage, |
| 9595 | StaticAssertOnlyMessage, |
| 9596 | FieldName, |
| 9597 | FieldTypeName, |
| 9598 | FieldSingleBitField, |
| 9599 | FieldDifferentWidthBitField, |
| 9600 | FieldSingleMutable, |
| 9601 | FieldSingleInitializer, |
| 9602 | FieldDifferentInitializers, |
| 9603 | MethodName, |
| 9604 | MethodDeleted, |
| 9605 | MethodDefaulted, |
| 9606 | MethodVirtual, |
| 9607 | MethodStatic, |
| 9608 | MethodVolatile, |
| 9609 | MethodConst, |
| 9610 | MethodInline, |
| 9611 | MethodNumberParameters, |
| 9612 | MethodParameterType, |
| 9613 | MethodParameterName, |
| 9614 | MethodParameterSingleDefaultArgument, |
| 9615 | MethodParameterDifferentDefaultArgument, |
| 9616 | MethodNoTemplateArguments, |
| 9617 | MethodDifferentNumberTemplateArguments, |
| 9618 | MethodDifferentTemplateArgument, |
| 9619 | MethodSingleBody, |
| 9620 | MethodDifferentBody, |
| 9621 | TypedefName, |
| 9622 | TypedefType, |
| 9623 | VarName, |
| 9624 | VarType, |
| 9625 | VarSingleInitializer, |
| 9626 | VarDifferentInitializer, |
| 9627 | VarConstexpr, |
| 9628 | FriendTypeFunction, |
| 9629 | FriendType, |
| 9630 | FriendFunction, |
| 9631 | FunctionTemplateDifferentNumberParameters, |
| 9632 | FunctionTemplateParameterDifferentKind, |
| 9633 | FunctionTemplateParameterName, |
| 9634 | FunctionTemplateParameterSingleDefaultArgument, |
| 9635 | FunctionTemplateParameterDifferentDefaultArgument, |
| 9636 | FunctionTemplateParameterDifferentType, |
| 9637 | FunctionTemplatePackParameter, |
| 9638 | }; |
| 9639 | |
| 9640 | |
| 9641 | |
| 9642 | |
| 9643 | auto ODRDiagDeclError = [this](NamedDecl *FirstRecord, StringRef FirstModule, |
| 9644 | SourceLocation Loc, SourceRange Range, |
| 9645 | ODRMismatchDeclDifference DiffType) { |
| 9646 | return Diag(Loc, diag::err_module_odr_violation_mismatch_decl_diff) |
| 9647 | << FirstRecord << FirstModule.empty() << FirstModule << Range |
| 9648 | << DiffType; |
| 9649 | }; |
| 9650 | auto ODRDiagDeclNote = [this](StringRef SecondModule, SourceLocation Loc, |
| 9651 | SourceRange Range, ODRMismatchDeclDifference DiffType) { |
| 9652 | return Diag(Loc, diag::note_module_odr_violation_mismatch_decl_diff) |
| 9653 | << SecondModule << Range << DiffType; |
| 9654 | }; |
| 9655 | |
| 9656 | auto ODRDiagField = [this, &ODRDiagDeclError, &ODRDiagDeclNote, |
| 9657 | &ComputeQualTypeODRHash, &ComputeODRHash]( |
| 9658 | NamedDecl *FirstRecord, StringRef FirstModule, |
| 9659 | StringRef SecondModule, FieldDecl *FirstField, |
| 9660 | FieldDecl *SecondField) { |
| 9661 | IdentifierInfo *FirstII = FirstField->getIdentifier(); |
| 9662 | IdentifierInfo *SecondII = SecondField->getIdentifier(); |
| 9663 | if (FirstII->getName() != SecondII->getName()) { |
| 9664 | ODRDiagDeclError(FirstRecord, FirstModule, FirstField->getLocation(), |
| 9665 | FirstField->getSourceRange(), FieldName) |
| 9666 | << FirstII; |
| 9667 | ODRDiagDeclNote(SecondModule, SecondField->getLocation(), |
| 9668 | SecondField->getSourceRange(), FieldName) |
| 9669 | << SecondII; |
| 9670 | |
| 9671 | return true; |
| 9672 | } |
| 9673 | |
| 9674 | assert(getContext().hasSameType(FirstField->getType(), |
| 9675 | SecondField->getType())); |
| 9676 | |
| 9677 | QualType FirstType = FirstField->getType(); |
| 9678 | QualType SecondType = SecondField->getType(); |
| 9679 | if (ComputeQualTypeODRHash(FirstType) != |
| 9680 | ComputeQualTypeODRHash(SecondType)) { |
| 9681 | ODRDiagDeclError(FirstRecord, FirstModule, FirstField->getLocation(), |
| 9682 | FirstField->getSourceRange(), FieldTypeName) |
| 9683 | << FirstII << FirstType; |
| 9684 | ODRDiagDeclNote(SecondModule, SecondField->getLocation(), |
| 9685 | SecondField->getSourceRange(), FieldTypeName) |
| 9686 | << SecondII << SecondType; |
| 9687 | |
| 9688 | return true; |
| 9689 | } |
| 9690 | |
| 9691 | const bool IsFirstBitField = FirstField->isBitField(); |
| 9692 | const bool IsSecondBitField = SecondField->isBitField(); |
| 9693 | if (IsFirstBitField != IsSecondBitField) { |
| 9694 | ODRDiagDeclError(FirstRecord, FirstModule, FirstField->getLocation(), |
| 9695 | FirstField->getSourceRange(), FieldSingleBitField) |
| 9696 | << FirstII << IsFirstBitField; |
| 9697 | ODRDiagDeclNote(SecondModule, SecondField->getLocation(), |
| 9698 | SecondField->getSourceRange(), FieldSingleBitField) |
| 9699 | << SecondII << IsSecondBitField; |
| 9700 | return true; |
| 9701 | } |
| 9702 | |
| 9703 | if (IsFirstBitField && IsSecondBitField) { |
| 9704 | unsigned FirstBitWidthHash = |
| 9705 | ComputeODRHash(FirstField->getBitWidth()); |
| 9706 | unsigned SecondBitWidthHash = |
| 9707 | ComputeODRHash(SecondField->getBitWidth()); |
| 9708 | if (FirstBitWidthHash != SecondBitWidthHash) { |
| 9709 | ODRDiagDeclError(FirstRecord, FirstModule, FirstField->getLocation(), |
| 9710 | FirstField->getSourceRange(), |
| 9711 | FieldDifferentWidthBitField) |
| 9712 | << FirstII << FirstField->getBitWidth()->getSourceRange(); |
| 9713 | ODRDiagDeclNote(SecondModule, SecondField->getLocation(), |
| 9714 | SecondField->getSourceRange(), |
| 9715 | FieldDifferentWidthBitField) |
| 9716 | << SecondII << SecondField->getBitWidth()->getSourceRange(); |
| 9717 | return true; |
| 9718 | } |
| 9719 | } |
| 9720 | |
| 9721 | if (!PP.getLangOpts().CPlusPlus) |
| 9722 | return false; |
| 9723 | |
| 9724 | const bool IsFirstMutable = FirstField->isMutable(); |
| 9725 | const bool IsSecondMutable = SecondField->isMutable(); |
| 9726 | if (IsFirstMutable != IsSecondMutable) { |
| 9727 | ODRDiagDeclError(FirstRecord, FirstModule, FirstField->getLocation(), |
| 9728 | FirstField->getSourceRange(), FieldSingleMutable) |
| 9729 | << FirstII << IsFirstMutable; |
| 9730 | ODRDiagDeclNote(SecondModule, SecondField->getLocation(), |
| 9731 | SecondField->getSourceRange(), FieldSingleMutable) |
| 9732 | << SecondII << IsSecondMutable; |
| 9733 | return true; |
| 9734 | } |
| 9735 | |
| 9736 | const Expr *FirstInitializer = FirstField->getInClassInitializer(); |
| 9737 | const Expr *SecondInitializer = SecondField->getInClassInitializer(); |
| 9738 | if ((!FirstInitializer && SecondInitializer) || |
| 9739 | (FirstInitializer && !SecondInitializer)) { |
| 9740 | ODRDiagDeclError(FirstRecord, FirstModule, FirstField->getLocation(), |
| 9741 | FirstField->getSourceRange(), FieldSingleInitializer) |
| 9742 | << FirstII << (FirstInitializer != nullptr); |
| 9743 | ODRDiagDeclNote(SecondModule, SecondField->getLocation(), |
| 9744 | SecondField->getSourceRange(), FieldSingleInitializer) |
| 9745 | << SecondII << (SecondInitializer != nullptr); |
| 9746 | return true; |
| 9747 | } |
| 9748 | |
| 9749 | if (FirstInitializer && SecondInitializer) { |
| 9750 | unsigned FirstInitHash = ComputeODRHash(FirstInitializer); |
| 9751 | unsigned SecondInitHash = ComputeODRHash(SecondInitializer); |
| 9752 | if (FirstInitHash != SecondInitHash) { |
| 9753 | ODRDiagDeclError(FirstRecord, FirstModule, FirstField->getLocation(), |
| 9754 | FirstField->getSourceRange(), |
| 9755 | FieldDifferentInitializers) |
| 9756 | << FirstII << FirstInitializer->getSourceRange(); |
| 9757 | ODRDiagDeclNote(SecondModule, SecondField->getLocation(), |
| 9758 | SecondField->getSourceRange(), |
| 9759 | FieldDifferentInitializers) |
| 9760 | << SecondII << SecondInitializer->getSourceRange(); |
| 9761 | return true; |
| 9762 | } |
| 9763 | } |
| 9764 | |
| 9765 | return false; |
| 9766 | }; |
| 9767 | |
| 9768 | auto ODRDiagTypeDefOrAlias = |
| 9769 | [&ODRDiagDeclError, &ODRDiagDeclNote, &ComputeQualTypeODRHash]( |
| 9770 | NamedDecl *FirstRecord, StringRef FirstModule, StringRef SecondModule, |
| 9771 | TypedefNameDecl *FirstTD, TypedefNameDecl *SecondTD, |
| 9772 | bool IsTypeAlias) { |
| 9773 | auto FirstName = FirstTD->getDeclName(); |
| 9774 | auto SecondName = SecondTD->getDeclName(); |
| 9775 | if (FirstName != SecondName) { |
| 9776 | ODRDiagDeclError(FirstRecord, FirstModule, FirstTD->getLocation(), |
| 9777 | FirstTD->getSourceRange(), TypedefName) |
| 9778 | << IsTypeAlias << FirstName; |
| 9779 | ODRDiagDeclNote(SecondModule, SecondTD->getLocation(), |
| 9780 | SecondTD->getSourceRange(), TypedefName) |
| 9781 | << IsTypeAlias << SecondName; |
| 9782 | return true; |
| 9783 | } |
| 9784 | |
| 9785 | QualType FirstType = FirstTD->getUnderlyingType(); |
| 9786 | QualType SecondType = SecondTD->getUnderlyingType(); |
| 9787 | if (ComputeQualTypeODRHash(FirstType) != |
| 9788 | ComputeQualTypeODRHash(SecondType)) { |
| 9789 | ODRDiagDeclError(FirstRecord, FirstModule, FirstTD->getLocation(), |
| 9790 | FirstTD->getSourceRange(), TypedefType) |
| 9791 | << IsTypeAlias << FirstName << FirstType; |
| 9792 | ODRDiagDeclNote(SecondModule, SecondTD->getLocation(), |
| 9793 | SecondTD->getSourceRange(), TypedefType) |
| 9794 | << IsTypeAlias << SecondName << SecondType; |
| 9795 | return true; |
| 9796 | } |
| 9797 | |
| 9798 | return false; |
| 9799 | }; |
| 9800 | |
| 9801 | auto ODRDiagVar = [&ODRDiagDeclError, &ODRDiagDeclNote, |
| 9802 | &ComputeQualTypeODRHash, &ComputeODRHash, |
| 9803 | this](NamedDecl *FirstRecord, StringRef FirstModule, |
| 9804 | StringRef SecondModule, VarDecl *FirstVD, |
| 9805 | VarDecl *SecondVD) { |
| 9806 | auto FirstName = FirstVD->getDeclName(); |
| 9807 | auto SecondName = SecondVD->getDeclName(); |
| 9808 | if (FirstName != SecondName) { |
| 9809 | ODRDiagDeclError(FirstRecord, FirstModule, FirstVD->getLocation(), |
| 9810 | FirstVD->getSourceRange(), VarName) |
| 9811 | << FirstName; |
| 9812 | ODRDiagDeclNote(SecondModule, SecondVD->getLocation(), |
| 9813 | SecondVD->getSourceRange(), VarName) |
| 9814 | << SecondName; |
| 9815 | return true; |
| 9816 | } |
| 9817 | |
| 9818 | QualType FirstType = FirstVD->getType(); |
| 9819 | QualType SecondType = SecondVD->getType(); |
| 9820 | if (ComputeQualTypeODRHash(FirstType) != |
| 9821 | ComputeQualTypeODRHash(SecondType)) { |
| 9822 | ODRDiagDeclError(FirstRecord, FirstModule, FirstVD->getLocation(), |
| 9823 | FirstVD->getSourceRange(), VarType) |
| 9824 | << FirstName << FirstType; |
| 9825 | ODRDiagDeclNote(SecondModule, SecondVD->getLocation(), |
| 9826 | SecondVD->getSourceRange(), VarType) |
| 9827 | << SecondName << SecondType; |
| 9828 | return true; |
| 9829 | } |
| 9830 | |
| 9831 | if (!PP.getLangOpts().CPlusPlus) |
| 9832 | return false; |
| 9833 | |
| 9834 | const Expr *FirstInit = FirstVD->getInit(); |
| 9835 | const Expr *SecondInit = SecondVD->getInit(); |
| 9836 | if ((FirstInit == nullptr) != (SecondInit == nullptr)) { |
| 9837 | ODRDiagDeclError(FirstRecord, FirstModule, FirstVD->getLocation(), |
| 9838 | FirstVD->getSourceRange(), VarSingleInitializer) |
| 9839 | << FirstName << (FirstInit == nullptr) |
| 9840 | << (FirstInit ? FirstInit->getSourceRange() : SourceRange()); |
| 9841 | ODRDiagDeclNote(SecondModule, SecondVD->getLocation(), |
| 9842 | SecondVD->getSourceRange(), VarSingleInitializer) |
| 9843 | << SecondName << (SecondInit == nullptr) |
| 9844 | << (SecondInit ? SecondInit->getSourceRange() : SourceRange()); |
| 9845 | return true; |
| 9846 | } |
| 9847 | |
| 9848 | if (FirstInit && SecondInit && |
| 9849 | ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) { |
| 9850 | ODRDiagDeclError(FirstRecord, FirstModule, FirstVD->getLocation(), |
| 9851 | FirstVD->getSourceRange(), VarDifferentInitializer) |
| 9852 | << FirstName << FirstInit->getSourceRange(); |
| 9853 | ODRDiagDeclNote(SecondModule, SecondVD->getLocation(), |
| 9854 | SecondVD->getSourceRange(), VarDifferentInitializer) |
| 9855 | << SecondName << SecondInit->getSourceRange(); |
| 9856 | return true; |
| 9857 | } |
| 9858 | |
| 9859 | const bool FirstIsConstexpr = FirstVD->isConstexpr(); |
| 9860 | const bool SecondIsConstexpr = SecondVD->isConstexpr(); |
| 9861 | if (FirstIsConstexpr != SecondIsConstexpr) { |
| 9862 | ODRDiagDeclError(FirstRecord, FirstModule, FirstVD->getLocation(), |
| 9863 | FirstVD->getSourceRange(), VarConstexpr) |
| 9864 | << FirstName << FirstIsConstexpr; |
| 9865 | ODRDiagDeclNote(SecondModule, SecondVD->getLocation(), |
| 9866 | SecondVD->getSourceRange(), VarConstexpr) |
| 9867 | << SecondName << SecondIsConstexpr; |
| 9868 | return true; |
| 9869 | } |
| 9870 | return false; |
| 9871 | }; |
| 9872 | |
| 9873 | auto DifferenceSelector = [](Decl *D) { |
| 9874 | assert(D && "valid Decl required"); |
| 9875 | switch (D->getKind()) { |
| 9876 | default: |
| 9877 | return Other; |
| 9878 | case Decl::AccessSpec: |
| 9879 | switch (D->getAccess()) { |
| 9880 | case AS_public: |
| 9881 | return PublicSpecifer; |
| 9882 | case AS_private: |
| 9883 | return PrivateSpecifer; |
| 9884 | case AS_protected: |
| 9885 | return ProtectedSpecifer; |
| 9886 | case AS_none: |
| 9887 | break; |
| 9888 | } |
| 9889 | llvm_unreachable("Invalid access specifier"); |
| 9890 | case Decl::StaticAssert: |
| 9891 | return StaticAssert; |
| 9892 | case Decl::Field: |
| 9893 | return Field; |
| 9894 | case Decl::CXXMethod: |
| 9895 | case Decl::CXXConstructor: |
| 9896 | case Decl::CXXDestructor: |
| 9897 | return CXXMethod; |
| 9898 | case Decl::TypeAlias: |
| 9899 | return TypeAlias; |
| 9900 | case Decl::Typedef: |
| 9901 | return TypeDef; |
| 9902 | case Decl::Var: |
| 9903 | return Var; |
| 9904 | case Decl::Friend: |
| 9905 | return Friend; |
| 9906 | case Decl::FunctionTemplate: |
| 9907 | return FunctionTemplate; |
| 9908 | } |
| 9909 | }; |
| 9910 | |
| 9911 | using DeclHashes = llvm::SmallVector<std::pair<Decl *, unsigned>, 4>; |
| 9912 | auto PopulateHashes = [&ComputeSubDeclODRHash](DeclHashes &Hashes, |
| 9913 | RecordDecl *Record, |
| 9914 | const DeclContext *DC) { |
| 9915 | for (auto *D : Record->decls()) { |
| 9916 | if (!ODRHash::isDeclToBeProcessed(D, DC)) |
| 9917 | continue; |
| 9918 | Hashes.emplace_back(D, ComputeSubDeclODRHash(D)); |
| 9919 | } |
| 9920 | }; |
| 9921 | |
| 9922 | struct DiffResult { |
| 9923 | Decl *FirstDecl = nullptr, *SecondDecl = nullptr; |
| 9924 | ODRMismatchDecl FirstDiffType = Other, SecondDiffType = Other; |
| 9925 | }; |
| 9926 | |
| 9927 | |
| 9928 | |
| 9929 | |
| 9930 | auto FindTypeDiffs = [&DifferenceSelector](DeclHashes &FirstHashes, |
| 9931 | DeclHashes &SecondHashes) { |
| 9932 | DiffResult DR; |
| 9933 | auto FirstIt = FirstHashes.begin(); |
| 9934 | auto SecondIt = SecondHashes.begin(); |
| 9935 | while (FirstIt != FirstHashes.end() || SecondIt != SecondHashes.end()) { |
| 9936 | if (FirstIt != FirstHashes.end() && SecondIt != SecondHashes.end() && |
| 9937 | FirstIt->second == SecondIt->second) { |
| 9938 | ++FirstIt; |
| 9939 | ++SecondIt; |
| 9940 | continue; |
| 9941 | } |
| 9942 | |
| 9943 | DR.FirstDecl = FirstIt == FirstHashes.end() ? nullptr : FirstIt->first; |
| 9944 | DR.SecondDecl = |
| 9945 | SecondIt == SecondHashes.end() ? nullptr : SecondIt->first; |
| 9946 | |
| 9947 | DR.FirstDiffType = |
| 9948 | DR.FirstDecl ? DifferenceSelector(DR.FirstDecl) : EndOfClass; |
| 9949 | DR.SecondDiffType = |
| 9950 | DR.SecondDecl ? DifferenceSelector(DR.SecondDecl) : EndOfClass; |
| 9951 | return DR; |
| 9952 | } |
| 9953 | return DR; |
| 9954 | }; |
| 9955 | |
| 9956 | |
| 9957 | |
| 9958 | |
| 9959 | auto DiagnoseODRUnexpected = [this](DiffResult &DR, NamedDecl *FirstRecord, |
| 9960 | StringRef FirstModule, |
| 9961 | NamedDecl *SecondRecord, |
| 9962 | StringRef SecondModule) { |
| 9963 | Diag(FirstRecord->getLocation(), |
| 9964 | diag::err_module_odr_violation_different_definitions) |
| 9965 | << FirstRecord << FirstModule.empty() << FirstModule; |
| 9966 | |
| 9967 | if (DR.FirstDecl) { |
| 9968 | Diag(DR.FirstDecl->getLocation(), diag::note_first_module_difference) |
| 9969 | << FirstRecord << DR.FirstDecl->getSourceRange(); |
| 9970 | } |
| 9971 | |
| 9972 | Diag(SecondRecord->getLocation(), |
| 9973 | diag::note_module_odr_violation_different_definitions) |
| 9974 | << SecondModule; |
| 9975 | |
| 9976 | if (DR.SecondDecl) { |
| 9977 | Diag(DR.SecondDecl->getLocation(), diag::note_second_module_difference) |
| 9978 | << DR.SecondDecl->getSourceRange(); |
| 9979 | } |
| 9980 | }; |
| 9981 | |
| 9982 | auto DiagnoseODRMismatch = |
| 9983 | [this](DiffResult &DR, NamedDecl *FirstRecord, StringRef FirstModule, |
| 9984 | NamedDecl *SecondRecord, StringRef SecondModule) { |
| 9985 | SourceLocation FirstLoc; |
| 9986 | SourceRange FirstRange; |
| 9987 | auto *FirstTag = dyn_cast<TagDecl>(FirstRecord); |
| 9988 | if (DR.FirstDiffType == EndOfClass && FirstTag) { |
| 9989 | FirstLoc = FirstTag->getBraceRange().getEnd(); |
| 9990 | } else { |
| 9991 | FirstLoc = DR.FirstDecl->getLocation(); |
| 9992 | FirstRange = DR.FirstDecl->getSourceRange(); |
| 9993 | } |
| 9994 | Diag(FirstLoc, diag::err_module_odr_violation_mismatch_decl) |
| 9995 | << FirstRecord << FirstModule.empty() << FirstModule << FirstRange |
| 9996 | << DR.FirstDiffType; |
| 9997 | |
| 9998 | SourceLocation SecondLoc; |
| 9999 | SourceRange SecondRange; |
| 10000 | auto *SecondTag = dyn_cast<TagDecl>(SecondRecord); |
| 10001 | if (DR.SecondDiffType == EndOfClass && SecondTag) { |
| 10002 | SecondLoc = SecondTag->getBraceRange().getEnd(); |
| 10003 | } else { |
| 10004 | SecondLoc = DR.SecondDecl->getLocation(); |
| 10005 | SecondRange = DR.SecondDecl->getSourceRange(); |
| 10006 | } |
| 10007 | Diag(SecondLoc, diag::note_module_odr_violation_mismatch_decl) |
| 10008 | << SecondModule << SecondRange << DR.SecondDiffType; |
| 10009 | }; |
| 10010 | |
| 10011 | |
| 10012 | for (auto &Merge : OdrMergeFailures) { |
| 10013 | |
| 10014 | |
| 10015 | if (!DiagnosedOdrMergeFailures.insert(Merge.first).second) |
| 10016 | continue; |
| 10017 | |
| 10018 | bool Diagnosed = false; |
| 10019 | CXXRecordDecl *FirstRecord = Merge.first; |
| 10020 | std::string FirstModule = getOwningModuleNameForDiagnostic(FirstRecord); |
| 10021 | for (auto &RecordPair : Merge.second) { |
| 10022 | CXXRecordDecl *SecondRecord = RecordPair.first; |
| 10023 | |
| 10024 | |
| 10025 | if (FirstRecord == SecondRecord) |
| 10026 | continue; |
| 10027 | |
| 10028 | std::string SecondModule = getOwningModuleNameForDiagnostic(SecondRecord); |
| 10029 | |
| 10030 | auto *FirstDD = FirstRecord->DefinitionData; |
| 10031 | auto *SecondDD = RecordPair.second; |
| 10032 | |
| 10033 | assert(FirstDD && SecondDD && "Definitions without DefinitionData"); |
| 10034 | |
| 10035 | |
| 10036 | if (FirstDD != SecondDD) { |
| 10037 | enum ODRDefinitionDataDifference { |
| 10038 | NumBases, |
| 10039 | NumVBases, |
| 10040 | BaseType, |
| 10041 | BaseVirtual, |
| 10042 | BaseAccess, |
| 10043 | }; |
| 10044 | auto ODRDiagBaseError = [FirstRecord, &FirstModule, |
| 10045 | this](SourceLocation Loc, SourceRange Range, |
| 10046 | ODRDefinitionDataDifference DiffType) { |
| 10047 | return Diag(Loc, diag::err_module_odr_violation_definition_data) |
| 10048 | << FirstRecord << FirstModule.empty() << FirstModule << Range |
| 10049 | << DiffType; |
| 10050 | }; |
| 10051 | auto ODRDiagBaseNote = [&SecondModule, |
| 10052 | this](SourceLocation Loc, SourceRange Range, |
| 10053 | ODRDefinitionDataDifference DiffType) { |
| 10054 | return Diag(Loc, diag::note_module_odr_violation_definition_data) |
| 10055 | << SecondModule << Range << DiffType; |
| 10056 | }; |
| 10057 | |
| 10058 | unsigned FirstNumBases = FirstDD->NumBases; |
| 10059 | unsigned FirstNumVBases = FirstDD->NumVBases; |
| 10060 | unsigned SecondNumBases = SecondDD->NumBases; |
| 10061 | unsigned SecondNumVBases = SecondDD->NumVBases; |
| 10062 | |
| 10063 | auto GetSourceRange = [](struct CXXRecordDecl::DefinitionData *DD) { |
| 10064 | unsigned NumBases = DD->NumBases; |
| 10065 | if (NumBases == 0) return SourceRange(); |
| 10066 | auto bases = DD->bases(); |
| 10067 | return SourceRange(bases[0].getBeginLoc(), |
| 10068 | bases[NumBases - 1].getEndLoc()); |
| 10069 | }; |
| 10070 | |
| 10071 | if (FirstNumBases != SecondNumBases) { |
| 10072 | ODRDiagBaseError(FirstRecord->getLocation(), GetSourceRange(FirstDD), |
| 10073 | NumBases) |
| 10074 | << FirstNumBases; |
| 10075 | ODRDiagBaseNote(SecondRecord->getLocation(), GetSourceRange(SecondDD), |
| 10076 | NumBases) |
| 10077 | << SecondNumBases; |
| 10078 | Diagnosed = true; |
| 10079 | break; |
| 10080 | } |
| 10081 | |
| 10082 | if (FirstNumVBases != SecondNumVBases) { |
| 10083 | ODRDiagBaseError(FirstRecord->getLocation(), GetSourceRange(FirstDD), |
| 10084 | NumVBases) |
| 10085 | << FirstNumVBases; |
| 10086 | ODRDiagBaseNote(SecondRecord->getLocation(), GetSourceRange(SecondDD), |
| 10087 | NumVBases) |
| 10088 | << SecondNumVBases; |
| 10089 | Diagnosed = true; |
| 10090 | break; |
| 10091 | } |
| 10092 | |
| 10093 | auto FirstBases = FirstDD->bases(); |
| 10094 | auto SecondBases = SecondDD->bases(); |
| 10095 | unsigned i = 0; |
| 10096 | for (i = 0; i < FirstNumBases; ++i) { |
| 10097 | auto FirstBase = FirstBases[i]; |
| 10098 | auto SecondBase = SecondBases[i]; |
| 10099 | if (ComputeQualTypeODRHash(FirstBase.getType()) != |
| 10100 | ComputeQualTypeODRHash(SecondBase.getType())) { |
| 10101 | ODRDiagBaseError(FirstRecord->getLocation(), |
| 10102 | FirstBase.getSourceRange(), BaseType) |
| 10103 | << (i + 1) << FirstBase.getType(); |
| 10104 | ODRDiagBaseNote(SecondRecord->getLocation(), |
| 10105 | SecondBase.getSourceRange(), BaseType) |
| 10106 | << (i + 1) << SecondBase.getType(); |
| 10107 | break; |
| 10108 | } |
| 10109 | |
| 10110 | if (FirstBase.isVirtual() != SecondBase.isVirtual()) { |
| 10111 | ODRDiagBaseError(FirstRecord->getLocation(), |
| 10112 | FirstBase.getSourceRange(), BaseVirtual) |
| 10113 | << (i + 1) << FirstBase.isVirtual() << FirstBase.getType(); |
| 10114 | ODRDiagBaseNote(SecondRecord->getLocation(), |
| 10115 | SecondBase.getSourceRange(), BaseVirtual) |
| 10116 | << (i + 1) << SecondBase.isVirtual() << SecondBase.getType(); |
| 10117 | break; |
| 10118 | } |
| 10119 | |
| 10120 | if (FirstBase.getAccessSpecifierAsWritten() != |
| 10121 | SecondBase.getAccessSpecifierAsWritten()) { |
| 10122 | ODRDiagBaseError(FirstRecord->getLocation(), |
| 10123 | FirstBase.getSourceRange(), BaseAccess) |
| 10124 | << (i + 1) << FirstBase.getType() |
| 10125 | << (int)FirstBase.getAccessSpecifierAsWritten(); |
| 10126 | ODRDiagBaseNote(SecondRecord->getLocation(), |
| 10127 | SecondBase.getSourceRange(), BaseAccess) |
| 10128 | << (i + 1) << SecondBase.getType() |
| 10129 | << (int)SecondBase.getAccessSpecifierAsWritten(); |
| 10130 | break; |
| 10131 | } |
| 10132 | } |
| 10133 | |
| 10134 | if (i != FirstNumBases) { |
| 10135 | Diagnosed = true; |
| 10136 | break; |
| 10137 | } |
| 10138 | } |
| 10139 | |
| 10140 | const ClassTemplateDecl *FirstTemplate = |
| 10141 | FirstRecord->getDescribedClassTemplate(); |
| 10142 | const ClassTemplateDecl *SecondTemplate = |
| 10143 | SecondRecord->getDescribedClassTemplate(); |
| 10144 | |
| 10145 | assert(!FirstTemplate == !SecondTemplate && |
| 10146 | "Both pointers should be null or non-null"); |
| 10147 | |
| 10148 | enum ODRTemplateDifference { |
| 10149 | ParamEmptyName, |
| 10150 | ParamName, |
| 10151 | ParamSingleDefaultArgument, |
| 10152 | ParamDifferentDefaultArgument, |
| 10153 | }; |
| 10154 | |
| 10155 | if (FirstTemplate && SecondTemplate) { |
| 10156 | DeclHashes FirstTemplateHashes; |
| 10157 | DeclHashes SecondTemplateHashes; |
| 10158 | |
| 10159 | auto PopulateTemplateParameterHashs = |
| 10160 | [&ComputeSubDeclODRHash](DeclHashes &Hashes, |
| 10161 | const ClassTemplateDecl *TD) { |
| 10162 | for (auto *D : TD->getTemplateParameters()->asArray()) { |
| 10163 | Hashes.emplace_back(D, ComputeSubDeclODRHash(D)); |
| 10164 | } |
| 10165 | }; |
| 10166 | |
| 10167 | PopulateTemplateParameterHashs(FirstTemplateHashes, FirstTemplate); |
| 10168 | PopulateTemplateParameterHashs(SecondTemplateHashes, SecondTemplate); |
| 10169 | |
| 10170 | assert(FirstTemplateHashes.size() == SecondTemplateHashes.size() && |
| 10171 | "Number of template parameters should be equal."); |
| 10172 | |
| 10173 | auto FirstIt = FirstTemplateHashes.begin(); |
| 10174 | auto FirstEnd = FirstTemplateHashes.end(); |
| 10175 | auto SecondIt = SecondTemplateHashes.begin(); |
| 10176 | for (; FirstIt != FirstEnd; ++FirstIt, ++SecondIt) { |
| 10177 | if (FirstIt->second == SecondIt->second) |
| 10178 | continue; |
| 10179 | |
| 10180 | auto ODRDiagTemplateError = [FirstRecord, &FirstModule, this]( |
| 10181 | SourceLocation Loc, SourceRange Range, |
| 10182 | ODRTemplateDifference DiffType) { |
| 10183 | return Diag(Loc, diag::err_module_odr_violation_template_parameter) |
| 10184 | << FirstRecord << FirstModule.empty() << FirstModule << Range |
| 10185 | << DiffType; |
| 10186 | }; |
| 10187 | auto ODRDiagTemplateNote = [&SecondModule, this]( |
| 10188 | SourceLocation Loc, SourceRange Range, |
| 10189 | ODRTemplateDifference DiffType) { |
| 10190 | return Diag(Loc, diag::note_module_odr_violation_template_parameter) |
| 10191 | << SecondModule << Range << DiffType; |
| 10192 | }; |
| 10193 | |
| 10194 | const NamedDecl* FirstDecl = cast<NamedDecl>(FirstIt->first); |
| 10195 | const NamedDecl* SecondDecl = cast<NamedDecl>(SecondIt->first); |
| 10196 | |
| 10197 | assert(FirstDecl->getKind() == SecondDecl->getKind() && |
| 10198 | "Parameter Decl's should be the same kind."); |
| 10199 | |
| 10200 | DeclarationName FirstName = FirstDecl->getDeclName(); |
| 10201 | DeclarationName SecondName = SecondDecl->getDeclName(); |
| 10202 | |
| 10203 | if (FirstName != SecondName) { |
| 10204 | const bool FirstNameEmpty = |
| 10205 | FirstName.isIdentifier() && !FirstName.getAsIdentifierInfo(); |
| 10206 | const bool SecondNameEmpty = |
| 10207 | SecondName.isIdentifier() && !SecondName.getAsIdentifierInfo(); |
| 10208 | assert((!FirstNameEmpty || !SecondNameEmpty) && |
| 10209 | "Both template parameters cannot be unnamed."); |
| 10210 | ODRDiagTemplateError(FirstDecl->getLocation(), |
| 10211 | FirstDecl->getSourceRange(), |
| 10212 | FirstNameEmpty ? ParamEmptyName : ParamName) |
| 10213 | << FirstName; |
| 10214 | ODRDiagTemplateNote(SecondDecl->getLocation(), |
| 10215 | SecondDecl->getSourceRange(), |
| 10216 | SecondNameEmpty ? ParamEmptyName : ParamName) |
| 10217 | << SecondName; |
| 10218 | break; |
| 10219 | } |
| 10220 | |
| 10221 | switch (FirstDecl->getKind()) { |
| 10222 | default: |
| 10223 | llvm_unreachable("Invalid template parameter type."); |
| 10224 | case Decl::TemplateTypeParm: { |
| 10225 | const auto *FirstParam = cast<TemplateTypeParmDecl>(FirstDecl); |
| 10226 | const auto *SecondParam = cast<TemplateTypeParmDecl>(SecondDecl); |
| 10227 | const bool HasFirstDefaultArgument = |
| 10228 | FirstParam->hasDefaultArgument() && |
| 10229 | !FirstParam->defaultArgumentWasInherited(); |
| 10230 | const bool HasSecondDefaultArgument = |
| 10231 | SecondParam->hasDefaultArgument() && |
| 10232 | !SecondParam->defaultArgumentWasInherited(); |
| 10233 | |
| 10234 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 10235 | ODRDiagTemplateError(FirstDecl->getLocation(), |
| 10236 | FirstDecl->getSourceRange(), |
| 10237 | ParamSingleDefaultArgument) |
| 10238 | << HasFirstDefaultArgument; |
| 10239 | ODRDiagTemplateNote(SecondDecl->getLocation(), |
| 10240 | SecondDecl->getSourceRange(), |
| 10241 | ParamSingleDefaultArgument) |
| 10242 | << HasSecondDefaultArgument; |
| 10243 | break; |
| 10244 | } |
| 10245 | |
| 10246 | assert(HasFirstDefaultArgument && HasSecondDefaultArgument && |
| 10247 | "Expecting default arguments."); |
| 10248 | |
| 10249 | ODRDiagTemplateError(FirstDecl->getLocation(), |
| 10250 | FirstDecl->getSourceRange(), |
| 10251 | ParamDifferentDefaultArgument); |
| 10252 | ODRDiagTemplateNote(SecondDecl->getLocation(), |
| 10253 | SecondDecl->getSourceRange(), |
| 10254 | ParamDifferentDefaultArgument); |
| 10255 | |
| 10256 | break; |
| 10257 | } |
| 10258 | case Decl::NonTypeTemplateParm: { |
| 10259 | const auto *FirstParam = cast<NonTypeTemplateParmDecl>(FirstDecl); |
| 10260 | const auto *SecondParam = cast<NonTypeTemplateParmDecl>(SecondDecl); |
| 10261 | const bool HasFirstDefaultArgument = |
| 10262 | FirstParam->hasDefaultArgument() && |
| 10263 | !FirstParam->defaultArgumentWasInherited(); |
| 10264 | const bool HasSecondDefaultArgument = |
| 10265 | SecondParam->hasDefaultArgument() && |
| 10266 | !SecondParam->defaultArgumentWasInherited(); |
| 10267 | |
| 10268 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 10269 | ODRDiagTemplateError(FirstDecl->getLocation(), |
| 10270 | FirstDecl->getSourceRange(), |
| 10271 | ParamSingleDefaultArgument) |
| 10272 | << HasFirstDefaultArgument; |
| 10273 | ODRDiagTemplateNote(SecondDecl->getLocation(), |
| 10274 | SecondDecl->getSourceRange(), |
| 10275 | ParamSingleDefaultArgument) |
| 10276 | << HasSecondDefaultArgument; |
| 10277 | break; |
| 10278 | } |
| 10279 | |
| 10280 | assert(HasFirstDefaultArgument && HasSecondDefaultArgument && |
| 10281 | "Expecting default arguments."); |
| 10282 | |
| 10283 | ODRDiagTemplateError(FirstDecl->getLocation(), |
| 10284 | FirstDecl->getSourceRange(), |
| 10285 | ParamDifferentDefaultArgument); |
| 10286 | ODRDiagTemplateNote(SecondDecl->getLocation(), |
| 10287 | SecondDecl->getSourceRange(), |
| 10288 | ParamDifferentDefaultArgument); |
| 10289 | |
| 10290 | break; |
| 10291 | } |
| 10292 | case Decl::TemplateTemplateParm: { |
| 10293 | const auto *FirstParam = cast<TemplateTemplateParmDecl>(FirstDecl); |
| 10294 | const auto *SecondParam = |
| 10295 | cast<TemplateTemplateParmDecl>(SecondDecl); |
| 10296 | const bool HasFirstDefaultArgument = |
| 10297 | FirstParam->hasDefaultArgument() && |
| 10298 | !FirstParam->defaultArgumentWasInherited(); |
| 10299 | const bool HasSecondDefaultArgument = |
| 10300 | SecondParam->hasDefaultArgument() && |
| 10301 | !SecondParam->defaultArgumentWasInherited(); |
| 10302 | |
| 10303 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 10304 | ODRDiagTemplateError(FirstDecl->getLocation(), |
| 10305 | FirstDecl->getSourceRange(), |
| 10306 | ParamSingleDefaultArgument) |
| 10307 | << HasFirstDefaultArgument; |
| 10308 | ODRDiagTemplateNote(SecondDecl->getLocation(), |
| 10309 | SecondDecl->getSourceRange(), |
| 10310 | ParamSingleDefaultArgument) |
| 10311 | << HasSecondDefaultArgument; |
| 10312 | break; |
| 10313 | } |
| 10314 | |
| 10315 | assert(HasFirstDefaultArgument && HasSecondDefaultArgument && |
| 10316 | "Expecting default arguments."); |
| 10317 | |
| 10318 | ODRDiagTemplateError(FirstDecl->getLocation(), |
| 10319 | FirstDecl->getSourceRange(), |
| 10320 | ParamDifferentDefaultArgument); |
| 10321 | ODRDiagTemplateNote(SecondDecl->getLocation(), |
| 10322 | SecondDecl->getSourceRange(), |
| 10323 | ParamDifferentDefaultArgument); |
| 10324 | |
| 10325 | break; |
| 10326 | } |
| 10327 | } |
| 10328 | |
| 10329 | break; |
| 10330 | } |
| 10331 | |
| 10332 | if (FirstIt != FirstEnd) { |
| 10333 | Diagnosed = true; |
| 10334 | break; |
| 10335 | } |
| 10336 | } |
| 10337 | |
| 10338 | DeclHashes FirstHashes; |
| 10339 | DeclHashes SecondHashes; |
| 10340 | const DeclContext *DC = FirstRecord; |
| 10341 | PopulateHashes(FirstHashes, FirstRecord, DC); |
| 10342 | PopulateHashes(SecondHashes, SecondRecord, DC); |
| 10343 | |
| 10344 | auto DR = FindTypeDiffs(FirstHashes, SecondHashes); |
| 10345 | ODRMismatchDecl FirstDiffType = DR.FirstDiffType; |
| 10346 | ODRMismatchDecl SecondDiffType = DR.SecondDiffType; |
| 10347 | Decl *FirstDecl = DR.FirstDecl; |
| 10348 | Decl *SecondDecl = DR.SecondDecl; |
| 10349 | |
| 10350 | if (FirstDiffType == Other || SecondDiffType == Other) { |
| 10351 | DiagnoseODRUnexpected(DR, FirstRecord, FirstModule, SecondRecord, |
| 10352 | SecondModule); |
| 10353 | Diagnosed = true; |
| 10354 | break; |
| 10355 | } |
| 10356 | |
| 10357 | if (FirstDiffType != SecondDiffType) { |
| 10358 | DiagnoseODRMismatch(DR, FirstRecord, FirstModule, SecondRecord, |
| 10359 | SecondModule); |
| 10360 | Diagnosed = true; |
| 10361 | break; |
| 10362 | } |
| 10363 | |
| 10364 | assert(FirstDiffType == SecondDiffType); |
| 10365 | |
| 10366 | switch (FirstDiffType) { |
| 10367 | case Other: |
| 10368 | case EndOfClass: |
| 10369 | case PublicSpecifer: |
| 10370 | case PrivateSpecifer: |
| 10371 | case ProtectedSpecifer: |
| 10372 | llvm_unreachable("Invalid diff type"); |
| 10373 | |
| 10374 | case StaticAssert: { |
| 10375 | StaticAssertDecl *FirstSA = cast<StaticAssertDecl>(FirstDecl); |
| 10376 | StaticAssertDecl *SecondSA = cast<StaticAssertDecl>(SecondDecl); |
| 10377 | |
| 10378 | Expr *FirstExpr = FirstSA->getAssertExpr(); |
| 10379 | Expr *SecondExpr = SecondSA->getAssertExpr(); |
| 10380 | unsigned FirstODRHash = ComputeODRHash(FirstExpr); |
| 10381 | unsigned SecondODRHash = ComputeODRHash(SecondExpr); |
| 10382 | if (FirstODRHash != SecondODRHash) { |
| 10383 | ODRDiagDeclError(FirstRecord, FirstModule, FirstExpr->getBeginLoc(), |
| 10384 | FirstExpr->getSourceRange(), StaticAssertCondition); |
| 10385 | ODRDiagDeclNote(SecondModule, SecondExpr->getBeginLoc(), |
| 10386 | SecondExpr->getSourceRange(), StaticAssertCondition); |
| 10387 | Diagnosed = true; |
| 10388 | break; |
| 10389 | } |
| 10390 | |
| 10391 | StringLiteral *FirstStr = FirstSA->getMessage(); |
| 10392 | StringLiteral *SecondStr = SecondSA->getMessage(); |
| 10393 | assert((FirstStr || SecondStr) && "Both messages cannot be empty"); |
| 10394 | if ((FirstStr && !SecondStr) || (!FirstStr && SecondStr)) { |
| 10395 | SourceLocation FirstLoc, SecondLoc; |
| 10396 | SourceRange FirstRange, SecondRange; |
| 10397 | if (FirstStr) { |
| 10398 | FirstLoc = FirstStr->getBeginLoc(); |
| 10399 | FirstRange = FirstStr->getSourceRange(); |
| 10400 | } else { |
| 10401 | FirstLoc = FirstSA->getBeginLoc(); |
| 10402 | FirstRange = FirstSA->getSourceRange(); |
| 10403 | } |
| 10404 | if (SecondStr) { |
| 10405 | SecondLoc = SecondStr->getBeginLoc(); |
| 10406 | SecondRange = SecondStr->getSourceRange(); |
| 10407 | } else { |
| 10408 | SecondLoc = SecondSA->getBeginLoc(); |
| 10409 | SecondRange = SecondSA->getSourceRange(); |
| 10410 | } |
| 10411 | ODRDiagDeclError(FirstRecord, FirstModule, FirstLoc, FirstRange, |
| 10412 | StaticAssertOnlyMessage) |
| 10413 | << (FirstStr == nullptr); |
| 10414 | ODRDiagDeclNote(SecondModule, SecondLoc, SecondRange, |
| 10415 | StaticAssertOnlyMessage) |
| 10416 | << (SecondStr == nullptr); |
| 10417 | Diagnosed = true; |
| 10418 | break; |
| 10419 | } |
| 10420 | |
| 10421 | if (FirstStr && SecondStr && |
| 10422 | FirstStr->getString() != SecondStr->getString()) { |
| 10423 | ODRDiagDeclError(FirstRecord, FirstModule, FirstStr->getBeginLoc(), |
| 10424 | FirstStr->getSourceRange(), StaticAssertMessage); |
| 10425 | ODRDiagDeclNote(SecondModule, SecondStr->getBeginLoc(), |
| 10426 | SecondStr->getSourceRange(), StaticAssertMessage); |
| 10427 | Diagnosed = true; |
| 10428 | break; |
| 10429 | } |
| 10430 | break; |
| 10431 | } |
| 10432 | case Field: { |
| 10433 | Diagnosed = ODRDiagField(FirstRecord, FirstModule, SecondModule, |
| 10434 | cast<FieldDecl>(FirstDecl), |
| 10435 | cast<FieldDecl>(SecondDecl)); |
| 10436 | break; |
| 10437 | } |
| 10438 | case CXXMethod: { |
| 10439 | enum { |
| 10440 | DiagMethod, |
| 10441 | DiagConstructor, |
| 10442 | DiagDestructor, |
| 10443 | } FirstMethodType, |
| 10444 | SecondMethodType; |
| 10445 | auto GetMethodTypeForDiagnostics = [](const CXXMethodDecl* D) { |
| 10446 | if (isa<CXXConstructorDecl>(D)) return DiagConstructor; |
| 10447 | if (isa<CXXDestructorDecl>(D)) return DiagDestructor; |
| 10448 | return DiagMethod; |
| 10449 | }; |
| 10450 | const CXXMethodDecl *FirstMethod = cast<CXXMethodDecl>(FirstDecl); |
| 10451 | const CXXMethodDecl *SecondMethod = cast<CXXMethodDecl>(SecondDecl); |
| 10452 | FirstMethodType = GetMethodTypeForDiagnostics(FirstMethod); |
| 10453 | SecondMethodType = GetMethodTypeForDiagnostics(SecondMethod); |
| 10454 | auto FirstName = FirstMethod->getDeclName(); |
| 10455 | auto SecondName = SecondMethod->getDeclName(); |
| 10456 | if (FirstMethodType != SecondMethodType || FirstName != SecondName) { |
| 10457 | ODRDiagDeclError(FirstRecord, FirstModule, FirstMethod->getLocation(), |
| 10458 | FirstMethod->getSourceRange(), MethodName) |
| 10459 | << FirstMethodType << FirstName; |
| 10460 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10461 | SecondMethod->getSourceRange(), MethodName) |
| 10462 | << SecondMethodType << SecondName; |
| 10463 | |
| 10464 | Diagnosed = true; |
| 10465 | break; |
| 10466 | } |
| 10467 | |
| 10468 | const bool FirstDeleted = FirstMethod->isDeletedAsWritten(); |
| 10469 | const bool SecondDeleted = SecondMethod->isDeletedAsWritten(); |
| 10470 | if (FirstDeleted != SecondDeleted) { |
| 10471 | ODRDiagDeclError(FirstRecord, FirstModule, FirstMethod->getLocation(), |
| 10472 | FirstMethod->getSourceRange(), MethodDeleted) |
| 10473 | << FirstMethodType << FirstName << FirstDeleted; |
| 10474 | |
| 10475 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10476 | SecondMethod->getSourceRange(), MethodDeleted) |
| 10477 | << SecondMethodType << SecondName << SecondDeleted; |
| 10478 | Diagnosed = true; |
| 10479 | break; |
| 10480 | } |
| 10481 | |
| 10482 | const bool FirstDefaulted = FirstMethod->isExplicitlyDefaulted(); |
| 10483 | const bool SecondDefaulted = SecondMethod->isExplicitlyDefaulted(); |
| 10484 | if (FirstDefaulted != SecondDefaulted) { |
| 10485 | ODRDiagDeclError(FirstRecord, FirstModule, FirstMethod->getLocation(), |
| 10486 | FirstMethod->getSourceRange(), MethodDefaulted) |
| 10487 | << FirstMethodType << FirstName << FirstDefaulted; |
| 10488 | |
| 10489 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10490 | SecondMethod->getSourceRange(), MethodDefaulted) |
| 10491 | << SecondMethodType << SecondName << SecondDefaulted; |
| 10492 | Diagnosed = true; |
| 10493 | break; |
| 10494 | } |
| 10495 | |
| 10496 | const bool FirstVirtual = FirstMethod->isVirtualAsWritten(); |
| 10497 | const bool SecondVirtual = SecondMethod->isVirtualAsWritten(); |
| 10498 | const bool FirstPure = FirstMethod->isPure(); |
| 10499 | const bool SecondPure = SecondMethod->isPure(); |
| 10500 | if ((FirstVirtual || SecondVirtual) && |
| 10501 | (FirstVirtual != SecondVirtual || FirstPure != SecondPure)) { |
| 10502 | ODRDiagDeclError(FirstRecord, FirstModule, FirstMethod->getLocation(), |
| 10503 | FirstMethod->getSourceRange(), MethodVirtual) |
| 10504 | << FirstMethodType << FirstName << FirstPure << FirstVirtual; |
| 10505 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10506 | SecondMethod->getSourceRange(), MethodVirtual) |
| 10507 | << SecondMethodType << SecondName << SecondPure << SecondVirtual; |
| 10508 | Diagnosed = true; |
| 10509 | break; |
| 10510 | } |
| 10511 | |
| 10512 | |
| 10513 | |
| 10514 | |
| 10515 | const auto FirstStorage = FirstMethod->getStorageClass(); |
| 10516 | const auto SecondStorage = SecondMethod->getStorageClass(); |
| 10517 | const bool FirstStatic = FirstStorage == SC_Static; |
| 10518 | const bool SecondStatic = SecondStorage == SC_Static; |
| 10519 | if (FirstStatic != SecondStatic) { |
| 10520 | ODRDiagDeclError(FirstRecord, FirstModule, FirstMethod->getLocation(), |
| 10521 | FirstMethod->getSourceRange(), MethodStatic) |
| 10522 | << FirstMethodType << FirstName << FirstStatic; |
| 10523 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10524 | SecondMethod->getSourceRange(), MethodStatic) |
| 10525 | << SecondMethodType << SecondName << SecondStatic; |
| 10526 | Diagnosed = true; |
| 10527 | break; |
| 10528 | } |
| 10529 | |
| 10530 | const bool FirstVolatile = FirstMethod->isVolatile(); |
| 10531 | const bool SecondVolatile = SecondMethod->isVolatile(); |
| 10532 | if (FirstVolatile != SecondVolatile) { |
| 10533 | ODRDiagDeclError(FirstRecord, FirstModule, FirstMethod->getLocation(), |
| 10534 | FirstMethod->getSourceRange(), MethodVolatile) |
| 10535 | << FirstMethodType << FirstName << FirstVolatile; |
| 10536 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10537 | SecondMethod->getSourceRange(), MethodVolatile) |
| 10538 | << SecondMethodType << SecondName << SecondVolatile; |
| 10539 | Diagnosed = true; |
| 10540 | break; |
| 10541 | } |
| 10542 | |
| 10543 | const bool FirstConst = FirstMethod->isConst(); |
| 10544 | const bool SecondConst = SecondMethod->isConst(); |
| 10545 | if (FirstConst != SecondConst) { |
| 10546 | ODRDiagDeclError(FirstRecord, FirstModule, FirstMethod->getLocation(), |
| 10547 | FirstMethod->getSourceRange(), MethodConst) |
| 10548 | << FirstMethodType << FirstName << FirstConst; |
| 10549 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10550 | SecondMethod->getSourceRange(), MethodConst) |
| 10551 | << SecondMethodType << SecondName << SecondConst; |
| 10552 | Diagnosed = true; |
| 10553 | break; |
| 10554 | } |
| 10555 | |
| 10556 | const bool FirstInline = FirstMethod->isInlineSpecified(); |
| 10557 | const bool SecondInline = SecondMethod->isInlineSpecified(); |
| 10558 | if (FirstInline != SecondInline) { |
| 10559 | ODRDiagDeclError(FirstRecord, FirstModule, FirstMethod->getLocation(), |
| 10560 | FirstMethod->getSourceRange(), MethodInline) |
| 10561 | << FirstMethodType << FirstName << FirstInline; |
| 10562 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10563 | SecondMethod->getSourceRange(), MethodInline) |
| 10564 | << SecondMethodType << SecondName << SecondInline; |
| 10565 | Diagnosed = true; |
| 10566 | break; |
| 10567 | } |
| 10568 | |
| 10569 | const unsigned FirstNumParameters = FirstMethod->param_size(); |
| 10570 | const unsigned SecondNumParameters = SecondMethod->param_size(); |
| 10571 | if (FirstNumParameters != SecondNumParameters) { |
| 10572 | ODRDiagDeclError(FirstRecord, FirstModule, FirstMethod->getLocation(), |
| 10573 | FirstMethod->getSourceRange(), |
| 10574 | MethodNumberParameters) |
| 10575 | << FirstMethodType << FirstName << FirstNumParameters; |
| 10576 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10577 | SecondMethod->getSourceRange(), |
| 10578 | MethodNumberParameters) |
| 10579 | << SecondMethodType << SecondName << SecondNumParameters; |
| 10580 | Diagnosed = true; |
| 10581 | break; |
| 10582 | } |
| 10583 | |
| 10584 | |
| 10585 | bool ParameterMismatch = false; |
| 10586 | for (unsigned I = 0; I < FirstNumParameters; ++I) { |
| 10587 | const ParmVarDecl *FirstParam = FirstMethod->getParamDecl(I); |
| 10588 | const ParmVarDecl *SecondParam = SecondMethod->getParamDecl(I); |
| 10589 | |
| 10590 | QualType FirstParamType = FirstParam->getType(); |
| 10591 | QualType SecondParamType = SecondParam->getType(); |
| 10592 | if (FirstParamType != SecondParamType && |
| 10593 | ComputeQualTypeODRHash(FirstParamType) != |
| 10594 | ComputeQualTypeODRHash(SecondParamType)) { |
| 10595 | if (const DecayedType *ParamDecayedType = |
| 10596 | FirstParamType->getAs<DecayedType>()) { |
| 10597 | ODRDiagDeclError( |
| 10598 | FirstRecord, FirstModule, FirstMethod->getLocation(), |
| 10599 | FirstMethod->getSourceRange(), MethodParameterType) |
| 10600 | << FirstMethodType << FirstName << (I + 1) << FirstParamType |
| 10601 | << true << ParamDecayedType->getOriginalType(); |
| 10602 | } else { |
| 10603 | ODRDiagDeclError( |
| 10604 | FirstRecord, FirstModule, FirstMethod->getLocation(), |
| 10605 | FirstMethod->getSourceRange(), MethodParameterType) |
| 10606 | << FirstMethodType << FirstName << (I + 1) << FirstParamType |
| 10607 | << false; |
| 10608 | } |
| 10609 | |
| 10610 | if (const DecayedType *ParamDecayedType = |
| 10611 | SecondParamType->getAs<DecayedType>()) { |
| 10612 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10613 | SecondMethod->getSourceRange(), |
| 10614 | MethodParameterType) |
| 10615 | << SecondMethodType << SecondName << (I + 1) |
| 10616 | << SecondParamType << true |
| 10617 | << ParamDecayedType->getOriginalType(); |
| 10618 | } else { |
| 10619 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10620 | SecondMethod->getSourceRange(), |
| 10621 | MethodParameterType) |
| 10622 | << SecondMethodType << SecondName << (I + 1) |
| 10623 | << SecondParamType << false; |
| 10624 | } |
| 10625 | ParameterMismatch = true; |
| 10626 | break; |
| 10627 | } |
| 10628 | |
| 10629 | DeclarationName FirstParamName = FirstParam->getDeclName(); |
| 10630 | DeclarationName SecondParamName = SecondParam->getDeclName(); |
| 10631 | if (FirstParamName != SecondParamName) { |
| 10632 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 10633 | FirstMethod->getLocation(), |
| 10634 | FirstMethod->getSourceRange(), MethodParameterName) |
| 10635 | << FirstMethodType << FirstName << (I + 1) << FirstParamName; |
| 10636 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10637 | SecondMethod->getSourceRange(), MethodParameterName) |
| 10638 | << SecondMethodType << SecondName << (I + 1) << SecondParamName; |
| 10639 | ParameterMismatch = true; |
| 10640 | break; |
| 10641 | } |
| 10642 | |
| 10643 | const Expr *FirstInit = FirstParam->getInit(); |
| 10644 | const Expr *SecondInit = SecondParam->getInit(); |
| 10645 | if ((FirstInit == nullptr) != (SecondInit == nullptr)) { |
| 10646 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 10647 | FirstMethod->getLocation(), |
| 10648 | FirstMethod->getSourceRange(), |
| 10649 | MethodParameterSingleDefaultArgument) |
| 10650 | << FirstMethodType << FirstName << (I + 1) |
| 10651 | << (FirstInit == nullptr) |
| 10652 | << (FirstInit ? FirstInit->getSourceRange() : SourceRange()); |
| 10653 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10654 | SecondMethod->getSourceRange(), |
| 10655 | MethodParameterSingleDefaultArgument) |
| 10656 | << SecondMethodType << SecondName << (I + 1) |
| 10657 | << (SecondInit == nullptr) |
| 10658 | << (SecondInit ? SecondInit->getSourceRange() : SourceRange()); |
| 10659 | ParameterMismatch = true; |
| 10660 | break; |
| 10661 | } |
| 10662 | |
| 10663 | if (FirstInit && SecondInit && |
| 10664 | ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) { |
| 10665 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 10666 | FirstMethod->getLocation(), |
| 10667 | FirstMethod->getSourceRange(), |
| 10668 | MethodParameterDifferentDefaultArgument) |
| 10669 | << FirstMethodType << FirstName << (I + 1) |
| 10670 | << FirstInit->getSourceRange(); |
| 10671 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10672 | SecondMethod->getSourceRange(), |
| 10673 | MethodParameterDifferentDefaultArgument) |
| 10674 | << SecondMethodType << SecondName << (I + 1) |
| 10675 | << SecondInit->getSourceRange(); |
| 10676 | ParameterMismatch = true; |
| 10677 | break; |
| 10678 | |
| 10679 | } |
| 10680 | } |
| 10681 | |
| 10682 | if (ParameterMismatch) { |
| 10683 | Diagnosed = true; |
| 10684 | break; |
| 10685 | } |
| 10686 | |
| 10687 | const auto *FirstTemplateArgs = |
| 10688 | FirstMethod->getTemplateSpecializationArgs(); |
| 10689 | const auto *SecondTemplateArgs = |
| 10690 | SecondMethod->getTemplateSpecializationArgs(); |
| 10691 | |
| 10692 | if ((FirstTemplateArgs && !SecondTemplateArgs) || |
| 10693 | (!FirstTemplateArgs && SecondTemplateArgs)) { |
| 10694 | ODRDiagDeclError(FirstRecord, FirstModule, FirstMethod->getLocation(), |
| 10695 | FirstMethod->getSourceRange(), |
| 10696 | MethodNoTemplateArguments) |
| 10697 | << FirstMethodType << FirstName << (FirstTemplateArgs != nullptr); |
| 10698 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10699 | SecondMethod->getSourceRange(), |
| 10700 | MethodNoTemplateArguments) |
| 10701 | << SecondMethodType << SecondName |
| 10702 | << (SecondTemplateArgs != nullptr); |
| 10703 | |
| 10704 | Diagnosed = true; |
| 10705 | break; |
| 10706 | } |
| 10707 | |
| 10708 | if (FirstTemplateArgs && SecondTemplateArgs) { |
| 10709 | |
| 10710 | auto ExpandTemplateArgumentList = |
| 10711 | [](const TemplateArgumentList *TAL) { |
| 10712 | llvm::SmallVector<const TemplateArgument *, 8> ExpandedList; |
| 10713 | for (const TemplateArgument &TA : TAL->asArray()) { |
| 10714 | if (TA.getKind() != TemplateArgument::Pack) { |
| 10715 | ExpandedList.push_back(&TA); |
| 10716 | continue; |
| 10717 | } |
| 10718 | for (const TemplateArgument &PackTA : TA.getPackAsArray()) { |
| 10719 | ExpandedList.push_back(&PackTA); |
| 10720 | } |
| 10721 | } |
| 10722 | return ExpandedList; |
| 10723 | }; |
| 10724 | llvm::SmallVector<const TemplateArgument *, 8> FirstExpandedList = |
| 10725 | ExpandTemplateArgumentList(FirstTemplateArgs); |
| 10726 | llvm::SmallVector<const TemplateArgument *, 8> SecondExpandedList = |
| 10727 | ExpandTemplateArgumentList(SecondTemplateArgs); |
| 10728 | |
| 10729 | if (FirstExpandedList.size() != SecondExpandedList.size()) { |
| 10730 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 10731 | FirstMethod->getLocation(), |
| 10732 | FirstMethod->getSourceRange(), |
| 10733 | MethodDifferentNumberTemplateArguments) |
| 10734 | << FirstMethodType << FirstName |
| 10735 | << (unsigned)FirstExpandedList.size(); |
| 10736 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10737 | SecondMethod->getSourceRange(), |
| 10738 | MethodDifferentNumberTemplateArguments) |
| 10739 | << SecondMethodType << SecondName |
| 10740 | << (unsigned)SecondExpandedList.size(); |
| 10741 | |
| 10742 | Diagnosed = true; |
| 10743 | break; |
| 10744 | } |
| 10745 | |
| 10746 | bool TemplateArgumentMismatch = false; |
| 10747 | for (unsigned i = 0, e = FirstExpandedList.size(); i != e; ++i) { |
| 10748 | const TemplateArgument &FirstTA = *FirstExpandedList[i], |
| 10749 | &SecondTA = *SecondExpandedList[i]; |
| 10750 | if (ComputeTemplateArgumentODRHash(FirstTA) == |
| 10751 | ComputeTemplateArgumentODRHash(SecondTA)) { |
| 10752 | continue; |
| 10753 | } |
| 10754 | |
| 10755 | ODRDiagDeclError( |
| 10756 | FirstRecord, FirstModule, FirstMethod->getLocation(), |
| 10757 | FirstMethod->getSourceRange(), MethodDifferentTemplateArgument) |
| 10758 | << FirstMethodType << FirstName << FirstTA << i + 1; |
| 10759 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10760 | SecondMethod->getSourceRange(), |
| 10761 | MethodDifferentTemplateArgument) |
| 10762 | << SecondMethodType << SecondName << SecondTA << i + 1; |
| 10763 | |
| 10764 | TemplateArgumentMismatch = true; |
| 10765 | break; |
| 10766 | } |
| 10767 | |
| 10768 | if (TemplateArgumentMismatch) { |
| 10769 | Diagnosed = true; |
| 10770 | break; |
| 10771 | } |
| 10772 | } |
| 10773 | |
| 10774 | |
| 10775 | auto ComputeCXXMethodODRHash = [&Hash](const CXXMethodDecl *D) { |
| 10776 | Hash.clear(); |
| 10777 | Hash.AddFunctionDecl(D, true ); |
| 10778 | return Hash.CalculateHash(); |
| 10779 | }; |
| 10780 | |
| 10781 | |
| 10782 | |
| 10783 | |
| 10784 | const bool HasFirstBody = |
| 10785 | ComputeCXXMethodODRHash(FirstMethod) != FirstMethod->getODRHash(); |
| 10786 | const bool HasSecondBody = |
| 10787 | ComputeCXXMethodODRHash(SecondMethod) != SecondMethod->getODRHash(); |
| 10788 | |
| 10789 | if (HasFirstBody != HasSecondBody) { |
| 10790 | ODRDiagDeclError(FirstRecord, FirstModule, FirstMethod->getLocation(), |
| 10791 | FirstMethod->getSourceRange(), MethodSingleBody) |
| 10792 | << FirstMethodType << FirstName << HasFirstBody; |
| 10793 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10794 | SecondMethod->getSourceRange(), MethodSingleBody) |
| 10795 | << SecondMethodType << SecondName << HasSecondBody; |
| 10796 | Diagnosed = true; |
| 10797 | break; |
| 10798 | } |
| 10799 | |
| 10800 | if (HasFirstBody && HasSecondBody) { |
| 10801 | ODRDiagDeclError(FirstRecord, FirstModule, FirstMethod->getLocation(), |
| 10802 | FirstMethod->getSourceRange(), MethodDifferentBody) |
| 10803 | << FirstMethodType << FirstName; |
| 10804 | ODRDiagDeclNote(SecondModule, SecondMethod->getLocation(), |
| 10805 | SecondMethod->getSourceRange(), MethodDifferentBody) |
| 10806 | << SecondMethodType << SecondName; |
| 10807 | Diagnosed = true; |
| 10808 | break; |
| 10809 | } |
| 10810 | |
| 10811 | break; |
| 10812 | } |
| 10813 | case TypeAlias: |
| 10814 | case TypeDef: { |
| 10815 | Diagnosed = ODRDiagTypeDefOrAlias( |
| 10816 | FirstRecord, FirstModule, SecondModule, |
| 10817 | cast<TypedefNameDecl>(FirstDecl), cast<TypedefNameDecl>(SecondDecl), |
| 10818 | FirstDiffType == TypeAlias); |
| 10819 | break; |
| 10820 | } |
| 10821 | case Var: { |
| 10822 | Diagnosed = |
| 10823 | ODRDiagVar(FirstRecord, FirstModule, SecondModule, |
| 10824 | cast<VarDecl>(FirstDecl), cast<VarDecl>(SecondDecl)); |
| 10825 | break; |
| 10826 | } |
| 10827 | case Friend: { |
| 10828 | FriendDecl *FirstFriend = cast<FriendDecl>(FirstDecl); |
| 10829 | FriendDecl *SecondFriend = cast<FriendDecl>(SecondDecl); |
| 10830 | |
| 10831 | NamedDecl *FirstND = FirstFriend->getFriendDecl(); |
| 10832 | NamedDecl *SecondND = SecondFriend->getFriendDecl(); |
| 10833 | |
| 10834 | TypeSourceInfo *FirstTSI = FirstFriend->getFriendType(); |
| 10835 | TypeSourceInfo *SecondTSI = SecondFriend->getFriendType(); |
| 10836 | |
| 10837 | if (FirstND && SecondND) { |
| 10838 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 10839 | FirstFriend->getFriendLoc(), |
| 10840 | FirstFriend->getSourceRange(), FriendFunction) |
| 10841 | << FirstND; |
| 10842 | ODRDiagDeclNote(SecondModule, SecondFriend->getFriendLoc(), |
| 10843 | SecondFriend->getSourceRange(), FriendFunction) |
| 10844 | << SecondND; |
| 10845 | |
| 10846 | Diagnosed = true; |
| 10847 | break; |
| 10848 | } |
| 10849 | |
| 10850 | if (FirstTSI && SecondTSI) { |
| 10851 | QualType FirstFriendType = FirstTSI->getType(); |
| 10852 | QualType SecondFriendType = SecondTSI->getType(); |
| 10853 | assert(ComputeQualTypeODRHash(FirstFriendType) != |
| 10854 | ComputeQualTypeODRHash(SecondFriendType)); |
| 10855 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 10856 | FirstFriend->getFriendLoc(), |
| 10857 | FirstFriend->getSourceRange(), FriendType) |
| 10858 | << FirstFriendType; |
| 10859 | ODRDiagDeclNote(SecondModule, SecondFriend->getFriendLoc(), |
| 10860 | SecondFriend->getSourceRange(), FriendType) |
| 10861 | << SecondFriendType; |
| 10862 | Diagnosed = true; |
| 10863 | break; |
| 10864 | } |
| 10865 | |
| 10866 | ODRDiagDeclError(FirstRecord, FirstModule, FirstFriend->getFriendLoc(), |
| 10867 | FirstFriend->getSourceRange(), FriendTypeFunction) |
| 10868 | << (FirstTSI == nullptr); |
| 10869 | ODRDiagDeclNote(SecondModule, SecondFriend->getFriendLoc(), |
| 10870 | SecondFriend->getSourceRange(), FriendTypeFunction) |
| 10871 | << (SecondTSI == nullptr); |
| 10872 | |
| 10873 | Diagnosed = true; |
| 10874 | break; |
| 10875 | } |
| 10876 | case FunctionTemplate: { |
| 10877 | FunctionTemplateDecl *FirstTemplate = |
| 10878 | cast<FunctionTemplateDecl>(FirstDecl); |
| 10879 | FunctionTemplateDecl *SecondTemplate = |
| 10880 | cast<FunctionTemplateDecl>(SecondDecl); |
| 10881 | |
| 10882 | TemplateParameterList *FirstTPL = |
| 10883 | FirstTemplate->getTemplateParameters(); |
| 10884 | TemplateParameterList *SecondTPL = |
| 10885 | SecondTemplate->getTemplateParameters(); |
| 10886 | |
| 10887 | if (FirstTPL->size() != SecondTPL->size()) { |
| 10888 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 10889 | FirstTemplate->getLocation(), |
| 10890 | FirstTemplate->getSourceRange(), |
| 10891 | FunctionTemplateDifferentNumberParameters) |
| 10892 | << FirstTemplate << FirstTPL->size(); |
| 10893 | ODRDiagDeclNote(SecondModule, SecondTemplate->getLocation(), |
| 10894 | SecondTemplate->getSourceRange(), |
| 10895 | FunctionTemplateDifferentNumberParameters) |
| 10896 | << SecondTemplate << SecondTPL->size(); |
| 10897 | |
| 10898 | Diagnosed = true; |
| 10899 | break; |
| 10900 | } |
| 10901 | |
| 10902 | bool ParameterMismatch = false; |
| 10903 | for (unsigned i = 0, e = FirstTPL->size(); i != e; ++i) { |
| 10904 | NamedDecl *FirstParam = FirstTPL->getParam(i); |
| 10905 | NamedDecl *SecondParam = SecondTPL->getParam(i); |
| 10906 | |
| 10907 | if (FirstParam->getKind() != SecondParam->getKind()) { |
| 10908 | enum { |
| 10909 | TemplateTypeParameter, |
| 10910 | NonTypeTemplateParameter, |
| 10911 | TemplateTemplateParameter, |
| 10912 | }; |
| 10913 | auto GetParamType = [](NamedDecl *D) { |
| 10914 | switch (D->getKind()) { |
| 10915 | default: |
| 10916 | llvm_unreachable("Unexpected template parameter type"); |
| 10917 | case Decl::TemplateTypeParm: |
| 10918 | return TemplateTypeParameter; |
| 10919 | case Decl::NonTypeTemplateParm: |
| 10920 | return NonTypeTemplateParameter; |
| 10921 | case Decl::TemplateTemplateParm: |
| 10922 | return TemplateTemplateParameter; |
| 10923 | } |
| 10924 | }; |
| 10925 | |
| 10926 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 10927 | FirstTemplate->getLocation(), |
| 10928 | FirstTemplate->getSourceRange(), |
| 10929 | FunctionTemplateParameterDifferentKind) |
| 10930 | << FirstTemplate << (i + 1) << GetParamType(FirstParam); |
| 10931 | ODRDiagDeclNote(SecondModule, SecondTemplate->getLocation(), |
| 10932 | SecondTemplate->getSourceRange(), |
| 10933 | FunctionTemplateParameterDifferentKind) |
| 10934 | << SecondTemplate << (i + 1) << GetParamType(SecondParam); |
| 10935 | |
| 10936 | ParameterMismatch = true; |
| 10937 | break; |
| 10938 | } |
| 10939 | |
| 10940 | if (FirstParam->getName() != SecondParam->getName()) { |
| 10941 | ODRDiagDeclError( |
| 10942 | FirstRecord, FirstModule, FirstTemplate->getLocation(), |
| 10943 | FirstTemplate->getSourceRange(), FunctionTemplateParameterName) |
| 10944 | << FirstTemplate << (i + 1) << (bool)FirstParam->getIdentifier() |
| 10945 | << FirstParam; |
| 10946 | ODRDiagDeclNote(SecondModule, SecondTemplate->getLocation(), |
| 10947 | SecondTemplate->getSourceRange(), |
| 10948 | FunctionTemplateParameterName) |
| 10949 | << SecondTemplate << (i + 1) |
| 10950 | << (bool)SecondParam->getIdentifier() << SecondParam; |
| 10951 | ParameterMismatch = true; |
| 10952 | break; |
| 10953 | } |
| 10954 | |
| 10955 | if (isa<TemplateTypeParmDecl>(FirstParam) && |
| 10956 | isa<TemplateTypeParmDecl>(SecondParam)) { |
| 10957 | TemplateTypeParmDecl *FirstTTPD = |
| 10958 | cast<TemplateTypeParmDecl>(FirstParam); |
| 10959 | TemplateTypeParmDecl *SecondTTPD = |
| 10960 | cast<TemplateTypeParmDecl>(SecondParam); |
| 10961 | bool HasFirstDefaultArgument = |
| 10962 | FirstTTPD->hasDefaultArgument() && |
| 10963 | !FirstTTPD->defaultArgumentWasInherited(); |
| 10964 | bool HasSecondDefaultArgument = |
| 10965 | SecondTTPD->hasDefaultArgument() && |
| 10966 | !SecondTTPD->defaultArgumentWasInherited(); |
| 10967 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 10968 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 10969 | FirstTemplate->getLocation(), |
| 10970 | FirstTemplate->getSourceRange(), |
| 10971 | FunctionTemplateParameterSingleDefaultArgument) |
| 10972 | << FirstTemplate << (i + 1) << HasFirstDefaultArgument; |
| 10973 | ODRDiagDeclNote(SecondModule, 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 | ODRDiagDeclError( |
| 10987 | FirstRecord, FirstModule, FirstTemplate->getLocation(), |
| 10988 | FirstTemplate->getSourceRange(), |
| 10989 | FunctionTemplateParameterDifferentDefaultArgument) |
| 10990 | << FirstTemplate << (i + 1) << FirstType; |
| 10991 | ODRDiagDeclNote( |
| 10992 | SecondModule, SecondTemplate->getLocation(), |
| 10993 | SecondTemplate->getSourceRange(), |
| 10994 | FunctionTemplateParameterDifferentDefaultArgument) |
| 10995 | << SecondTemplate << (i + 1) << SecondType; |
| 10996 | ParameterMismatch = true; |
| 10997 | break; |
| 10998 | } |
| 10999 | } |
| 11000 | |
| 11001 | if (FirstTTPD->isParameterPack() != |
| 11002 | SecondTTPD->isParameterPack()) { |
| 11003 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 11004 | FirstTemplate->getLocation(), |
| 11005 | FirstTemplate->getSourceRange(), |
| 11006 | FunctionTemplatePackParameter) |
| 11007 | << FirstTemplate << (i + 1) << FirstTTPD->isParameterPack(); |
| 11008 | ODRDiagDeclNote(SecondModule, SecondTemplate->getLocation(), |
| 11009 | SecondTemplate->getSourceRange(), |
| 11010 | FunctionTemplatePackParameter) |
| 11011 | << SecondTemplate << (i + 1) << SecondTTPD->isParameterPack(); |
| 11012 | ParameterMismatch = true; |
| 11013 | break; |
| 11014 | } |
| 11015 | } |
| 11016 | |
| 11017 | if (isa<TemplateTemplateParmDecl>(FirstParam) && |
| 11018 | isa<TemplateTemplateParmDecl>(SecondParam)) { |
| 11019 | TemplateTemplateParmDecl *FirstTTPD = |
| 11020 | cast<TemplateTemplateParmDecl>(FirstParam); |
| 11021 | TemplateTemplateParmDecl *SecondTTPD = |
| 11022 | cast<TemplateTemplateParmDecl>(SecondParam); |
| 11023 | |
| 11024 | TemplateParameterList *FirstTPL = |
| 11025 | FirstTTPD->getTemplateParameters(); |
| 11026 | TemplateParameterList *SecondTPL = |
| 11027 | SecondTTPD->getTemplateParameters(); |
| 11028 | |
| 11029 | if (ComputeTemplateParameterListODRHash(FirstTPL) != |
| 11030 | ComputeTemplateParameterListODRHash(SecondTPL)) { |
| 11031 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 11032 | FirstTemplate->getLocation(), |
| 11033 | FirstTemplate->getSourceRange(), |
| 11034 | FunctionTemplateParameterDifferentType) |
| 11035 | << FirstTemplate << (i + 1); |
| 11036 | ODRDiagDeclNote(SecondModule, SecondTemplate->getLocation(), |
| 11037 | SecondTemplate->getSourceRange(), |
| 11038 | FunctionTemplateParameterDifferentType) |
| 11039 | << SecondTemplate << (i + 1); |
| 11040 | ParameterMismatch = true; |
| 11041 | break; |
| 11042 | } |
| 11043 | |
| 11044 | bool HasFirstDefaultArgument = |
| 11045 | FirstTTPD->hasDefaultArgument() && |
| 11046 | !FirstTTPD->defaultArgumentWasInherited(); |
| 11047 | bool HasSecondDefaultArgument = |
| 11048 | SecondTTPD->hasDefaultArgument() && |
| 11049 | !SecondTTPD->defaultArgumentWasInherited(); |
| 11050 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 11051 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 11052 | FirstTemplate->getLocation(), |
| 11053 | FirstTemplate->getSourceRange(), |
| 11054 | FunctionTemplateParameterSingleDefaultArgument) |
| 11055 | << FirstTemplate << (i + 1) << HasFirstDefaultArgument; |
| 11056 | ODRDiagDeclNote(SecondModule, SecondTemplate->getLocation(), |
| 11057 | SecondTemplate->getSourceRange(), |
| 11058 | FunctionTemplateParameterSingleDefaultArgument) |
| 11059 | << SecondTemplate << (i + 1) << HasSecondDefaultArgument; |
| 11060 | ParameterMismatch = true; |
| 11061 | break; |
| 11062 | } |
| 11063 | |
| 11064 | if (HasFirstDefaultArgument && HasSecondDefaultArgument) { |
| 11065 | TemplateArgument FirstTA = |
| 11066 | FirstTTPD->getDefaultArgument().getArgument(); |
| 11067 | TemplateArgument SecondTA = |
| 11068 | SecondTTPD->getDefaultArgument().getArgument(); |
| 11069 | if (ComputeTemplateArgumentODRHash(FirstTA) != |
| 11070 | ComputeTemplateArgumentODRHash(SecondTA)) { |
| 11071 | ODRDiagDeclError( |
| 11072 | FirstRecord, FirstModule, FirstTemplate->getLocation(), |
| 11073 | FirstTemplate->getSourceRange(), |
| 11074 | FunctionTemplateParameterDifferentDefaultArgument) |
| 11075 | << FirstTemplate << (i + 1) << FirstTA; |
| 11076 | ODRDiagDeclNote( |
| 11077 | SecondModule, SecondTemplate->getLocation(), |
| 11078 | SecondTemplate->getSourceRange(), |
| 11079 | FunctionTemplateParameterDifferentDefaultArgument) |
| 11080 | << SecondTemplate << (i + 1) << SecondTA; |
| 11081 | ParameterMismatch = true; |
| 11082 | break; |
| 11083 | } |
| 11084 | } |
| 11085 | |
| 11086 | if (FirstTTPD->isParameterPack() != |
| 11087 | SecondTTPD->isParameterPack()) { |
| 11088 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 11089 | FirstTemplate->getLocation(), |
| 11090 | FirstTemplate->getSourceRange(), |
| 11091 | FunctionTemplatePackParameter) |
| 11092 | << FirstTemplate << (i + 1) << FirstTTPD->isParameterPack(); |
| 11093 | ODRDiagDeclNote(SecondModule, SecondTemplate->getLocation(), |
| 11094 | SecondTemplate->getSourceRange(), |
| 11095 | FunctionTemplatePackParameter) |
| 11096 | << SecondTemplate << (i + 1) << SecondTTPD->isParameterPack(); |
| 11097 | ParameterMismatch = true; |
| 11098 | break; |
| 11099 | } |
| 11100 | } |
| 11101 | |
| 11102 | if (isa<NonTypeTemplateParmDecl>(FirstParam) && |
| 11103 | isa<NonTypeTemplateParmDecl>(SecondParam)) { |
| 11104 | NonTypeTemplateParmDecl *FirstNTTPD = |
| 11105 | cast<NonTypeTemplateParmDecl>(FirstParam); |
| 11106 | NonTypeTemplateParmDecl *SecondNTTPD = |
| 11107 | cast<NonTypeTemplateParmDecl>(SecondParam); |
| 11108 | |
| 11109 | QualType FirstType = FirstNTTPD->getType(); |
| 11110 | QualType SecondType = SecondNTTPD->getType(); |
| 11111 | if (ComputeQualTypeODRHash(FirstType) != |
| 11112 | ComputeQualTypeODRHash(SecondType)) { |
| 11113 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 11114 | FirstTemplate->getLocation(), |
| 11115 | FirstTemplate->getSourceRange(), |
| 11116 | FunctionTemplateParameterDifferentType) |
| 11117 | << FirstTemplate << (i + 1); |
| 11118 | ODRDiagDeclNote(SecondModule, SecondTemplate->getLocation(), |
| 11119 | SecondTemplate->getSourceRange(), |
| 11120 | FunctionTemplateParameterDifferentType) |
| 11121 | << SecondTemplate << (i + 1); |
| 11122 | ParameterMismatch = true; |
| 11123 | break; |
| 11124 | } |
| 11125 | |
| 11126 | bool HasFirstDefaultArgument = |
| 11127 | FirstNTTPD->hasDefaultArgument() && |
| 11128 | !FirstNTTPD->defaultArgumentWasInherited(); |
| 11129 | bool HasSecondDefaultArgument = |
| 11130 | SecondNTTPD->hasDefaultArgument() && |
| 11131 | !SecondNTTPD->defaultArgumentWasInherited(); |
| 11132 | if (HasFirstDefaultArgument != HasSecondDefaultArgument) { |
| 11133 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 11134 | FirstTemplate->getLocation(), |
| 11135 | FirstTemplate->getSourceRange(), |
| 11136 | FunctionTemplateParameterSingleDefaultArgument) |
| 11137 | << FirstTemplate << (i + 1) << HasFirstDefaultArgument; |
| 11138 | ODRDiagDeclNote(SecondModule, SecondTemplate->getLocation(), |
| 11139 | SecondTemplate->getSourceRange(), |
| 11140 | FunctionTemplateParameterSingleDefaultArgument) |
| 11141 | << SecondTemplate << (i + 1) << HasSecondDefaultArgument; |
| 11142 | ParameterMismatch = true; |
| 11143 | break; |
| 11144 | } |
| 11145 | |
| 11146 | if (HasFirstDefaultArgument && HasSecondDefaultArgument) { |
| 11147 | Expr *FirstDefaultArgument = FirstNTTPD->getDefaultArgument(); |
| 11148 | Expr *SecondDefaultArgument = SecondNTTPD->getDefaultArgument(); |
| 11149 | if (ComputeODRHash(FirstDefaultArgument) != |
| 11150 | ComputeODRHash(SecondDefaultArgument)) { |
| 11151 | ODRDiagDeclError( |
| 11152 | FirstRecord, FirstModule, FirstTemplate->getLocation(), |
| 11153 | FirstTemplate->getSourceRange(), |
| 11154 | FunctionTemplateParameterDifferentDefaultArgument) |
| 11155 | << FirstTemplate << (i + 1) << FirstDefaultArgument; |
| 11156 | ODRDiagDeclNote( |
| 11157 | SecondModule, SecondTemplate->getLocation(), |
| 11158 | SecondTemplate->getSourceRange(), |
| 11159 | FunctionTemplateParameterDifferentDefaultArgument) |
| 11160 | << SecondTemplate << (i + 1) << SecondDefaultArgument; |
| 11161 | ParameterMismatch = true; |
| 11162 | break; |
| 11163 | } |
| 11164 | } |
| 11165 | |
| 11166 | if (FirstNTTPD->isParameterPack() != |
| 11167 | SecondNTTPD->isParameterPack()) { |
| 11168 | ODRDiagDeclError(FirstRecord, FirstModule, |
| 11169 | FirstTemplate->getLocation(), |
| 11170 | FirstTemplate->getSourceRange(), |
| 11171 | FunctionTemplatePackParameter) |
| 11172 | << FirstTemplate << (i + 1) << FirstNTTPD->isParameterPack(); |
| 11173 | ODRDiagDeclNote(SecondModule, SecondTemplate->getLocation(), |
| 11174 | SecondTemplate->getSourceRange(), |
| 11175 | FunctionTemplatePackParameter) |
| 11176 | << SecondTemplate << (i + 1) |
| 11177 | << SecondNTTPD->isParameterPack(); |
| 11178 | ParameterMismatch = true; |
| 11179 | break; |
| 11180 | } |
| 11181 | } |
| 11182 | } |
| 11183 | |
| 11184 | if (ParameterMismatch) { |
| 11185 | Diagnosed = true; |
| 11186 | break; |
| 11187 | } |
| 11188 | |
| 11189 | break; |
| 11190 | } |
| 11191 | } |
| 11192 | |
| 11193 | if (Diagnosed) |
| 11194 | continue; |
| 11195 | |
| 11196 | Diag(FirstDecl->getLocation(), |
| 11197 | diag::err_module_odr_violation_mismatch_decl_unknown) |
| 11198 | << FirstRecord << FirstModule.empty() << FirstModule << FirstDiffType |
| 11199 | << FirstDecl->getSourceRange(); |
| 11200 | Diag(SecondDecl->getLocation(), |
| 11201 | diag::note_module_odr_violation_mismatch_decl_unknown) |
| 11202 | << SecondModule << FirstDiffType << SecondDecl->getSourceRange(); |
| 11203 | Diagnosed = true; |
| 11204 | } |
| 11205 | |
| 11206 | if (!Diagnosed) { |
| 11207 | |
| 11208 | |
| 11209 | |
| 11210 | |
| 11211 | |
| 11212 | |
| 11213 | Diag(Merge.first->getLocation(), |
| 11214 | diag::err_module_odr_violation_different_instantiations) |
| 11215 | << Merge.first; |
| 11216 | } |
| 11217 | } |
| 11218 | |
| 11219 | |
| 11220 | for (auto &Merge : FunctionOdrMergeFailures) { |
| 11221 | enum ODRFunctionDifference { |
| 11222 | ReturnType, |
| 11223 | ParameterName, |
| 11224 | ParameterType, |
| 11225 | ParameterSingleDefaultArgument, |
| 11226 | ParameterDifferentDefaultArgument, |
| 11227 | FunctionBody, |
| 11228 | }; |
| 11229 | |
| 11230 | FunctionDecl *FirstFunction = Merge.first; |
| 11231 | std::string FirstModule = getOwningModuleNameForDiagnostic(FirstFunction); |
| 11232 | |
| 11233 | bool Diagnosed = false; |
| 11234 | for (auto &SecondFunction : Merge.second) { |
| 11235 | |
| 11236 | if (FirstFunction == SecondFunction) |
| 11237 | continue; |
| 11238 | |
| 11239 | std::string SecondModule = |
| 11240 | getOwningModuleNameForDiagnostic(SecondFunction); |
| 11241 | |
| 11242 | auto ODRDiagError = [FirstFunction, &FirstModule, |
| 11243 | this](SourceLocation Loc, SourceRange Range, |
| 11244 | ODRFunctionDifference DiffType) { |
| 11245 | return Diag(Loc, diag::err_module_odr_violation_function) |
| 11246 | << FirstFunction << FirstModule.empty() << FirstModule << Range |
| 11247 | << DiffType; |
| 11248 | }; |
| 11249 | auto ODRDiagNote = [&SecondModule, this](SourceLocation Loc, |
| 11250 | SourceRange Range, |
| 11251 | ODRFunctionDifference DiffType) { |
| 11252 | return Diag(Loc, diag::note_module_odr_violation_function) |
| 11253 | << SecondModule << Range << DiffType; |
| 11254 | }; |
| 11255 | |
| 11256 | if (ComputeQualTypeODRHash(FirstFunction->getReturnType()) != |
| 11257 | ComputeQualTypeODRHash(SecondFunction->getReturnType())) { |
| 11258 | ODRDiagError(FirstFunction->getReturnTypeSourceRange().getBegin(), |
| 11259 | FirstFunction->getReturnTypeSourceRange(), ReturnType) |
| 11260 | << FirstFunction->getReturnType(); |
| 11261 | ODRDiagNote(SecondFunction->getReturnTypeSourceRange().getBegin(), |
| 11262 | SecondFunction->getReturnTypeSourceRange(), ReturnType) |
| 11263 | << SecondFunction->getReturnType(); |
| 11264 | Diagnosed = true; |
| 11265 | break; |
| 11266 | } |
| 11267 | |
| 11268 | assert(FirstFunction->param_size() == SecondFunction->param_size() && |
| 11269 | "Merged functions with different number of parameters"); |
| 11270 | |
| 11271 | auto ParamSize = FirstFunction->param_size(); |
| 11272 | bool ParameterMismatch = false; |
| 11273 | for (unsigned I = 0; I < ParamSize; ++I) { |
| 11274 | auto *FirstParam = FirstFunction->getParamDecl(I); |
| 11275 | auto *SecondParam = SecondFunction->getParamDecl(I); |
| 11276 | |
| 11277 | assert(getContext().hasSameType(FirstParam->getType(), |
| 11278 | SecondParam->getType()) && |
| 11279 | "Merged function has different parameter types."); |
| 11280 | |
| 11281 | if (FirstParam->getDeclName() != SecondParam->getDeclName()) { |
| 11282 | ODRDiagError(FirstParam->getLocation(), FirstParam->getSourceRange(), |
| 11283 | ParameterName) |
| 11284 | << I + 1 << FirstParam->getDeclName(); |
| 11285 | ODRDiagNote(SecondParam->getLocation(), SecondParam->getSourceRange(), |
| 11286 | ParameterName) |
| 11287 | << I + 1 << SecondParam->getDeclName(); |
| 11288 | ParameterMismatch = true; |
| 11289 | break; |
| 11290 | }; |
| 11291 | |
| 11292 | QualType FirstParamType = FirstParam->getType(); |
| 11293 | QualType SecondParamType = SecondParam->getType(); |
| 11294 | if (FirstParamType != SecondParamType && |
| 11295 | ComputeQualTypeODRHash(FirstParamType) != |
| 11296 | ComputeQualTypeODRHash(SecondParamType)) { |
| 11297 | if (const DecayedType *ParamDecayedType = |
| 11298 | FirstParamType->getAs<DecayedType>()) { |
| 11299 | ODRDiagError(FirstParam->getLocation(), |
| 11300 | FirstParam->getSourceRange(), ParameterType) |
| 11301 | << (I + 1) << FirstParamType << true |
| 11302 | << ParamDecayedType->getOriginalType(); |
| 11303 | } else { |
| 11304 | ODRDiagError(FirstParam->getLocation(), |
| 11305 | FirstParam->getSourceRange(), ParameterType) |
| 11306 | << (I + 1) << FirstParamType << false; |
| 11307 | } |
| 11308 | |
| 11309 | if (const DecayedType *ParamDecayedType = |
| 11310 | SecondParamType->getAs<DecayedType>()) { |
| 11311 | ODRDiagNote(SecondParam->getLocation(), |
| 11312 | SecondParam->getSourceRange(), ParameterType) |
| 11313 | << (I + 1) << SecondParamType << true |
| 11314 | << ParamDecayedType->getOriginalType(); |
| 11315 | } else { |
| 11316 | ODRDiagNote(SecondParam->getLocation(), |
| 11317 | SecondParam->getSourceRange(), ParameterType) |
| 11318 | << (I + 1) << SecondParamType << false; |
| 11319 | } |
| 11320 | ParameterMismatch = true; |
| 11321 | break; |
| 11322 | } |
| 11323 | |
| 11324 | const Expr *FirstInit = FirstParam->getInit(); |
| 11325 | const Expr *SecondInit = SecondParam->getInit(); |
| 11326 | if ((FirstInit == nullptr) != (SecondInit == nullptr)) { |
| 11327 | ODRDiagError(FirstParam->getLocation(), FirstParam->getSourceRange(), |
| 11328 | ParameterSingleDefaultArgument) |
| 11329 | << (I + 1) << (FirstInit == nullptr) |
| 11330 | << (FirstInit ? FirstInit->getSourceRange() : SourceRange()); |
| 11331 | ODRDiagNote(SecondParam->getLocation(), SecondParam->getSourceRange(), |
| 11332 | ParameterSingleDefaultArgument) |
| 11333 | << (I + 1) << (SecondInit == nullptr) |
| 11334 | << (SecondInit ? SecondInit->getSourceRange() : SourceRange()); |
| 11335 | ParameterMismatch = true; |
| 11336 | break; |
| 11337 | } |
| 11338 | |
| 11339 | if (FirstInit && SecondInit && |
| 11340 | ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) { |
| 11341 | ODRDiagError(FirstParam->getLocation(), FirstParam->getSourceRange(), |
| 11342 | ParameterDifferentDefaultArgument) |
| 11343 | << (I + 1) << FirstInit->getSourceRange(); |
| 11344 | ODRDiagNote(SecondParam->getLocation(), SecondParam->getSourceRange(), |
| 11345 | ParameterDifferentDefaultArgument) |
| 11346 | << (I + 1) << SecondInit->getSourceRange(); |
| 11347 | ParameterMismatch = true; |
| 11348 | break; |
| 11349 | } |
| 11350 | |
| 11351 | assert(ComputeSubDeclODRHash(FirstParam) == |
| 11352 | ComputeSubDeclODRHash(SecondParam) && |
| 11353 | "Undiagnosed parameter difference."); |
| 11354 | } |
| 11355 | |
| 11356 | if (ParameterMismatch) { |
| 11357 | Diagnosed = true; |
| 11358 | break; |
| 11359 | } |
| 11360 | |
| 11361 | |
| 11362 | |
| 11363 | ODRDiagError(FirstFunction->getLocation(), |
| 11364 | FirstFunction->getSourceRange(), FunctionBody); |
| 11365 | ODRDiagNote(SecondFunction->getLocation(), |
| 11366 | SecondFunction->getSourceRange(), FunctionBody); |
| 11367 | Diagnosed = true; |
| 11368 | break; |
| 11369 | } |
| 11370 | (void)Diagnosed; |
| 11371 | assert(Diagnosed && "Unable to emit ODR diagnostic."); |
| 11372 | } |
| 11373 | |
| 11374 | |
| 11375 | for (auto &Merge : EnumOdrMergeFailures) { |
| 11376 | enum ODREnumDifference { |
| 11377 | SingleScopedEnum, |
| 11378 | EnumTagKeywordMismatch, |
| 11379 | SingleSpecifiedType, |
| 11380 | DifferentSpecifiedTypes, |
| 11381 | DifferentNumberEnumConstants, |
| 11382 | EnumConstantName, |
| 11383 | EnumConstantSingleInitilizer, |
| 11384 | EnumConstantDifferentInitilizer, |
| 11385 | }; |
| 11386 | |
| 11387 | |
| 11388 | |
| 11389 | if (!DiagnosedOdrMergeFailures.insert(Merge.first).second) |
| 11390 | continue; |
| 11391 | |
| 11392 | EnumDecl *FirstEnum = Merge.first; |
| 11393 | std::string FirstModule = getOwningModuleNameForDiagnostic(FirstEnum); |
| 11394 | |
| 11395 | using DeclHashes = |
| 11396 | llvm::SmallVector<std::pair<EnumConstantDecl *, unsigned>, 4>; |
| 11397 | auto PopulateHashes = [&ComputeSubDeclODRHash, FirstEnum]( |
| 11398 | DeclHashes &Hashes, EnumDecl *Enum) { |
| 11399 | for (auto *D : Enum->decls()) { |
| 11400 | |
| 11401 | |
| 11402 | if (!ODRHash::isDeclToBeProcessed(D, FirstEnum)) |
| 11403 | continue; |
| 11404 | assert(isa<EnumConstantDecl>(D) && "Unexpected Decl kind"); |
| 11405 | Hashes.emplace_back(cast<EnumConstantDecl>(D), |
| 11406 | ComputeSubDeclODRHash(D)); |
| 11407 | } |
| 11408 | }; |
| 11409 | DeclHashes FirstHashes; |
| 11410 | PopulateHashes(FirstHashes, FirstEnum); |
| 11411 | bool Diagnosed = false; |
| 11412 | for (auto &SecondEnum : Merge.second) { |
| 11413 | |
| 11414 | if (FirstEnum == SecondEnum) |
| 11415 | continue; |
| 11416 | |
| 11417 | std::string SecondModule = |
| 11418 | getOwningModuleNameForDiagnostic(SecondEnum); |
| 11419 | |
| 11420 | auto ODRDiagError = [FirstEnum, &FirstModule, |
| 11421 | this](SourceLocation Loc, SourceRange Range, |
| 11422 | ODREnumDifference DiffType) { |
| 11423 | return Diag(Loc, diag::err_module_odr_violation_enum) |
| 11424 | << FirstEnum << FirstModule.empty() << FirstModule << Range |
| 11425 | << DiffType; |
| 11426 | }; |
| 11427 | auto ODRDiagNote = [&SecondModule, this](SourceLocation Loc, |
| 11428 | SourceRange Range, |
| 11429 | ODREnumDifference DiffType) { |
| 11430 | return Diag(Loc, diag::note_module_odr_violation_enum) |
| 11431 | << SecondModule << Range << DiffType; |
| 11432 | }; |
| 11433 | |
| 11434 | if (FirstEnum->isScoped() != SecondEnum->isScoped()) { |
| 11435 | ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(), |
| 11436 | SingleScopedEnum) |
| 11437 | << FirstEnum->isScoped(); |
| 11438 | ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(), |
| 11439 | SingleScopedEnum) |
| 11440 | << SecondEnum->isScoped(); |
| 11441 | Diagnosed = true; |
| 11442 | continue; |
| 11443 | } |
| 11444 | |
| 11445 | if (FirstEnum->isScoped() && SecondEnum->isScoped()) { |
| 11446 | if (FirstEnum->isScopedUsingClassTag() != |
| 11447 | SecondEnum->isScopedUsingClassTag()) { |
| 11448 | ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(), |
| 11449 | EnumTagKeywordMismatch) |
| 11450 | << FirstEnum->isScopedUsingClassTag(); |
| 11451 | ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(), |
| 11452 | EnumTagKeywordMismatch) |
| 11453 | << SecondEnum->isScopedUsingClassTag(); |
| 11454 | Diagnosed = true; |
| 11455 | continue; |
| 11456 | } |
| 11457 | } |
| 11458 | |
| 11459 | QualType FirstUnderlyingType = |
| 11460 | FirstEnum->getIntegerTypeSourceInfo() |
| 11461 | ? FirstEnum->getIntegerTypeSourceInfo()->getType() |
| 11462 | : QualType(); |
| 11463 | QualType SecondUnderlyingType = |
| 11464 | SecondEnum->getIntegerTypeSourceInfo() |
| 11465 | ? SecondEnum->getIntegerTypeSourceInfo()->getType() |
| 11466 | : QualType(); |
| 11467 | if (FirstUnderlyingType.isNull() != SecondUnderlyingType.isNull()) { |
| 11468 | ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(), |
| 11469 | SingleSpecifiedType) |
| 11470 | << !FirstUnderlyingType.isNull(); |
| 11471 | ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(), |
| 11472 | SingleSpecifiedType) |
| 11473 | << !SecondUnderlyingType.isNull(); |
| 11474 | Diagnosed = true; |
| 11475 | continue; |
| 11476 | } |
| 11477 | |
| 11478 | if (!FirstUnderlyingType.isNull() && !SecondUnderlyingType.isNull()) { |
| 11479 | if (ComputeQualTypeODRHash(FirstUnderlyingType) != |
| 11480 | ComputeQualTypeODRHash(SecondUnderlyingType)) { |
| 11481 | ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(), |
| 11482 | DifferentSpecifiedTypes) |
| 11483 | << FirstUnderlyingType; |
| 11484 | ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(), |
| 11485 | DifferentSpecifiedTypes) |
| 11486 | << SecondUnderlyingType; |
| 11487 | Diagnosed = true; |
| 11488 | continue; |
| 11489 | } |
| 11490 | } |
| 11491 | |
| 11492 | DeclHashes SecondHashes; |
| 11493 | PopulateHashes(SecondHashes, SecondEnum); |
| 11494 | |
| 11495 | if (FirstHashes.size() != SecondHashes.size()) { |
| 11496 | ODRDiagError(FirstEnum->getLocation(), FirstEnum->getSourceRange(), |
| 11497 | DifferentNumberEnumConstants) |
| 11498 | << (int)FirstHashes.size(); |
| 11499 | ODRDiagNote(SecondEnum->getLocation(), SecondEnum->getSourceRange(), |
| 11500 | DifferentNumberEnumConstants) |
| 11501 | << (int)SecondHashes.size(); |
| 11502 | Diagnosed = true; |
| 11503 | continue; |
| 11504 | } |
| 11505 | |
| 11506 | for (unsigned I = 0; I < FirstHashes.size(); ++I) { |
| 11507 | if (FirstHashes[I].second == SecondHashes[I].second) |
| 11508 | continue; |
| 11509 | const EnumConstantDecl *FirstEnumConstant = FirstHashes[I].first; |
| 11510 | const EnumConstantDecl *SecondEnumConstant = SecondHashes[I].first; |
| 11511 | |
| 11512 | if (FirstEnumConstant->getDeclName() != |
| 11513 | SecondEnumConstant->getDeclName()) { |
| 11514 | |
| 11515 | ODRDiagError(FirstEnumConstant->getLocation(), |
| 11516 | FirstEnumConstant->getSourceRange(), EnumConstantName) |
| 11517 | << I + 1 << FirstEnumConstant; |
| 11518 | ODRDiagNote(SecondEnumConstant->getLocation(), |
| 11519 | SecondEnumConstant->getSourceRange(), EnumConstantName) |
| 11520 | << I + 1 << SecondEnumConstant; |
| 11521 | Diagnosed = true; |
| 11522 | break; |
| 11523 | } |
| 11524 | |
| 11525 | const Expr *FirstInit = FirstEnumConstant->getInitExpr(); |
| 11526 | const Expr *SecondInit = SecondEnumConstant->getInitExpr(); |
| 11527 | if (!FirstInit && !SecondInit) |
| 11528 | continue; |
| 11529 | |
| 11530 | if (!FirstInit || !SecondInit) { |
| 11531 | ODRDiagError(FirstEnumConstant->getLocation(), |
| 11532 | FirstEnumConstant->getSourceRange(), |
| 11533 | EnumConstantSingleInitilizer) |
| 11534 | << I + 1 << FirstEnumConstant << (FirstInit != nullptr); |
| 11535 | ODRDiagNote(SecondEnumConstant->getLocation(), |
| 11536 | SecondEnumConstant->getSourceRange(), |
| 11537 | EnumConstantSingleInitilizer) |
| 11538 | << I + 1 << SecondEnumConstant << (SecondInit != nullptr); |
| 11539 | Diagnosed = true; |
| 11540 | break; |
| 11541 | } |
| 11542 | |
| 11543 | if (ComputeODRHash(FirstInit) != ComputeODRHash(SecondInit)) { |
| 11544 | ODRDiagError(FirstEnumConstant->getLocation(), |
| 11545 | FirstEnumConstant->getSourceRange(), |
| 11546 | EnumConstantDifferentInitilizer) |
| 11547 | << I + 1 << FirstEnumConstant; |
| 11548 | ODRDiagNote(SecondEnumConstant->getLocation(), |
| 11549 | SecondEnumConstant->getSourceRange(), |
| 11550 | EnumConstantDifferentInitilizer) |
| 11551 | << I + 1 << SecondEnumConstant; |
| 11552 | Diagnosed = true; |
| 11553 | break; |
| 11554 | } |
| 11555 | } |
| 11556 | } |
| 11557 | |
| 11558 | (void)Diagnosed; |
| 11559 | assert(Diagnosed && "Unable to emit ODR diagnostic."); |
| 11560 | } |
| 11561 | } |
| 11562 | |
| 11563 | void ASTReader::StartedDeserializing() { |
| 11564 | if (++NumCurrentElementsDeserializing == 1 && ReadTimer.get()) |
| 11565 | ReadTimer->startTimer(); |
| 11566 | } |
| 11567 | |
| 11568 | void ASTReader::FinishedDeserializing() { |
| 11569 | assert(NumCurrentElementsDeserializing && |
| 11570 | "FinishedDeserializing not paired with StartedDeserializing"); |
| 11571 | if (NumCurrentElementsDeserializing == 1) { |
| 11572 | |
| 11573 | |
| 11574 | finishPendingActions(); |
| 11575 | } |
| 11576 | --NumCurrentElementsDeserializing; |
| 11577 | |
| 11578 | if (NumCurrentElementsDeserializing == 0) { |
| 11579 | |
| 11580 | |
| 11581 | |
| 11582 | |
| 11583 | |
| 11584 | while (!PendingExceptionSpecUpdates.empty() || |
| 11585 | !PendingDeducedTypeUpdates.empty()) { |
| 11586 | auto ESUpdates = std::move(PendingExceptionSpecUpdates); |
| 11587 | PendingExceptionSpecUpdates.clear(); |
| 11588 | for (auto Update : ESUpdates) { |
| 11589 | ProcessingUpdatesRAIIObj ProcessingUpdates(*this); |
| 11590 | auto *FPT = Update.second->getType()->castAs<FunctionProtoType>(); |
| 11591 | auto ESI = FPT->getExtProtoInfo().ExceptionSpec; |
| 11592 | if (auto *Listener = getContext().getASTMutationListener()) |
| 11593 | Listener->ResolvedExceptionSpec(cast<FunctionDecl>(Update.second)); |
| 11594 | for (auto *Redecl : Update.second->redecls()) |
| 11595 | getContext().adjustExceptionSpec(cast<FunctionDecl>(Redecl), ESI); |
| 11596 | } |
| 11597 | |
| 11598 | auto DTUpdates = std::move(PendingDeducedTypeUpdates); |
| 11599 | PendingDeducedTypeUpdates.clear(); |
| 11600 | for (auto Update : DTUpdates) { |
| 11601 | ProcessingUpdatesRAIIObj ProcessingUpdates(*this); |
| 11602 | |
| 11603 | getContext().adjustDeducedFunctionResultType(Update.first, |
| 11604 | Update.second); |
| 11605 | } |
| 11606 | } |
| 11607 | |
| 11608 | if (ReadTimer) |
| 11609 | ReadTimer->stopTimer(); |
| 11610 | |
| 11611 | diagnoseOdrViolations(); |
| 11612 | |
| 11613 | |
| 11614 | |
| 11615 | if (Consumer) |
| 11616 | PassInterestingDeclsToConsumer(); |
| 11617 | } |
| 11618 | } |
| 11619 | |
| 11620 | void ASTReader::pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name) { |
| 11621 | if (IdentifierInfo *II = Name.getAsIdentifierInfo()) { |
| 11622 | |
| 11623 | auto It = PendingFakeLookupResults.find(II); |
| 11624 | if (It != PendingFakeLookupResults.end()) { |
| 11625 | for (auto *ND : It->second) |
| 11626 | SemaObj->IdResolver.RemoveDecl(ND); |
| 11627 | |
| 11628 | |
| 11629 | |
| 11630 | It->second.clear(); |
| 11631 | } |
| 11632 | } |
| 11633 | |
| 11634 | if (SemaObj->IdResolver.tryAddTopLevelDecl(D, Name) && SemaObj->TUScope) { |
| 11635 | SemaObj->TUScope->AddDecl(D); |
| 11636 | } else if (SemaObj->TUScope) { |
| 11637 | |
| 11638 | |
| 11639 | |
| 11640 | if (std::find(SemaObj->IdResolver.begin(Name), |
| 11641 | SemaObj->IdResolver.end(), D) != SemaObj->IdResolver.end()) |
| 11642 | SemaObj->TUScope->AddDecl(D); |
| 11643 | } |
| 11644 | } |
| 11645 | |
| 11646 | ASTReader::ASTReader(Preprocessor &PP, InMemoryModuleCache &ModuleCache, |
| 11647 | ASTContext *Context, |
| 11648 | const PCHContainerReader &PCHContainerRdr, |
| 11649 | ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions, |
| 11650 | StringRef isysroot, |
| 11651 | DisableValidationForModuleKind DisableValidationKind, |
| 11652 | bool AllowASTWithCompilerErrors, |
| 11653 | bool AllowConfigurationMismatch, bool ValidateSystemInputs, |
| 11654 | bool ValidateASTInputFilesContent, bool UseGlobalIndex, |
| 11655 | std::unique_ptr<llvm::Timer> ReadTimer) |
| 11656 | : Listener(bool(DisableValidationKind &DisableValidationForModuleKind::PCH) |
| 11657 | ? cast<ASTReaderListener>(new SimpleASTReaderListener(PP)) |
| 11658 | : cast<ASTReaderListener>(new PCHValidator(PP, *this))), |
| 11659 | SourceMgr(PP.getSourceManager()), FileMgr(PP.getFileManager()), |
| 11660 | PCHContainerRdr(PCHContainerRdr), Diags(PP.getDiagnostics()), PP(PP), |
| 11661 | ContextObj(Context), ModuleMgr(PP.getFileManager(), ModuleCache, |
| 11662 | PCHContainerRdr, PP.getHeaderSearchInfo()), |
| 11663 | DummyIdResolver(PP), ReadTimer(std::move(ReadTimer)), isysroot(isysroot), |
| 11664 | DisableValidationKind(DisableValidationKind), |
| 11665 | AllowASTWithCompilerErrors(AllowASTWithCompilerErrors), |
| 11666 | AllowConfigurationMismatch(AllowConfigurationMismatch), |
| 11667 | ValidateSystemInputs(ValidateSystemInputs), |
| 11668 | ValidateASTInputFilesContent(ValidateASTInputFilesContent), |
| 11669 | UseGlobalIndex(UseGlobalIndex), CurrSwitchCaseStmts(&SwitchCaseStmts) { |
| 11670 | SourceMgr.setExternalSLocEntrySource(this); |
| 11671 | |
| 11672 | for (const auto &Ext : Extensions) { |
| 11673 | auto BlockName = Ext->getExtensionMetadata().BlockName; |
| 11674 | auto Known = ModuleFileExtensions.find(BlockName); |
| 11675 | if (Known != ModuleFileExtensions.end()) { |
| 11676 | Diags.Report(diag::warn_duplicate_module_file_extension) |
| 11677 | << BlockName; |
| 11678 | continue; |
| 11679 | } |
| 11680 | |
| 11681 | ModuleFileExtensions.insert({BlockName, Ext}); |
| 11682 | } |
| 11683 | } |
| 11684 | |
| 11685 | ASTReader::~ASTReader() { |
| 11686 | if (OwnsDeserializationListener) |
| 11687 | delete DeserializationListener; |
| 11688 | } |
| 11689 | |
| 11690 | IdentifierResolver &ASTReader::getIdResolver() { |
| 11691 | return SemaObj ? SemaObj->IdResolver : DummyIdResolver; |
| 11692 | } |
| 11693 | |
| 11694 | Expected<unsigned> ASTRecordReader::readRecord(llvm::BitstreamCursor &Cursor, |
| 11695 | unsigned AbbrevID) { |
| 11696 | Idx = 0; |
| 11697 | Record.clear(); |
| 11698 | return Cursor.readRecord(AbbrevID, Record); |
| 11699 | } |
| 11700 | |
| 11701 | |
| 11702 | |
| 11703 | |
| 11704 | |
| 11705 | |
| 11706 | namespace clang { |
| 11707 | |
| 11708 | class OMPClauseReader : public OMPClauseVisitor<OMPClauseReader> { |
| 11709 | ASTRecordReader &Record; |
| 11710 | ASTContext &Context; |
| 11711 | |
| 11712 | public: |
| 11713 | OMPClauseReader(ASTRecordReader &Record) |
| 11714 | : Record(Record), Context(Record.getContext()) {} |
| 11715 | #define GEN_CLANG_CLAUSE_CLASS |
| 11716 | #define CLAUSE_CLASS(Enum, Str, Class) void Visit##Class(Class *C); |
| 11717 | #include "llvm/Frontend/OpenMP/OMP.inc" |
| 11718 | OMPClause *readClause(); |
| 11719 | void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C); |
| 11720 | void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C); |
| 11721 | }; |
| 11722 | |
| 11723 | } |
| 11724 | |
| 11725 | OMPClause *ASTRecordReader::readOMPClause() { |
| 11726 | return OMPClauseReader(*this).readClause(); |
| 11727 | } |
| 11728 | |
| 11729 | OMPClause *OMPClauseReader::readClause() { |
| 11730 | OMPClause *C = nullptr; |
| 11731 | switch (llvm::omp::Clause(Record.readInt())) { |
| 11732 | case llvm::omp::OMPC_if: |
| 11733 | C = new (Context) OMPIfClause(); |
| 11734 | break; |
| 11735 | case llvm::omp::OMPC_final: |
| 11736 | C = new (Context) OMPFinalClause(); |
| 11737 | break; |
| 11738 | case llvm::omp::OMPC_num_threads: |
| 11739 | C = new (Context) OMPNumThreadsClause(); |
| 11740 | break; |
| 11741 | case llvm::omp::OMPC_safelen: |
| 11742 | C = new (Context) OMPSafelenClause(); |
| 11743 | break; |
| 11744 | case llvm::omp::OMPC_simdlen: |
| 11745 | C = new (Context) OMPSimdlenClause(); |
| 11746 | break; |
| 11747 | case llvm::omp::OMPC_sizes: { |
| 11748 | unsigned NumSizes = Record.readInt(); |
| 11749 | C = OMPSizesClause::CreateEmpty(Context, NumSizes); |
| 11750 | break; |
| 11751 | } |
| 11752 | case llvm::omp::OMPC_full: |
| 11753 | C = OMPFullClause::CreateEmpty(Context); |
| 11754 | break; |
| 11755 | case llvm::omp::OMPC_partial: |
| 11756 | C = OMPPartialClause::CreateEmpty(Context); |
| 11757 | break; |
| 11758 | case llvm::omp::OMPC_allocator: |
| 11759 | C = new (Context) OMPAllocatorClause(); |
| 11760 | break; |
| 11761 | case llvm::omp::OMPC_collapse: |
| 11762 | C = new (Context) OMPCollapseClause(); |
| 11763 | break; |
| 11764 | case llvm::omp::OMPC_default: |
| 11765 | C = new (Context) OMPDefaultClause(); |
| 11766 | break; |
| 11767 | case llvm::omp::OMPC_proc_bind: |
| 11768 | C = new (Context) OMPProcBindClause(); |
| 11769 | break; |
| 11770 | case llvm::omp::OMPC_schedule: |
| 11771 | C = new (Context) OMPScheduleClause(); |
| 11772 | break; |
| 11773 | case llvm::omp::OMPC_ordered: |
| 11774 | C = OMPOrderedClause::CreateEmpty(Context, Record.readInt()); |
| 11775 | break; |
| 11776 | case llvm::omp::OMPC_nowait: |
| 11777 | C = new (Context) OMPNowaitClause(); |
| 11778 | break; |
| 11779 | case llvm::omp::OMPC_untied: |
| 11780 | C = new (Context) OMPUntiedClause(); |
| 11781 | break; |
| 11782 | case llvm::omp::OMPC_mergeable: |
| 11783 | C = new (Context) OMPMergeableClause(); |
| 11784 | break; |
| 11785 | case llvm::omp::OMPC_read: |
| 11786 | C = new (Context) OMPReadClause(); |
| 11787 | break; |
| 11788 | case llvm::omp::OMPC_write: |
| 11789 | C = new (Context) OMPWriteClause(); |
| 11790 | break; |
| 11791 | case llvm::omp::OMPC_update: |
| 11792 | C = OMPUpdateClause::CreateEmpty(Context, Record.readInt()); |
| 11793 | break; |
| 11794 | case llvm::omp::OMPC_capture: |
| 11795 | C = new (Context) OMPCaptureClause(); |
| 11796 | break; |
| 11797 | case llvm::omp::OMPC_seq_cst: |
| 11798 | C = new (Context) OMPSeqCstClause(); |
| 11799 | break; |
| 11800 | case llvm::omp::OMPC_acq_rel: |
| 11801 | C = new (Context) OMPAcqRelClause(); |
| 11802 | break; |
| 11803 | case llvm::omp::OMPC_acquire: |
| 11804 | C = new (Context) OMPAcquireClause(); |
| 11805 | break; |
| 11806 | case llvm::omp::OMPC_release: |
| 11807 | C = new (Context) OMPReleaseClause(); |
| 11808 | break; |
| 11809 | case llvm::omp::OMPC_relaxed: |
| 11810 | C = new (Context) OMPRelaxedClause(); |
| 11811 | break; |
| 11812 | case llvm::omp::OMPC_threads: |
| 11813 | C = new (Context) OMPThreadsClause(); |
| 11814 | break; |
| 11815 | case llvm::omp::OMPC_simd: |
| 11816 | C = new (Context) OMPSIMDClause(); |
| 11817 | break; |
| 11818 | case llvm::omp::OMPC_nogroup: |
| 11819 | C = new (Context) OMPNogroupClause(); |
| 11820 | break; |
| 11821 | case llvm::omp::OMPC_unified_address: |
| 11822 | C = new (Context) OMPUnifiedAddressClause(); |
| 11823 | break; |
| 11824 | case llvm::omp::OMPC_unified_shared_memory: |
| 11825 | C = new (Context) OMPUnifiedSharedMemoryClause(); |
| 11826 | break; |
| 11827 | case llvm::omp::OMPC_reverse_offload: |
| 11828 | C = new (Context) OMPReverseOffloadClause(); |
| 11829 | break; |
| 11830 | case llvm::omp::OMPC_dynamic_allocators: |
| 11831 | C = new (Context) OMPDynamicAllocatorsClause(); |
| 11832 | break; |
| 11833 | case llvm::omp::OMPC_atomic_default_mem_order: |
| 11834 | C = new (Context) OMPAtomicDefaultMemOrderClause(); |
| 11835 | break; |
| 11836 | case llvm::omp::OMPC_private: |
| 11837 | C = OMPPrivateClause::CreateEmpty(Context, Record.readInt()); |
| 11838 | break; |
| 11839 | case llvm::omp::OMPC_firstprivate: |
| 11840 | C = OMPFirstprivateClause::CreateEmpty(Context, Record.readInt()); |
| 11841 | break; |
| 11842 | case llvm::omp::OMPC_lastprivate: |
| 11843 | C = OMPLastprivateClause::CreateEmpty(Context, Record.readInt()); |
| 11844 | break; |
| 11845 | case llvm::omp::OMPC_shared: |
| 11846 | C = OMPSharedClause::CreateEmpty(Context, Record.readInt()); |
| 11847 | break; |
| 11848 | case llvm::omp::OMPC_reduction: { |
| 11849 | unsigned N = Record.readInt(); |
| 11850 | auto Modifier = Record.readEnum<OpenMPReductionClauseModifier>(); |
| 11851 | C = OMPReductionClause::CreateEmpty(Context, N, Modifier); |
| 11852 | break; |
| 11853 | } |
| 11854 | case llvm::omp::OMPC_task_reduction: |
| 11855 | C = OMPTaskReductionClause::CreateEmpty(Context, Record.readInt()); |
| 11856 | break; |
| 11857 | case llvm::omp::OMPC_in_reduction: |
| 11858 | C = OMPInReductionClause::CreateEmpty(Context, Record.readInt()); |
| 11859 | break; |
| 11860 | case llvm::omp::OMPC_linear: |
| 11861 | C = OMPLinearClause::CreateEmpty(Context, Record.readInt()); |
| 11862 | break; |
| 11863 | case llvm::omp::OMPC_aligned: |
| 11864 | C = OMPAlignedClause::CreateEmpty(Context, Record.readInt()); |
| 11865 | break; |
| 11866 | case llvm::omp::OMPC_copyin: |
| 11867 | C = OMPCopyinClause::CreateEmpty(Context, Record.readInt()); |
| 11868 | break; |
| 11869 | case llvm::omp::OMPC_copyprivate: |
| 11870 | C = OMPCopyprivateClause::CreateEmpty(Context, Record.readInt()); |
| 11871 | break; |
| 11872 | case llvm::omp::OMPC_flush: |
| 11873 | C = OMPFlushClause::CreateEmpty(Context, Record.readInt()); |
| 11874 | break; |
| 11875 | case llvm::omp::OMPC_depobj: |
| 11876 | C = OMPDepobjClause::CreateEmpty(Context); |
| 11877 | break; |
| 11878 | case llvm::omp::OMPC_depend: { |
| 11879 | unsigned NumVars = Record.readInt(); |
| 11880 | unsigned NumLoops = Record.readInt(); |
| 11881 | C = OMPDependClause::CreateEmpty(Context, NumVars, NumLoops); |
| 11882 | break; |
| 11883 | } |
| 11884 | case llvm::omp::OMPC_device: |
| 11885 | C = new (Context) OMPDeviceClause(); |
| 11886 | break; |
| 11887 | case llvm::omp::OMPC_map: { |
| 11888 | OMPMappableExprListSizeTy Sizes; |
| 11889 | Sizes.NumVars = Record.readInt(); |
| 11890 | Sizes.NumUniqueDeclarations = Record.readInt(); |
| 11891 | Sizes.NumComponentLists = Record.readInt(); |
| 11892 | Sizes.NumComponents = Record.readInt(); |
| 11893 | C = OMPMapClause::CreateEmpty(Context, Sizes); |
| 11894 | break; |
| 11895 | } |
| 11896 | case llvm::omp::OMPC_num_teams: |
| 11897 | C = new (Context) OMPNumTeamsClause(); |
| 11898 | break; |
| 11899 | case llvm::omp::OMPC_thread_limit: |
| 11900 | C = new (Context) OMPThreadLimitClause(); |
| 11901 | break; |
| 11902 | case llvm::omp::OMPC_priority: |
| 11903 | C = new (Context) OMPPriorityClause(); |
| 11904 | break; |
| 11905 | case llvm::omp::OMPC_grainsize: |
| 11906 | C = new (Context) OMPGrainsizeClause(); |
| 11907 | break; |
| 11908 | case llvm::omp::OMPC_num_tasks: |
| 11909 | C = new (Context) OMPNumTasksClause(); |
| 11910 | break; |
| 11911 | case llvm::omp::OMPC_hint: |
| 11912 | C = new (Context) OMPHintClause(); |
| 11913 | break; |
| 11914 | case llvm::omp::OMPC_dist_schedule: |
| 11915 | C = new (Context) OMPDistScheduleClause(); |
| 11916 | break; |
| 11917 | case llvm::omp::OMPC_defaultmap: |
| 11918 | C = new (Context) OMPDefaultmapClause(); |
| 11919 | break; |
| 11920 | case llvm::omp::OMPC_to: { |
| 11921 | OMPMappableExprListSizeTy Sizes; |
| 11922 | Sizes.NumVars = Record.readInt(); |
| 11923 | Sizes.NumUniqueDeclarations = Record.readInt(); |
| 11924 | Sizes.NumComponentLists = Record.readInt(); |
| 11925 | Sizes.NumComponents = Record.readInt(); |
| 11926 | C = OMPToClause::CreateEmpty(Context, Sizes); |
| 11927 | break; |
| 11928 | } |
| 11929 | case llvm::omp::OMPC_from: { |
| 11930 | OMPMappableExprListSizeTy Sizes; |
| 11931 | Sizes.NumVars = Record.readInt(); |
| 11932 | Sizes.NumUniqueDeclarations = Record.readInt(); |
| 11933 | Sizes.NumComponentLists = Record.readInt(); |
| 11934 | Sizes.NumComponents = Record.readInt(); |
| 11935 | C = OMPFromClause::CreateEmpty(Context, Sizes); |
| 11936 | break; |
| 11937 | } |
| 11938 | case llvm::omp::OMPC_use_device_ptr: { |
| 11939 | OMPMappableExprListSizeTy Sizes; |
| 11940 | Sizes.NumVars = Record.readInt(); |
| 11941 | Sizes.NumUniqueDeclarations = Record.readInt(); |
| 11942 | Sizes.NumComponentLists = Record.readInt(); |
| 11943 | Sizes.NumComponents = Record.readInt(); |
| 11944 | C = OMPUseDevicePtrClause::CreateEmpty(Context, Sizes); |
| 11945 | break; |
| 11946 | } |
| 11947 | case llvm::omp::OMPC_use_device_addr: { |
| 11948 | OMPMappableExprListSizeTy Sizes; |
| 11949 | Sizes.NumVars = Record.readInt(); |
| 11950 | Sizes.NumUniqueDeclarations = Record.readInt(); |
| 11951 | Sizes.NumComponentLists = Record.readInt(); |
| 11952 | Sizes.NumComponents = Record.readInt(); |
| 11953 | C = OMPUseDeviceAddrClause::CreateEmpty(Context, Sizes); |
| 11954 | break; |
| 11955 | } |
| 11956 | case llvm::omp::OMPC_is_device_ptr: { |
| 11957 | OMPMappableExprListSizeTy Sizes; |
| 11958 | Sizes.NumVars = Record.readInt(); |
| 11959 | Sizes.NumUniqueDeclarations = Record.readInt(); |
| 11960 | Sizes.NumComponentLists = Record.readInt(); |
| 11961 | Sizes.NumComponents = Record.readInt(); |
| 11962 | C = OMPIsDevicePtrClause::CreateEmpty(Context, Sizes); |
| 11963 | break; |
| 11964 | } |
| 11965 | case llvm::omp::OMPC_allocate: |
| 11966 | C = OMPAllocateClause::CreateEmpty(Context, Record.readInt()); |
| 11967 | break; |
| 11968 | case llvm::omp::OMPC_nontemporal: |
| 11969 | C = OMPNontemporalClause::CreateEmpty(Context, Record.readInt()); |
| 11970 | break; |
| 11971 | case llvm::omp::OMPC_inclusive: |
| 11972 | C = OMPInclusiveClause::CreateEmpty(Context, Record.readInt()); |
| 11973 | break; |
| 11974 | case llvm::omp::OMPC_exclusive: |
| 11975 | C = OMPExclusiveClause::CreateEmpty(Context, Record.readInt()); |
| 11976 | break; |
| 11977 | case llvm::omp::OMPC_order: |
| 11978 | C = new (Context) OMPOrderClause(); |
| 11979 | break; |
| 11980 | case llvm::omp::OMPC_init: |
| 11981 | C = OMPInitClause::CreateEmpty(Context, Record.readInt()); |
| 11982 | break; |
| 11983 | case llvm::omp::OMPC_use: |
| 11984 | C = new (Context) OMPUseClause(); |
| 11985 | break; |
| 11986 | case llvm::omp::OMPC_destroy: |
| 11987 | C = new (Context) OMPDestroyClause(); |
| 11988 | break; |
| 11989 | case llvm::omp::OMPC_novariants: |
| 11990 | C = new (Context) OMPNovariantsClause(); |
| 11991 | break; |
| 11992 | case llvm::omp::OMPC_nocontext: |
| 11993 | C = new (Context) OMPNocontextClause(); |
| 11994 | break; |
| 11995 | case llvm::omp::OMPC_detach: |
| 11996 | C = new (Context) OMPDetachClause(); |
| 11997 | break; |
| 11998 | case llvm::omp::OMPC_uses_allocators: |
| 11999 | C = OMPUsesAllocatorsClause::CreateEmpty(Context, Record.readInt()); |
| 12000 | break; |
| 12001 | case llvm::omp::OMPC_affinity: |
| 12002 | C = OMPAffinityClause::CreateEmpty(Context, Record.readInt()); |
| 12003 | break; |
| 12004 | case llvm::omp::OMPC_filter: |
| 12005 | C = new (Context) OMPFilterClause(); |
| 12006 | break; |
| 12007 | #define OMP_CLAUSE_NO_CLASS(Enum, Str) \ |
| 12008 | case llvm::omp::Enum: \ |
| 12009 | break; |
| 12010 | #include "llvm/Frontend/OpenMP/OMPKinds.def" |
| 12011 | default: |
| 12012 | break; |
| 12013 | } |
| 12014 | assert(C && "Unknown OMPClause type"); |
| 12015 | |
| 12016 | Visit(C); |
| 12017 | C->setLocStart(Record.readSourceLocation()); |
| 12018 | C->setLocEnd(Record.readSourceLocation()); |
| 12019 | |
| 12020 | return C; |
| 12021 | } |
| 12022 | |
| 12023 | void OMPClauseReader::VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C) { |
| 12024 | C->setPreInitStmt(Record.readSubStmt(), |
| 12025 | static_cast<OpenMPDirectiveKind>(Record.readInt())); |
| 12026 | } |
| 12027 | |
| 12028 | void OMPClauseReader::VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C) { |
| 12029 | VisitOMPClauseWithPreInit(C); |
| 12030 | C->setPostUpdateExpr(Record.readSubExpr()); |
| 12031 | } |
| 12032 | |
| 12033 | void OMPClauseReader::VisitOMPIfClause(OMPIfClause *C) { |
| 12034 | VisitOMPClauseWithPreInit(C); |
| 12035 | C->setNameModifier(static_cast<OpenMPDirectiveKind>(Record.readInt())); |
| 12036 | C->setNameModifierLoc(Record.readSourceLocation()); |
| 12037 | C->setColonLoc(Record.readSourceLocation()); |
| 12038 | C->setCondition(Record.readSubExpr()); |
| 12039 | C->setLParenLoc(Record.readSourceLocation()); |
| 12040 | } |
| 12041 | |
| 12042 | void OMPClauseReader::VisitOMPFinalClause(OMPFinalClause *C) { |
| 12043 | VisitOMPClauseWithPreInit(C); |
| 12044 | C->setCondition(Record.readSubExpr()); |
| 12045 | C->setLParenLoc(Record.readSourceLocation()); |
| 12046 | } |
| 12047 | |
| 12048 | void OMPClauseReader::VisitOMPNumThreadsClause(OMPNumThreadsClause *C) { |
| 12049 | VisitOMPClauseWithPreInit(C); |
| 12050 | C->setNumThreads(Record.readSubExpr()); |
| 12051 | C->setLParenLoc(Record.readSourceLocation()); |
| 12052 | } |
| 12053 | |
| 12054 | void OMPClauseReader::VisitOMPSafelenClause(OMPSafelenClause *C) { |
| 12055 | C->setSafelen(Record.readSubExpr()); |
| 12056 | C->setLParenLoc(Record.readSourceLocation()); |
| 12057 | } |
| 12058 | |
| 12059 | void OMPClauseReader::VisitOMPSimdlenClause(OMPSimdlenClause *C) { |
| 12060 | C->setSimdlen(Record.readSubExpr()); |
| 12061 | C->setLParenLoc(Record.readSourceLocation()); |
| 12062 | } |
| 12063 | |
| 12064 | void OMPClauseReader::VisitOMPSizesClause(OMPSizesClause *C) { |
| 12065 | for (Expr *&E : C->getSizesRefs()) |
| 12066 | E = Record.readSubExpr(); |
| 12067 | C->setLParenLoc(Record.readSourceLocation()); |
| 12068 | } |
| 12069 | |
| 12070 | void OMPClauseReader::VisitOMPFullClause(OMPFullClause *C) {} |
| 12071 | |
| 12072 | void OMPClauseReader::VisitOMPPartialClause(OMPPartialClause *C) { |
| 12073 | C->setFactor(Record.readSubExpr()); |
| 12074 | C->setLParenLoc(Record.readSourceLocation()); |
| 12075 | } |
| 12076 | |
| 12077 | void OMPClauseReader::VisitOMPAllocatorClause(OMPAllocatorClause *C) { |
| 12078 | C->setAllocator(Record.readExpr()); |
| 12079 | C->setLParenLoc(Record.readSourceLocation()); |
| 12080 | } |
| 12081 | |
| 12082 | void OMPClauseReader::VisitOMPCollapseClause(OMPCollapseClause *C) { |
| 12083 | C->setNumForLoops(Record.readSubExpr()); |
| 12084 | C->setLParenLoc(Record.readSourceLocation()); |
| 12085 | } |
| 12086 | |
| 12087 | void OMPClauseReader::VisitOMPDefaultClause(OMPDefaultClause *C) { |
| 12088 | C->setDefaultKind(static_cast<llvm::omp::DefaultKind>(Record.readInt())); |
| 12089 | C->setLParenLoc(Record.readSourceLocation()); |
| 12090 | C->setDefaultKindKwLoc(Record.readSourceLocation()); |
| 12091 | } |
| 12092 | |
| 12093 | void OMPClauseReader::VisitOMPProcBindClause(OMPProcBindClause *C) { |
| 12094 | C->setProcBindKind(static_cast<llvm::omp::ProcBindKind>(Record.readInt())); |
| 12095 | C->setLParenLoc(Record.readSourceLocation()); |
| 12096 | C->setProcBindKindKwLoc(Record.readSourceLocation()); |
| 12097 | } |
| 12098 | |
| 12099 | void OMPClauseReader::VisitOMPScheduleClause(OMPScheduleClause *C) { |
| 12100 | VisitOMPClauseWithPreInit(C); |
| 12101 | C->setScheduleKind( |
| 12102 | static_cast<OpenMPScheduleClauseKind>(Record.readInt())); |
| 12103 | C->setFirstScheduleModifier( |
| 12104 | static_cast<OpenMPScheduleClauseModifier>(Record.readInt())); |
| 12105 | C->setSecondScheduleModifier( |
| 12106 | static_cast<OpenMPScheduleClauseModifier>(Record.readInt())); |
| 12107 | C->setChunkSize(Record.readSubExpr()); |
| 12108 | C->setLParenLoc(Record.readSourceLocation()); |
| 12109 | C->setFirstScheduleModifierLoc(Record.readSourceLocation()); |
| 12110 | C->setSecondScheduleModifierLoc(Record.readSourceLocation()); |
| 12111 | C->setScheduleKindLoc(Record.readSourceLocation()); |
| 12112 | C->setCommaLoc(Record.readSourceLocation()); |
| 12113 | } |
| 12114 | |
| 12115 | void OMPClauseReader::VisitOMPOrderedClause(OMPOrderedClause *C) { |
| 12116 | C->setNumForLoops(Record.readSubExpr()); |
| 12117 | for (unsigned I = 0, E = C->NumberOfLoops; I < E; ++I) |
| 12118 | C->setLoopNumIterations(I, Record.readSubExpr()); |
| 12119 | for (unsigned I = 0, E = C->NumberOfLoops; I < E; ++I) |
| 12120 | C->setLoopCounter(I, Record.readSubExpr()); |
| 12121 | C->setLParenLoc(Record.readSourceLocation()); |
| 12122 | } |
| 12123 | |
| 12124 | void OMPClauseReader::VisitOMPDetachClause(OMPDetachClause *C) { |
| 12125 | C->setEventHandler(Record.readSubExpr()); |
| 12126 | C->setLParenLoc(Record.readSourceLocation()); |
| 12127 | } |
| 12128 | |
| 12129 | void OMPClauseReader::VisitOMPNowaitClause(OMPNowaitClause *) {} |
| 12130 | |
| 12131 | void OMPClauseReader::VisitOMPUntiedClause(OMPUntiedClause *) {} |
| 12132 | |
| 12133 | void OMPClauseReader::VisitOMPMergeableClause(OMPMergeableClause *) {} |
| 12134 | |
| 12135 | void OMPClauseReader::VisitOMPReadClause(OMPReadClause *) {} |
| 12136 | |
| 12137 | void OMPClauseReader::VisitOMPWriteClause(OMPWriteClause *) {} |
| 12138 | |
| 12139 | void OMPClauseReader::VisitOMPUpdateClause(OMPUpdateClause *C) { |
| 12140 | if (C->isExtended()) { |
| 12141 | C->setLParenLoc(Record.readSourceLocation()); |
| 12142 | C->setArgumentLoc(Record.readSourceLocation()); |
| 12143 | C->setDependencyKind(Record.readEnum<OpenMPDependClauseKind>()); |
| 12144 | } |
| 12145 | } |
| 12146 | |
| 12147 | void OMPClauseReader::VisitOMPCaptureClause(OMPCaptureClause *) {} |
| 12148 | |
| 12149 | void OMPClauseReader::VisitOMPSeqCstClause(OMPSeqCstClause *) {} |
| 12150 | |
| 12151 | void OMPClauseReader::VisitOMPAcqRelClause(OMPAcqRelClause *) {} |
| 12152 | |
| 12153 | void OMPClauseReader::VisitOMPAcquireClause(OMPAcquireClause *) {} |
| 12154 | |
| 12155 | void OMPClauseReader::VisitOMPReleaseClause(OMPReleaseClause *) {} |
| 12156 | |
| 12157 | void OMPClauseReader::VisitOMPRelaxedClause(OMPRelaxedClause *) {} |
| 12158 | |
| 12159 | void OMPClauseReader::VisitOMPThreadsClause(OMPThreadsClause *) {} |
| 12160 | |
| 12161 | void OMPClauseReader::VisitOMPSIMDClause(OMPSIMDClause *) {} |
| 12162 | |
| 12163 | void OMPClauseReader::VisitOMPNogroupClause(OMPNogroupClause *) {} |
| 12164 | |
| 12165 | void OMPClauseReader::VisitOMPInitClause(OMPInitClause *C) { |
| 12166 | unsigned NumVars = C->varlist_size(); |
| 12167 | SmallVector<Expr *, 16> Vars; |
| 12168 | Vars.reserve(NumVars); |
| 12169 | for (unsigned I = 0; I != NumVars; ++I) |
| 12170 | Vars.push_back(Record.readSubExpr()); |
| 12171 | C->setVarRefs(Vars); |
| 12172 | C->setIsTarget(Record.readBool()); |
| 12173 | C->setIsTargetSync(Record.readBool()); |
| 12174 | C->setLParenLoc(Record.readSourceLocation()); |
| 12175 | C->setVarLoc(Record.readSourceLocation()); |
| 12176 | } |
| 12177 | |
| 12178 | void OMPClauseReader::VisitOMPUseClause(OMPUseClause *C) { |
| 12179 | C->setInteropVar(Record.readSubExpr()); |
| 12180 | C->setLParenLoc(Record.readSourceLocation()); |
| 12181 | C->setVarLoc(Record.readSourceLocation()); |
| 12182 | } |
| 12183 | |
| 12184 | void OMPClauseReader::VisitOMPDestroyClause(OMPDestroyClause *C) { |
| 12185 | C->setInteropVar(Record.readSubExpr()); |
| 12186 | C->setLParenLoc(Record.readSourceLocation()); |
| 12187 | C->setVarLoc(Record.readSourceLocation()); |
| 12188 | } |
| 12189 | |
| 12190 | void OMPClauseReader::VisitOMPNovariantsClause(OMPNovariantsClause *C) { |
| 12191 | VisitOMPClauseWithPreInit(C); |
| 12192 | C->setCondition(Record.readSubExpr()); |
| 12193 | C->setLParenLoc(Record.readSourceLocation()); |
| 12194 | } |
| 12195 | |
| 12196 | void OMPClauseReader::VisitOMPNocontextClause(OMPNocontextClause *C) { |
| 12197 | VisitOMPClauseWithPreInit(C); |
| 12198 | C->setCondition(Record.readSubExpr()); |
| 12199 | C->setLParenLoc(Record.readSourceLocation()); |
| 12200 | } |
| 12201 | |
| 12202 | void OMPClauseReader::VisitOMPUnifiedAddressClause(OMPUnifiedAddressClause *) {} |
| 12203 | |
| 12204 | void OMPClauseReader::VisitOMPUnifiedSharedMemoryClause( |
| 12205 | OMPUnifiedSharedMemoryClause *) {} |
| 12206 | |
| 12207 | void OMPClauseReader::VisitOMPReverseOffloadClause(OMPReverseOffloadClause *) {} |
| 12208 | |
| 12209 | void |
| 12210 | OMPClauseReader::VisitOMPDynamicAllocatorsClause(OMPDynamicAllocatorsClause *) { |
| 12211 | } |
| 12212 | |
| 12213 | void OMPClauseReader::VisitOMPAtomicDefaultMemOrderClause( |
| 12214 | OMPAtomicDefaultMemOrderClause *C) { |
| 12215 | C->setAtomicDefaultMemOrderKind( |
| 12216 | static_cast<OpenMPAtomicDefaultMemOrderClauseKind>(Record.readInt())); |
| 12217 | C->setLParenLoc(Record.readSourceLocation()); |
| 12218 | C->setAtomicDefaultMemOrderKindKwLoc(Record.readSourceLocation()); |
| 12219 | } |
| 12220 | |
| 12221 | void OMPClauseReader::VisitOMPPrivateClause(OMPPrivateClause *C) { |
| 12222 | C->setLParenLoc(Record.readSourceLocation()); |
| 12223 | unsigned NumVars = C->varlist_size(); |
| 12224 | SmallVector<Expr *, 16> Vars; |
| 12225 | Vars.reserve(NumVars); |
| 12226 | for (unsigned i = 0; i != NumVars; ++i) |
| 12227 | Vars.push_back(Record.readSubExpr()); |
| 12228 | C->setVarRefs(Vars); |
| 12229 | Vars.clear(); |
| 12230 | for (unsigned i = 0; i != NumVars; ++i) |
| 12231 | Vars.push_back(Record.readSubExpr()); |
| 12232 | C->setPrivateCopies(Vars); |
| 12233 | } |
| 12234 | |
| 12235 | void OMPClauseReader::VisitOMPFirstprivateClause(OMPFirstprivateClause *C) { |
| 12236 | VisitOMPClauseWithPreInit(C); |
| 12237 | C->setLParenLoc(Record.readSourceLocation()); |
| 12238 | unsigned NumVars = C->varlist_size(); |
| 12239 | SmallVector<Expr *, 16> Vars; |
| 12240 | Vars.reserve(NumVars); |
| 12241 | for (unsigned i = 0; i != NumVars; ++i) |
| 12242 | Vars.push_back(Record.readSubExpr()); |
| 12243 | C->setVarRefs(Vars); |
| 12244 | Vars.clear(); |
| 12245 | for (unsigned i = 0; i != NumVars; ++i) |
| 12246 | Vars.push_back(Record.readSubExpr()); |
| 12247 | C->setPrivateCopies(Vars); |
| 12248 | Vars.clear(); |
| 12249 | for (unsigned i = 0; i != NumVars; ++i) |
| 12250 | Vars.push_back(Record.readSubExpr()); |
| 12251 | C->setInits(Vars); |
| 12252 | } |
| 12253 | |
| 12254 | void OMPClauseReader::VisitOMPLastprivateClause(OMPLastprivateClause *C) { |
| 12255 | VisitOMPClauseWithPostUpdate(C); |
| 12256 | C->setLParenLoc(Record.readSourceLocation()); |
| 12257 | C->setKind(Record.readEnum<OpenMPLastprivateModifier>()); |
| 12258 | C->setKindLoc(Record.readSourceLocation()); |
| 12259 | C->setColonLoc(Record.readSourceLocation()); |
| 12260 | unsigned NumVars = C->varlist_size(); |
| 12261 | SmallVector<Expr *, 16> Vars; |
| 12262 | Vars.reserve(NumVars); |
| 12263 | for (unsigned i = 0; i != NumVars; ++i) |
| 12264 | Vars.push_back(Record.readSubExpr()); |
| 12265 | C->setVarRefs(Vars); |
| 12266 | Vars.clear(); |
| 12267 | for (unsigned i = 0; i != NumVars; ++i) |
| 12268 | Vars.push_back(Record.readSubExpr()); |
| 12269 | C->setPrivateCopies(Vars); |
| 12270 | Vars.clear(); |
| 12271 | for (unsigned i = 0; i != NumVars; ++i) |
| 12272 | Vars.push_back(Record.readSubExpr()); |
| 12273 | C->setSourceExprs(Vars); |
| 12274 | Vars.clear(); |
| 12275 | for (unsigned i = 0; i != NumVars; ++i) |
| 12276 | Vars.push_back(Record.readSubExpr()); |
| 12277 | C->setDestinationExprs(Vars); |
| 12278 | Vars.clear(); |
| 12279 | for (unsigned i = 0; i != NumVars; ++i) |
| 12280 | Vars.push_back(Record.readSubExpr()); |
| 12281 | C->setAssignmentOps(Vars); |
| 12282 | } |
| 12283 | |
| 12284 | void OMPClauseReader::VisitOMPSharedClause(OMPSharedClause *C) { |
| 12285 | C->setLParenLoc(Record.readSourceLocation()); |
| 12286 | unsigned NumVars = C->varlist_size(); |
| 12287 | SmallVector<Expr *, 16> Vars; |
| 12288 | Vars.reserve(NumVars); |
| 12289 | for (unsigned i = 0; i != NumVars; ++i) |
| 12290 | Vars.push_back(Record.readSubExpr()); |
| 12291 | C->setVarRefs(Vars); |
| 12292 | } |
| 12293 | |
| 12294 | void OMPClauseReader::VisitOMPReductionClause(OMPReductionClause *C) { |
| 12295 | VisitOMPClauseWithPostUpdate(C); |
| 12296 | C->setLParenLoc(Record.readSourceLocation()); |
| 12297 | C->setModifierLoc(Record.readSourceLocation()); |
| 12298 | C->setColonLoc(Record.readSourceLocation()); |
| 12299 | NestedNameSpecifierLoc NNSL = Record.readNestedNameSpecifierLoc(); |
| 12300 | DeclarationNameInfo DNI = Record.readDeclarationNameInfo(); |
| 12301 | C->setQualifierLoc(NNSL); |
| 12302 | C->setNameInfo(DNI); |
| 12303 | |
| 12304 | unsigned NumVars = C->varlist_size(); |
| 12305 | SmallVector<Expr *, 16> Vars; |
| 12306 | Vars.reserve(NumVars); |
| 12307 | for (unsigned i = 0; i != NumVars; ++i) |
| 12308 | Vars.push_back(Record.readSubExpr()); |
| 12309 | C->setVarRefs(Vars); |
| 12310 | Vars.clear(); |
| 12311 | for (unsigned i = 0; i != NumVars; ++i) |
| 12312 | Vars.push_back(Record.readSubExpr()); |
| 12313 | C->setPrivates(Vars); |
| 12314 | Vars.clear(); |
| 12315 | for (unsigned i = 0; i != NumVars; ++i) |
| 12316 | Vars.push_back(Record.readSubExpr()); |
| 12317 | C->setLHSExprs(Vars); |
| 12318 | Vars.clear(); |
| 12319 | for (unsigned i = 0; i != NumVars; ++i) |
| 12320 | Vars.push_back(Record.readSubExpr()); |
| 12321 | C->setRHSExprs(Vars); |
| 12322 | Vars.clear(); |
| 12323 | for (unsigned i = 0; i != NumVars; ++i) |
| 12324 | Vars.push_back(Record.readSubExpr()); |
| 12325 | C->setReductionOps(Vars); |
| 12326 | if (C->getModifier() == OMPC_REDUCTION_inscan) { |
| 12327 | Vars.clear(); |
| 12328 | for (unsigned i = 0; i != NumVars; ++i) |
| 12329 | Vars.push_back(Record.readSubExpr()); |
| 12330 | C->setInscanCopyOps(Vars); |
| 12331 | Vars.clear(); |
| 12332 | for (unsigned i = 0; i != NumVars; ++i) |
| 12333 | Vars.push_back(Record.readSubExpr()); |
| 12334 | C->setInscanCopyArrayTemps(Vars); |
| 12335 | Vars.clear(); |
| 12336 | for (unsigned i = 0; i != NumVars; ++i) |
| 12337 | Vars.push_back(Record.readSubExpr()); |
| 12338 | C->setInscanCopyArrayElems(Vars); |
| 12339 | } |
| 12340 | } |
| 12341 | |
| 12342 | void OMPClauseReader::VisitOMPTaskReductionClause(OMPTaskReductionClause *C) { |
| 12343 | VisitOMPClauseWithPostUpdate(C); |
| 12344 | C->setLParenLoc(Record.readSourceLocation()); |
| 12345 | C->setColonLoc(Record.readSourceLocation()); |
| 12346 | NestedNameSpecifierLoc NNSL = Record.readNestedNameSpecifierLoc(); |
| 12347 | DeclarationNameInfo DNI = Record.readDeclarationNameInfo(); |
| 12348 | C->setQualifierLoc(NNSL); |
| 12349 | C->setNameInfo(DNI); |
| 12350 | |
| 12351 | unsigned NumVars = C->varlist_size(); |
| 12352 | SmallVector<Expr *, 16> Vars; |
| 12353 | Vars.reserve(NumVars); |
| 12354 | for (unsigned I = 0; I != NumVars; ++I) |
| 12355 | Vars.push_back(Record.readSubExpr()); |
| 12356 | C->setVarRefs(Vars); |
| 12357 | Vars.clear(); |
| 12358 | for (unsigned I = 0; I != NumVars; ++I) |
| 12359 | Vars.push_back(Record.readSubExpr()); |
| 12360 | C->setPrivates(Vars); |
| 12361 | Vars.clear(); |
| 12362 | for (unsigned I = 0; I != NumVars; ++I) |
| 12363 | Vars.push_back(Record.readSubExpr()); |
| 12364 | C->setLHSExprs(Vars); |
| 12365 | Vars.clear(); |
| 12366 | for (unsigned I = 0; I != NumVars; ++I) |
| 12367 | Vars.push_back(Record.readSubExpr()); |
| 12368 | C->setRHSExprs(Vars); |
| 12369 | Vars.clear(); |
| 12370 | for (unsigned I = 0; I != NumVars; ++I) |
| 12371 | Vars.push_back(Record.readSubExpr()); |
| 12372 | C->setReductionOps(Vars); |
| 12373 | } |
| 12374 | |
| 12375 | void OMPClauseReader::VisitOMPInReductionClause(OMPInReductionClause *C) { |
| 12376 | VisitOMPClauseWithPostUpdate(C); |
| 12377 | C->setLParenLoc(Record.readSourceLocation()); |
| 12378 | C->setColonLoc(Record.readSourceLocation()); |
| 12379 | NestedNameSpecifierLoc NNSL = Record.readNestedNameSpecifierLoc(); |
| 12380 | DeclarationNameInfo DNI = Record.readDeclarationNameInfo(); |
| 12381 | C->setQualifierLoc(NNSL); |
| 12382 | C->setNameInfo(DNI); |
| 12383 | |
| 12384 | unsigned NumVars = C->varlist_size(); |
| 12385 | SmallVector<Expr *, 16> Vars; |
| 12386 | Vars.reserve(NumVars); |
| 12387 | for (unsigned I = 0; I != NumVars; ++I) |
| 12388 | Vars.push_back(Record.readSubExpr()); |
| 12389 | C->setVarRefs(Vars); |
| 12390 | Vars.clear(); |
| 12391 | for (unsigned I = 0; I != NumVars; ++I) |
| 12392 | Vars.push_back(Record.readSubExpr()); |
| 12393 | C->setPrivates(Vars); |
| 12394 | Vars.clear(); |
| 12395 | for (unsigned I = 0; I != NumVars; ++I) |
| 12396 | Vars.push_back(Record.readSubExpr()); |
| 12397 | C->setLHSExprs(Vars); |
| 12398 | Vars.clear(); |
| 12399 | for (unsigned I = 0; I != NumVars; ++I) |
| 12400 | Vars.push_back(Record.readSubExpr()); |
| 12401 | C->setRHSExprs(Vars); |
| 12402 | Vars.clear(); |
| 12403 | for (unsigned I = 0; I != NumVars; ++I) |
| 12404 | Vars.push_back(Record.readSubExpr()); |
| 12405 | C->setReductionOps(Vars); |
| 12406 | Vars.clear(); |
| 12407 | for (unsigned I = 0; I != NumVars; ++I) |
| 12408 | Vars.push_back(Record.readSubExpr()); |
| 12409 | C->setTaskgroupDescriptors(Vars); |
| 12410 | } |
| 12411 | |
| 12412 | void OMPClauseReader::VisitOMPLinearClause(OMPLinearClause *C) { |
| 12413 | VisitOMPClauseWithPostUpdate(C); |
| 12414 | C->setLParenLoc(Record.readSourceLocation()); |
| 12415 | C->setColonLoc(Record.readSourceLocation()); |
| 12416 | C->setModifier(static_cast<OpenMPLinearClauseKind>(Record.readInt())); |
| 12417 | C->setModifierLoc(Record.readSourceLocation()); |
| 12418 | unsigned NumVars = C->varlist_size(); |
| 12419 | SmallVector<Expr *, 16> Vars; |
| 12420 | Vars.reserve(NumVars); |
| 12421 | for (unsigned i = 0; i != NumVars; ++i) |
| 12422 | Vars.push_back(Record.readSubExpr()); |
| 12423 | C->setVarRefs(Vars); |
| 12424 | Vars.clear(); |
| 12425 | for (unsigned i = 0; i != NumVars; ++i) |
| 12426 | Vars.push_back(Record.readSubExpr()); |
| 12427 | C->setPrivates(Vars); |
| 12428 | Vars.clear(); |
| 12429 | for (unsigned i = 0; i != NumVars; ++i) |
| 12430 | Vars.push_back(Record.readSubExpr()); |
| 12431 | C->setInits(Vars); |
| 12432 | Vars.clear(); |
| 12433 | for (unsigned i = 0; i != NumVars; ++i) |
| 12434 | Vars.push_back(Record.readSubExpr()); |
| 12435 | C->setUpdates(Vars); |
| 12436 | Vars.clear(); |
| 12437 | for (unsigned i = 0; i != NumVars; ++i) |
| 12438 | Vars.push_back(Record.readSubExpr()); |
| 12439 | C->setFinals(Vars); |
| 12440 | C->setStep(Record.readSubExpr()); |
| 12441 | C->setCalcStep(Record.readSubExpr()); |
| 12442 | Vars.clear(); |
| 12443 | for (unsigned I = 0; I != NumVars + 1; ++I) |
| 12444 | Vars.push_back(Record.readSubExpr()); |
| 12445 | C->setUsedExprs(Vars); |
| 12446 | } |
| 12447 | |
| 12448 | void OMPClauseReader::VisitOMPAlignedClause(OMPAlignedClause *C) { |
| 12449 | C->setLParenLoc(Record.readSourceLocation()); |
| 12450 | C->setColonLoc(Record.readSourceLocation()); |
| 12451 | unsigned NumVars = C->varlist_size(); |
| 12452 | SmallVector<Expr *, 16> Vars; |
| 12453 | Vars.reserve(NumVars); |
| 12454 | for (unsigned i = 0; i != NumVars; ++i) |
| 12455 | Vars.push_back(Record.readSubExpr()); |
| 12456 | C->setVarRefs(Vars); |
| 12457 | C->setAlignment(Record.readSubExpr()); |
| 12458 | } |
| 12459 | |
| 12460 | void OMPClauseReader::VisitOMPCopyinClause(OMPCopyinClause *C) { |
| 12461 | C->setLParenLoc(Record.readSourceLocation()); |
| 12462 | unsigned NumVars = C->varlist_size(); |
| 12463 | SmallVector<Expr *, 16> Exprs; |
| 12464 | Exprs.reserve(NumVars); |
| 12465 | for (unsigned i = 0; i != NumVars; ++i) |
| 12466 | Exprs.push_back(Record.readSubExpr()); |
| 12467 | C->setVarRefs(Exprs); |
| 12468 | Exprs.clear(); |
| 12469 | for (unsigned i = 0; i != NumVars; ++i) |
| 12470 | Exprs.push_back(Record.readSubExpr()); |
| 12471 | C->setSourceExprs(Exprs); |
| 12472 | Exprs.clear(); |
| 12473 | for (unsigned i = 0; i != NumVars; ++i) |
| 12474 | Exprs.push_back(Record.readSubExpr()); |
| 12475 | C->setDestinationExprs(Exprs); |
| 12476 | Exprs.clear(); |
| 12477 | for (unsigned i = 0; i != NumVars; ++i) |
| 12478 | Exprs.push_back(Record.readSubExpr()); |
| 12479 | C->setAssignmentOps(Exprs); |
| 12480 | } |
| 12481 | |
| 12482 | void OMPClauseReader::VisitOMPCopyprivateClause(OMPCopyprivateClause *C) { |
| 12483 | C->setLParenLoc(Record.readSourceLocation()); |
| 12484 | unsigned NumVars = C->varlist_size(); |
| 12485 | SmallVector<Expr *, 16> Exprs; |
| 12486 | Exprs.reserve(NumVars); |
| 12487 | for (unsigned i = 0; i != NumVars; ++i) |
| 12488 | Exprs.push_back(Record.readSubExpr()); |
| 12489 | C->setVarRefs(Exprs); |
| 12490 | Exprs.clear(); |
| 12491 | for (unsigned i = 0; i != NumVars; ++i) |
| 12492 | Exprs.push_back(Record.readSubExpr()); |
| 12493 | C->setSourceExprs(Exprs); |
| 12494 | Exprs.clear(); |
| 12495 | for (unsigned i = 0; i != NumVars; ++i) |
| 12496 | Exprs.push_back(Record.readSubExpr()); |
| 12497 | C->setDestinationExprs(Exprs); |
| 12498 | Exprs.clear(); |
| 12499 | for (unsigned i = 0; i != NumVars; ++i) |
| 12500 | Exprs.push_back(Record.readSubExpr()); |
| 12501 | C->setAssignmentOps(Exprs); |
| 12502 | } |
| 12503 | |
| 12504 | void OMPClauseReader::VisitOMPFlushClause(OMPFlushClause *C) { |
| 12505 | C->setLParenLoc(Record.readSourceLocation()); |
| 12506 | unsigned NumVars = C->varlist_size(); |
| 12507 | SmallVector<Expr *, 16> Vars; |
| 12508 | Vars.reserve(NumVars); |
| 12509 | for (unsigned i = 0; i != NumVars; ++i) |
| 12510 | Vars.push_back(Record.readSubExpr()); |
| 12511 | C->setVarRefs(Vars); |
| 12512 | } |
| 12513 | |
| 12514 | void OMPClauseReader::VisitOMPDepobjClause(OMPDepobjClause *C) { |
| 12515 | C->setDepobj(Record.readSubExpr()); |
| 12516 | C->setLParenLoc(Record.readSourceLocation()); |
| 12517 | } |
| 12518 | |
| 12519 | void OMPClauseReader::VisitOMPDependClause(OMPDependClause *C) { |
| 12520 | C->setLParenLoc(Record.readSourceLocation()); |
| 12521 | C->setModifier(Record.readSubExpr()); |
| 12522 | C->setDependencyKind( |
| 12523 | static_cast<OpenMPDependClauseKind>(Record.readInt())); |
| 12524 | C->setDependencyLoc(Record.readSourceLocation()); |
| 12525 | C->setColonLoc(Record.readSourceLocation()); |
| 12526 | unsigned NumVars = C->varlist_size(); |
| 12527 | SmallVector<Expr *, 16> Vars; |
| 12528 | Vars.reserve(NumVars); |
| 12529 | for (unsigned I = 0; I != NumVars; ++I) |
| 12530 | Vars.push_back(Record.readSubExpr()); |
| 12531 | C->setVarRefs(Vars); |
| 12532 | for (unsigned I = 0, E = C->getNumLoops(); I < E; ++I) |
| 12533 | C->setLoopData(I, Record.readSubExpr()); |
| 12534 | } |
| 12535 | |
| 12536 | void OMPClauseReader::VisitOMPDeviceClause(OMPDeviceClause *C) { |
| 12537 | VisitOMPClauseWithPreInit(C); |
| 12538 | C->setModifier(Record.readEnum<OpenMPDeviceClauseModifier>()); |
| 12539 | C->setDevice(Record.readSubExpr()); |
| 12540 | C->setModifierLoc(Record.readSourceLocation()); |
| 12541 | C->setLParenLoc(Record.readSourceLocation()); |
| 12542 | } |
| 12543 | |
| 12544 | void OMPClauseReader::VisitOMPMapClause(OMPMapClause *C) { |
| 12545 | C->setLParenLoc(Record.readSourceLocation()); |
| 12546 | for (unsigned I = 0; I < NumberOfOMPMapClauseModifiers; ++I) { |
| 12547 | C->setMapTypeModifier( |
| 12548 | I, static_cast<OpenMPMapModifierKind>(Record.readInt())); |
| 12549 | C->setMapTypeModifierLoc(I, Record.readSourceLocation()); |
| 12550 | } |
| 12551 | C->setMapperQualifierLoc(Record.readNestedNameSpecifierLoc()); |
| 12552 | C->setMapperIdInfo(Record.readDeclarationNameInfo()); |
| 12553 | C->setMapType( |
| 12554 | static_cast<OpenMPMapClauseKind>(Record.readInt())); |
| 12555 | C->setMapLoc(Record.readSourceLocation()); |
| 12556 | C->setColonLoc(Record.readSourceLocation()); |
| 12557 | auto NumVars = C->varlist_size(); |
| 12558 | auto UniqueDecls = C->getUniqueDeclarationsNum(); |
| 12559 | auto TotalLists = C->getTotalComponentListNum(); |
| 12560 | auto TotalComponents = C->getTotalComponentsNum(); |
| 12561 | |
| 12562 | SmallVector<Expr *, 16> Vars; |
| 12563 | Vars.reserve(NumVars); |
| 12564 | for (unsigned i = 0; i != NumVars; ++i) |
| 12565 | Vars.push_back(Record.readExpr()); |
| 12566 | C->setVarRefs(Vars); |
| 12567 | |
| 12568 | SmallVector<Expr *, 16> UDMappers; |
| 12569 | UDMappers.reserve(NumVars); |
| 12570 | for (unsigned I = 0; I < NumVars; ++I) |
| 12571 | UDMappers.push_back(Record.readExpr()); |
| 12572 | C->setUDMapperRefs(UDMappers); |
| 12573 | |
| 12574 | SmallVector<ValueDecl *, 16> Decls; |
| 12575 | Decls.reserve(UniqueDecls); |
| 12576 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12577 | Decls.push_back(Record.readDeclAs<ValueDecl>()); |
| 12578 | C->setUniqueDecls(Decls); |
| 12579 | |
| 12580 | SmallVector<unsigned, 16> ListsPerDecl; |
| 12581 | ListsPerDecl.reserve(UniqueDecls); |
| 12582 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12583 | ListsPerDecl.push_back(Record.readInt()); |
| 12584 | C->setDeclNumLists(ListsPerDecl); |
| 12585 | |
| 12586 | SmallVector<unsigned, 32> ListSizes; |
| 12587 | ListSizes.reserve(TotalLists); |
| 12588 | for (unsigned i = 0; i < TotalLists; ++i) |
| 12589 | ListSizes.push_back(Record.readInt()); |
| 12590 | C->setComponentListSizes(ListSizes); |
| 12591 | |
| 12592 | SmallVector<OMPClauseMappableExprCommon::MappableComponent, 32> Components; |
| 12593 | Components.reserve(TotalComponents); |
| 12594 | for (unsigned i = 0; i < TotalComponents; ++i) { |
| 12595 | Expr *AssociatedExprPr = Record.readExpr(); |
| 12596 | auto *AssociatedDecl = Record.readDeclAs<ValueDecl>(); |
| 12597 | Components.emplace_back(AssociatedExprPr, AssociatedDecl, |
| 12598 | false); |
| 12599 | } |
| 12600 | C->setComponents(Components, ListSizes); |
| 12601 | } |
| 12602 | |
| 12603 | void OMPClauseReader::VisitOMPAllocateClause(OMPAllocateClause *C) { |
| 12604 | C->setLParenLoc(Record.readSourceLocation()); |
| 12605 | C->setColonLoc(Record.readSourceLocation()); |
| 12606 | C->setAllocator(Record.readSubExpr()); |
| 12607 | unsigned NumVars = C->varlist_size(); |
| 12608 | SmallVector<Expr *, 16> Vars; |
| 12609 | Vars.reserve(NumVars); |
| 12610 | for (unsigned i = 0; i != NumVars; ++i) |
| 12611 | Vars.push_back(Record.readSubExpr()); |
| 12612 | C->setVarRefs(Vars); |
| 12613 | } |
| 12614 | |
| 12615 | void OMPClauseReader::VisitOMPNumTeamsClause(OMPNumTeamsClause *C) { |
| 12616 | VisitOMPClauseWithPreInit(C); |
| 12617 | C->setNumTeams(Record.readSubExpr()); |
| 12618 | C->setLParenLoc(Record.readSourceLocation()); |
| 12619 | } |
| 12620 | |
| 12621 | void OMPClauseReader::VisitOMPThreadLimitClause(OMPThreadLimitClause *C) { |
| 12622 | VisitOMPClauseWithPreInit(C); |
| 12623 | C->setThreadLimit(Record.readSubExpr()); |
| 12624 | C->setLParenLoc(Record.readSourceLocation()); |
| 12625 | } |
| 12626 | |
| 12627 | void OMPClauseReader::VisitOMPPriorityClause(OMPPriorityClause *C) { |
| 12628 | VisitOMPClauseWithPreInit(C); |
| 12629 | C->setPriority(Record.readSubExpr()); |
| 12630 | C->setLParenLoc(Record.readSourceLocation()); |
| 12631 | } |
| 12632 | |
| 12633 | void OMPClauseReader::VisitOMPGrainsizeClause(OMPGrainsizeClause *C) { |
| 12634 | VisitOMPClauseWithPreInit(C); |
| 12635 | C->setGrainsize(Record.readSubExpr()); |
| 12636 | C->setLParenLoc(Record.readSourceLocation()); |
| 12637 | } |
| 12638 | |
| 12639 | void OMPClauseReader::VisitOMPNumTasksClause(OMPNumTasksClause *C) { |
| 12640 | VisitOMPClauseWithPreInit(C); |
| 12641 | C->setNumTasks(Record.readSubExpr()); |
| 12642 | C->setLParenLoc(Record.readSourceLocation()); |
| 12643 | } |
| 12644 | |
| 12645 | void OMPClauseReader::VisitOMPHintClause(OMPHintClause *C) { |
| 12646 | C->setHint(Record.readSubExpr()); |
| 12647 | C->setLParenLoc(Record.readSourceLocation()); |
| 12648 | } |
| 12649 | |
| 12650 | void OMPClauseReader::VisitOMPDistScheduleClause(OMPDistScheduleClause *C) { |
| 12651 | VisitOMPClauseWithPreInit(C); |
| 12652 | C->setDistScheduleKind( |
| 12653 | static_cast<OpenMPDistScheduleClauseKind>(Record.readInt())); |
| 12654 | C->setChunkSize(Record.readSubExpr()); |
| 12655 | C->setLParenLoc(Record.readSourceLocation()); |
| 12656 | C->setDistScheduleKindLoc(Record.readSourceLocation()); |
| 12657 | C->setCommaLoc(Record.readSourceLocation()); |
| 12658 | } |
| 12659 | |
| 12660 | void OMPClauseReader::VisitOMPDefaultmapClause(OMPDefaultmapClause *C) { |
| 12661 | C->setDefaultmapKind( |
| 12662 | static_cast<OpenMPDefaultmapClauseKind>(Record.readInt())); |
| 12663 | C->setDefaultmapModifier( |
| 12664 | static_cast<OpenMPDefaultmapClauseModifier>(Record.readInt())); |
| 12665 | C->setLParenLoc(Record.readSourceLocation()); |
| 12666 | C->setDefaultmapModifierLoc(Record.readSourceLocation()); |
| 12667 | C->setDefaultmapKindLoc(Record.readSourceLocation()); |
| 12668 | } |
| 12669 | |
| 12670 | void OMPClauseReader::VisitOMPToClause(OMPToClause *C) { |
| 12671 | C->setLParenLoc(Record.readSourceLocation()); |
| 12672 | for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) { |
| 12673 | C->setMotionModifier( |
| 12674 | I, static_cast<OpenMPMotionModifierKind>(Record.readInt())); |
| 12675 | C->setMotionModifierLoc(I, Record.readSourceLocation()); |
| 12676 | } |
| 12677 | C->setMapperQualifierLoc(Record.readNestedNameSpecifierLoc()); |
| 12678 | C->setMapperIdInfo(Record.readDeclarationNameInfo()); |
| 12679 | C->setColonLoc(Record.readSourceLocation()); |
| 12680 | auto NumVars = C->varlist_size(); |
| 12681 | auto UniqueDecls = C->getUniqueDeclarationsNum(); |
| 12682 | auto TotalLists = C->getTotalComponentListNum(); |
| 12683 | auto TotalComponents = C->getTotalComponentsNum(); |
| 12684 | |
| 12685 | SmallVector<Expr *, 16> Vars; |
| 12686 | Vars.reserve(NumVars); |
| 12687 | for (unsigned i = 0; i != NumVars; ++i) |
| 12688 | Vars.push_back(Record.readSubExpr()); |
| 12689 | C->setVarRefs(Vars); |
| 12690 | |
| 12691 | SmallVector<Expr *, 16> UDMappers; |
| 12692 | UDMappers.reserve(NumVars); |
| 12693 | for (unsigned I = 0; I < NumVars; ++I) |
| 12694 | UDMappers.push_back(Record.readSubExpr()); |
| 12695 | C->setUDMapperRefs(UDMappers); |
| 12696 | |
| 12697 | SmallVector<ValueDecl *, 16> Decls; |
| 12698 | Decls.reserve(UniqueDecls); |
| 12699 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12700 | Decls.push_back(Record.readDeclAs<ValueDecl>()); |
| 12701 | C->setUniqueDecls(Decls); |
| 12702 | |
| 12703 | SmallVector<unsigned, 16> ListsPerDecl; |
| 12704 | ListsPerDecl.reserve(UniqueDecls); |
| 12705 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12706 | ListsPerDecl.push_back(Record.readInt()); |
| 12707 | C->setDeclNumLists(ListsPerDecl); |
| 12708 | |
| 12709 | SmallVector<unsigned, 32> ListSizes; |
| 12710 | ListSizes.reserve(TotalLists); |
| 12711 | for (unsigned i = 0; i < TotalLists; ++i) |
| 12712 | ListSizes.push_back(Record.readInt()); |
| 12713 | C->setComponentListSizes(ListSizes); |
| 12714 | |
| 12715 | SmallVector<OMPClauseMappableExprCommon::MappableComponent, 32> Components; |
| 12716 | Components.reserve(TotalComponents); |
| 12717 | for (unsigned i = 0; i < TotalComponents; ++i) { |
| 12718 | Expr *AssociatedExprPr = Record.readSubExpr(); |
| 12719 | bool IsNonContiguous = Record.readBool(); |
| 12720 | auto *AssociatedDecl = Record.readDeclAs<ValueDecl>(); |
| 12721 | Components.emplace_back(AssociatedExprPr, AssociatedDecl, IsNonContiguous); |
| 12722 | } |
| 12723 | C->setComponents(Components, ListSizes); |
| 12724 | } |
| 12725 | |
| 12726 | void OMPClauseReader::VisitOMPFromClause(OMPFromClause *C) { |
| 12727 | C->setLParenLoc(Record.readSourceLocation()); |
| 12728 | for (unsigned I = 0; I < NumberOfOMPMotionModifiers; ++I) { |
| 12729 | C->setMotionModifier( |
| 12730 | I, static_cast<OpenMPMotionModifierKind>(Record.readInt())); |
| 12731 | C->setMotionModifierLoc(I, Record.readSourceLocation()); |
| 12732 | } |
| 12733 | C->setMapperQualifierLoc(Record.readNestedNameSpecifierLoc()); |
| 12734 | C->setMapperIdInfo(Record.readDeclarationNameInfo()); |
| 12735 | C->setColonLoc(Record.readSourceLocation()); |
| 12736 | auto NumVars = C->varlist_size(); |
| 12737 | auto UniqueDecls = C->getUniqueDeclarationsNum(); |
| 12738 | auto TotalLists = C->getTotalComponentListNum(); |
| 12739 | auto TotalComponents = C->getTotalComponentsNum(); |
| 12740 | |
| 12741 | SmallVector<Expr *, 16> Vars; |
| 12742 | Vars.reserve(NumVars); |
| 12743 | for (unsigned i = 0; i != NumVars; ++i) |
| 12744 | Vars.push_back(Record.readSubExpr()); |
| 12745 | C->setVarRefs(Vars); |
| 12746 | |
| 12747 | SmallVector<Expr *, 16> UDMappers; |
| 12748 | UDMappers.reserve(NumVars); |
| 12749 | for (unsigned I = 0; I < NumVars; ++I) |
| 12750 | UDMappers.push_back(Record.readSubExpr()); |
| 12751 | C->setUDMapperRefs(UDMappers); |
| 12752 | |
| 12753 | SmallVector<ValueDecl *, 16> Decls; |
| 12754 | Decls.reserve(UniqueDecls); |
| 12755 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12756 | Decls.push_back(Record.readDeclAs<ValueDecl>()); |
| 12757 | C->setUniqueDecls(Decls); |
| 12758 | |
| 12759 | SmallVector<unsigned, 16> ListsPerDecl; |
| 12760 | ListsPerDecl.reserve(UniqueDecls); |
| 12761 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12762 | ListsPerDecl.push_back(Record.readInt()); |
| 12763 | C->setDeclNumLists(ListsPerDecl); |
| 12764 | |
| 12765 | SmallVector<unsigned, 32> ListSizes; |
| 12766 | ListSizes.reserve(TotalLists); |
| 12767 | for (unsigned i = 0; i < TotalLists; ++i) |
| 12768 | ListSizes.push_back(Record.readInt()); |
| 12769 | C->setComponentListSizes(ListSizes); |
| 12770 | |
| 12771 | SmallVector<OMPClauseMappableExprCommon::MappableComponent, 32> Components; |
| 12772 | Components.reserve(TotalComponents); |
| 12773 | for (unsigned i = 0; i < TotalComponents; ++i) { |
| 12774 | Expr *AssociatedExprPr = Record.readSubExpr(); |
| 12775 | bool IsNonContiguous = Record.readBool(); |
| 12776 | auto *AssociatedDecl = Record.readDeclAs<ValueDecl>(); |
| 12777 | Components.emplace_back(AssociatedExprPr, AssociatedDecl, IsNonContiguous); |
| 12778 | } |
| 12779 | C->setComponents(Components, ListSizes); |
| 12780 | } |
| 12781 | |
| 12782 | void OMPClauseReader::VisitOMPUseDevicePtrClause(OMPUseDevicePtrClause *C) { |
| 12783 | C->setLParenLoc(Record.readSourceLocation()); |
| 12784 | auto NumVars = C->varlist_size(); |
| 12785 | auto UniqueDecls = C->getUniqueDeclarationsNum(); |
| 12786 | auto TotalLists = C->getTotalComponentListNum(); |
| 12787 | auto TotalComponents = C->getTotalComponentsNum(); |
| 12788 | |
| 12789 | SmallVector<Expr *, 16> Vars; |
| 12790 | Vars.reserve(NumVars); |
| 12791 | for (unsigned i = 0; i != NumVars; ++i) |
| 12792 | Vars.push_back(Record.readSubExpr()); |
| 12793 | C->setVarRefs(Vars); |
| 12794 | Vars.clear(); |
| 12795 | for (unsigned i = 0; i != NumVars; ++i) |
| 12796 | Vars.push_back(Record.readSubExpr()); |
| 12797 | C->setPrivateCopies(Vars); |
| 12798 | Vars.clear(); |
| 12799 | for (unsigned i = 0; i != NumVars; ++i) |
| 12800 | Vars.push_back(Record.readSubExpr()); |
| 12801 | C->setInits(Vars); |
| 12802 | |
| 12803 | SmallVector<ValueDecl *, 16> Decls; |
| 12804 | Decls.reserve(UniqueDecls); |
| 12805 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12806 | Decls.push_back(Record.readDeclAs<ValueDecl>()); |
| 12807 | C->setUniqueDecls(Decls); |
| 12808 | |
| 12809 | SmallVector<unsigned, 16> ListsPerDecl; |
| 12810 | ListsPerDecl.reserve(UniqueDecls); |
| 12811 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12812 | ListsPerDecl.push_back(Record.readInt()); |
| 12813 | C->setDeclNumLists(ListsPerDecl); |
| 12814 | |
| 12815 | SmallVector<unsigned, 32> ListSizes; |
| 12816 | ListSizes.reserve(TotalLists); |
| 12817 | for (unsigned i = 0; i < TotalLists; ++i) |
| 12818 | ListSizes.push_back(Record.readInt()); |
| 12819 | C->setComponentListSizes(ListSizes); |
| 12820 | |
| 12821 | SmallVector<OMPClauseMappableExprCommon::MappableComponent, 32> Components; |
| 12822 | Components.reserve(TotalComponents); |
| 12823 | for (unsigned i = 0; i < TotalComponents; ++i) { |
| 12824 | auto *AssociatedExprPr = Record.readSubExpr(); |
| 12825 | auto *AssociatedDecl = Record.readDeclAs<ValueDecl>(); |
| 12826 | Components.emplace_back(AssociatedExprPr, AssociatedDecl, |
| 12827 | false); |
| 12828 | } |
| 12829 | C->setComponents(Components, ListSizes); |
| 12830 | } |
| 12831 | |
| 12832 | void OMPClauseReader::VisitOMPUseDeviceAddrClause(OMPUseDeviceAddrClause *C) { |
| 12833 | C->setLParenLoc(Record.readSourceLocation()); |
| 12834 | auto NumVars = C->varlist_size(); |
| 12835 | auto UniqueDecls = C->getUniqueDeclarationsNum(); |
| 12836 | auto TotalLists = C->getTotalComponentListNum(); |
| 12837 | auto TotalComponents = C->getTotalComponentsNum(); |
| 12838 | |
| 12839 | SmallVector<Expr *, 16> Vars; |
| 12840 | Vars.reserve(NumVars); |
| 12841 | for (unsigned i = 0; i != NumVars; ++i) |
| 12842 | Vars.push_back(Record.readSubExpr()); |
| 12843 | C->setVarRefs(Vars); |
| 12844 | |
| 12845 | SmallVector<ValueDecl *, 16> Decls; |
| 12846 | Decls.reserve(UniqueDecls); |
| 12847 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12848 | Decls.push_back(Record.readDeclAs<ValueDecl>()); |
| 12849 | C->setUniqueDecls(Decls); |
| 12850 | |
| 12851 | SmallVector<unsigned, 16> ListsPerDecl; |
| 12852 | ListsPerDecl.reserve(UniqueDecls); |
| 12853 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12854 | ListsPerDecl.push_back(Record.readInt()); |
| 12855 | C->setDeclNumLists(ListsPerDecl); |
| 12856 | |
| 12857 | SmallVector<unsigned, 32> ListSizes; |
| 12858 | ListSizes.reserve(TotalLists); |
| 12859 | for (unsigned i = 0; i < TotalLists; ++i) |
| 12860 | ListSizes.push_back(Record.readInt()); |
| 12861 | C->setComponentListSizes(ListSizes); |
| 12862 | |
| 12863 | SmallVector<OMPClauseMappableExprCommon::MappableComponent, 32> Components; |
| 12864 | Components.reserve(TotalComponents); |
| 12865 | for (unsigned i = 0; i < TotalComponents; ++i) { |
| 12866 | Expr *AssociatedExpr = Record.readSubExpr(); |
| 12867 | auto *AssociatedDecl = Record.readDeclAs<ValueDecl>(); |
| 12868 | Components.emplace_back(AssociatedExpr, AssociatedDecl, |
| 12869 | false); |
| 12870 | } |
| 12871 | C->setComponents(Components, ListSizes); |
| 12872 | } |
| 12873 | |
| 12874 | void OMPClauseReader::VisitOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) { |
| 12875 | C->setLParenLoc(Record.readSourceLocation()); |
| 12876 | auto NumVars = C->varlist_size(); |
| 12877 | auto UniqueDecls = C->getUniqueDeclarationsNum(); |
| 12878 | auto TotalLists = C->getTotalComponentListNum(); |
| 12879 | auto TotalComponents = C->getTotalComponentsNum(); |
| 12880 | |
| 12881 | SmallVector<Expr *, 16> Vars; |
| 12882 | Vars.reserve(NumVars); |
| 12883 | for (unsigned i = 0; i != NumVars; ++i) |
| 12884 | Vars.push_back(Record.readSubExpr()); |
| 12885 | C->setVarRefs(Vars); |
| 12886 | Vars.clear(); |
| 12887 | |
| 12888 | SmallVector<ValueDecl *, 16> Decls; |
| 12889 | Decls.reserve(UniqueDecls); |
| 12890 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12891 | Decls.push_back(Record.readDeclAs<ValueDecl>()); |
| 12892 | C->setUniqueDecls(Decls); |
| 12893 | |
| 12894 | SmallVector<unsigned, 16> ListsPerDecl; |
| 12895 | ListsPerDecl.reserve(UniqueDecls); |
| 12896 | for (unsigned i = 0; i < UniqueDecls; ++i) |
| 12897 | ListsPerDecl.push_back(Record.readInt()); |
| 12898 | C->setDeclNumLists(ListsPerDecl); |
| 12899 | |
| 12900 | SmallVector<unsigned, 32> ListSizes; |
| 12901 | ListSizes.reserve(TotalLists); |
| 12902 | for (unsigned i = 0; i < TotalLists; ++i) |
| 12903 | ListSizes.push_back(Record.readInt()); |
| 12904 | C->setComponentListSizes(ListSizes); |
| 12905 | |
| 12906 | SmallVector<OMPClauseMappableExprCommon::MappableComponent, 32> Components; |
| 12907 | Components.reserve(TotalComponents); |
| 12908 | for (unsigned i = 0; i < TotalComponents; ++i) { |
| 12909 | Expr *AssociatedExpr = Record.readSubExpr(); |
| 12910 | auto *AssociatedDecl = Record.readDeclAs<ValueDecl>(); |
| 12911 | Components.emplace_back(AssociatedExpr, AssociatedDecl, |
| 12912 | false); |
| 12913 | } |
| 12914 | C->setComponents(Components, ListSizes); |
| 12915 | } |
| 12916 | |
| 12917 | void OMPClauseReader::VisitOMPNontemporalClause(OMPNontemporalClause *C) { |
| 12918 | C->setLParenLoc(Record.readSourceLocation()); |
| 12919 | unsigned NumVars = C->varlist_size(); |
| 12920 | SmallVector<Expr *, 16> Vars; |
| 12921 | Vars.reserve(NumVars); |
| 12922 | for (unsigned i = 0; i != NumVars; ++i) |
| 12923 | Vars.push_back(Record.readSubExpr()); |
| 12924 | C->setVarRefs(Vars); |
| 12925 | Vars.clear(); |
| 12926 | Vars.reserve(NumVars); |
| 12927 | for (unsigned i = 0; i != NumVars; ++i) |
| 12928 | Vars.push_back(Record.readSubExpr()); |
| 12929 | C->setPrivateRefs(Vars); |
| 12930 | } |
| 12931 | |
| 12932 | void OMPClauseReader::VisitOMPInclusiveClause(OMPInclusiveClause *C) { |
| 12933 | C->setLParenLoc(Record.readSourceLocation()); |
| 12934 | unsigned NumVars = C->varlist_size(); |
| 12935 | SmallVector<Expr *, 16> Vars; |
| 12936 | Vars.reserve(NumVars); |
| 12937 | for (unsigned i = 0; i != NumVars; ++i) |
| 12938 | Vars.push_back(Record.readSubExpr()); |
| 12939 | C->setVarRefs(Vars); |
| 12940 | } |
| 12941 | |
| 12942 | void OMPClauseReader::VisitOMPExclusiveClause(OMPExclusiveClause *C) { |
| 12943 | C->setLParenLoc(Record.readSourceLocation()); |
| 12944 | unsigned NumVars = C->varlist_size(); |
| 12945 | SmallVector<Expr *, 16> Vars; |
| 12946 | Vars.reserve(NumVars); |
| 12947 | for (unsigned i = 0; i != NumVars; ++i) |
| 12948 | Vars.push_back(Record.readSubExpr()); |
| 12949 | C->setVarRefs(Vars); |
| 12950 | } |
| 12951 | |
| 12952 | void OMPClauseReader::VisitOMPUsesAllocatorsClause(OMPUsesAllocatorsClause *C) { |
| 12953 | C->setLParenLoc(Record.readSourceLocation()); |
| 12954 | unsigned NumOfAllocators = C->getNumberOfAllocators(); |
| 12955 | SmallVector<OMPUsesAllocatorsClause::Data, 4> Data; |
| 12956 | Data.reserve(NumOfAllocators); |
| 12957 | for (unsigned I = 0; I != NumOfAllocators; ++I) { |
| 12958 | OMPUsesAllocatorsClause::Data &D = Data.emplace_back(); |
| 12959 | D.Allocator = Record.readSubExpr(); |
| 12960 | D.AllocatorTraits = Record.readSubExpr(); |
| 12961 | D.LParenLoc = Record.readSourceLocation(); |
| 12962 | D.RParenLoc = Record.readSourceLocation(); |
| 12963 | } |
| 12964 | C->setAllocatorsData(Data); |
| 12965 | } |
| 12966 | |
| 12967 | void OMPClauseReader::VisitOMPAffinityClause(OMPAffinityClause *C) { |
| 12968 | C->setLParenLoc(Record.readSourceLocation()); |
| 12969 | C->setModifier(Record.readSubExpr()); |
| 12970 | C->setColonLoc(Record.readSourceLocation()); |
| 12971 | unsigned NumOfLocators = C->varlist_size(); |
| 12972 | SmallVector<Expr *, 4> Locators; |
| 12973 | Locators.reserve(NumOfLocators); |
| 12974 | for (unsigned I = 0; I != NumOfLocators; ++I) |
| 12975 | Locators.push_back(Record.readSubExpr()); |
| 12976 | C->setVarRefs(Locators); |
| 12977 | } |
| 12978 | |
| 12979 | void OMPClauseReader::VisitOMPOrderClause(OMPOrderClause *C) { |
| 12980 | C->setKind(Record.readEnum<OpenMPOrderClauseKind>()); |
| 12981 | C->setLParenLoc(Record.readSourceLocation()); |
| 12982 | C->setKindKwLoc(Record.readSourceLocation()); |
| 12983 | } |
| 12984 | |
| 12985 | void OMPClauseReader::VisitOMPFilterClause(OMPFilterClause *C) { |
| 12986 | VisitOMPClauseWithPreInit(C); |
| 12987 | C->setThreadID(Record.readSubExpr()); |
| 12988 | C->setLParenLoc(Record.readSourceLocation()); |
| 12989 | } |
| 12990 | |
| 12991 | OMPTraitInfo *ASTRecordReader::readOMPTraitInfo() { |
| 12992 | OMPTraitInfo &TI = getContext().getNewOMPTraitInfo(); |
| 12993 | TI.Sets.resize(readUInt32()); |
| 12994 | for (auto &Set : TI.Sets) { |
| 12995 | Set.Kind = readEnum<llvm::omp::TraitSet>(); |
| 12996 | Set.Selectors.resize(readUInt32()); |
| 12997 | for (auto &Selector : Set.Selectors) { |
| 12998 | Selector.Kind = readEnum<llvm::omp::TraitSelector>(); |
| 12999 | Selector.ScoreOrCondition = nullptr; |
| 13000 | if (readBool()) |
| 13001 | Selector.ScoreOrCondition = readExprRef(); |
| 13002 | Selector.Properties.resize(readUInt32()); |
| 13003 | for (auto &Property : Selector.Properties) |
| 13004 | Property.Kind = readEnum<llvm::omp::TraitProperty>(); |
| 13005 | } |
| 13006 | } |
| 13007 | return &TI; |
| 13008 | } |
| 13009 | |
| 13010 | void ASTRecordReader::readOMPChildren(OMPChildren *Data) { |
| 13011 | if (!Data) |
| 13012 | return; |
| 13013 | if (Reader->ReadingKind == ASTReader::Read_Stmt) { |
| 13014 | |
| 13015 | skipInts(3); |
| 13016 | } |
| 13017 | SmallVector<OMPClause *, 4> Clauses(Data->getNumClauses()); |
| 13018 | for (unsigned I = 0, E = Data->getNumClauses(); I < E; ++I) |
| 13019 | Clauses[I] = readOMPClause(); |
| 13020 | Data->setClauses(Clauses); |
| 13021 | if (Data->hasAssociatedStmt()) |
| 13022 | Data->setAssociatedStmt(readStmt()); |
| 13023 | for (unsigned I = 0, E = Data->getNumChildren(); I < E; ++I) |
| 13024 | Data->getChildren()[I] = readStmt(); |
| 13025 | } |
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | #ifndef LLVM_CLANG_AST_TYPE_H |
| 18 | #define LLVM_CLANG_AST_TYPE_H |
| 19 | |
| 20 | #include "clang/AST/DependenceFlags.h" |
| 21 | #include "clang/AST/NestedNameSpecifier.h" |
| 22 | #include "clang/AST/TemplateName.h" |
| 23 | #include "clang/Basic/AddressSpaces.h" |
| 24 | #include "clang/Basic/AttrKinds.h" |
| 25 | #include "clang/Basic/Diagnostic.h" |
| 26 | #include "clang/Basic/ExceptionSpecificationType.h" |
| 27 | #include "clang/Basic/LLVM.h" |
| 28 | #include "clang/Basic/Linkage.h" |
| 29 | #include "clang/Basic/PartialDiagnostic.h" |
| 30 | #include "clang/Basic/SourceLocation.h" |
| 31 | #include "clang/Basic/Specifiers.h" |
| 32 | #include "clang/Basic/Visibility.h" |
| 33 | #include "llvm/ADT/APInt.h" |
| 34 | #include "llvm/ADT/APSInt.h" |
| 35 | #include "llvm/ADT/ArrayRef.h" |
| 36 | #include "llvm/ADT/FoldingSet.h" |
| 37 | #include "llvm/ADT/None.h" |
| 38 | #include "llvm/ADT/Optional.h" |
| 39 | #include "llvm/ADT/PointerIntPair.h" |
| 40 | #include "llvm/ADT/PointerUnion.h" |
| 41 | #include "llvm/ADT/StringRef.h" |
| 42 | #include "llvm/ADT/Twine.h" |
| 43 | #include "llvm/ADT/iterator_range.h" |
| 44 | #include "llvm/Support/Casting.h" |
| 45 | #include "llvm/Support/Compiler.h" |
| 46 | #include "llvm/Support/ErrorHandling.h" |
| 47 | #include "llvm/Support/PointerLikeTypeTraits.h" |
| 48 | #include "llvm/Support/TrailingObjects.h" |
| 49 | #include "llvm/Support/type_traits.h" |
| 50 | #include <cassert> |
| 51 | #include <cstddef> |
| 52 | #include <cstdint> |
| 53 | #include <cstring> |
| 54 | #include <string> |
| 55 | #include <type_traits> |
| 56 | #include <utility> |
| 57 | |
| 58 | namespace clang { |
| 59 | |
| 60 | class ExtQuals; |
| 61 | class QualType; |
| 62 | class ConceptDecl; |
| 63 | class TagDecl; |
| 64 | class TemplateParameterList; |
| 65 | class Type; |
| 66 | |
| 67 | enum { |
| 68 | TypeAlignmentInBits = 4, |
| 69 | TypeAlignment = 1 << TypeAlignmentInBits |
| 70 | }; |
| 71 | |
| 72 | namespace serialization { |
| 73 | template <class T> class AbstractTypeReader; |
| 74 | template <class T> class AbstractTypeWriter; |
| 75 | } |
| 76 | |
| 77 | } |
| 78 | |
| 79 | namespace llvm { |
| 80 | |
| 81 | template <typename T> |
| 82 | struct PointerLikeTypeTraits; |
| 83 | template<> |
| 84 | struct PointerLikeTypeTraits< ::clang::Type*> { |
| 85 | static inline void *getAsVoidPointer(::clang::Type *P) { return P; } |
| 86 | |
| 87 | static inline ::clang::Type *getFromVoidPointer(void *P) { |
| 88 | return static_cast< ::clang::Type*>(P); |
| 89 | } |
| 90 | |
| 91 | static constexpr int NumLowBitsAvailable = clang::TypeAlignmentInBits; |
| 92 | }; |
| 93 | |
| 94 | template<> |
| 95 | struct PointerLikeTypeTraits< ::clang::ExtQuals*> { |
| 96 | static inline void *getAsVoidPointer(::clang::ExtQuals *P) { return P; } |
| 97 | |
| 98 | static inline ::clang::ExtQuals *getFromVoidPointer(void *P) { |
| 99 | return static_cast< ::clang::ExtQuals*>(P); |
| 100 | } |
| 101 | |
| 102 | static constexpr int NumLowBitsAvailable = clang::TypeAlignmentInBits; |
| 103 | }; |
| 104 | |
| 105 | } |
| 106 | |
| 107 | namespace clang { |
| 108 | |
| 109 | class ASTContext; |
| 110 | template <typename> class CanQual; |
| 111 | class CXXRecordDecl; |
| 112 | class DeclContext; |
| 113 | class EnumDecl; |
| 114 | class Expr; |
| 115 | class ExtQualsTypeCommonBase; |
| 116 | class FunctionDecl; |
| 117 | class IdentifierInfo; |
| 118 | class NamedDecl; |
| 119 | class ObjCInterfaceDecl; |
| 120 | class ObjCProtocolDecl; |
| 121 | class ObjCTypeParamDecl; |
| 122 | struct PrintingPolicy; |
| 123 | class RecordDecl; |
| 124 | class Stmt; |
| 125 | class TagDecl; |
| 126 | class TemplateArgument; |
| 127 | class TemplateArgumentListInfo; |
| 128 | class TemplateArgumentLoc; |
| 129 | class TemplateTypeParmDecl; |
| 130 | class TypedefNameDecl; |
| 131 | class UnresolvedUsingTypenameDecl; |
| 132 | |
| 133 | using CanQualType = CanQual<Type>; |
| 134 | |
| 135 | |
| 136 | #define TYPE(Class, Base) class Class##Type; |
| 137 | #include "clang/AST/TypeNodes.inc" |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | class Qualifiers { |
| 146 | public: |
| 147 | enum TQ { |
| 148 | Const = 0x1, |
| 149 | Restrict = 0x2, |
| 150 | Volatile = 0x4, |
| 151 | CVRMask = Const | Volatile | Restrict |
| 152 | }; |
| 153 | |
| 154 | enum GC { |
| 155 | GCNone = 0, |
| 156 | Weak, |
| 157 | Strong |
| 158 | }; |
| 159 | |
| 160 | enum ObjCLifetime { |
| 161 | |
| 162 | OCL_None, |
| 163 | |
| 164 | |
| 165 | |
| 166 | OCL_ExplicitNone, |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | OCL_Strong, |
| 174 | |
| 175 | |
| 176 | OCL_Weak, |
| 177 | |
| 178 | |
| 179 | OCL_Autoreleasing |
| 180 | }; |
| 181 | |
| 182 | enum { |
| 183 | |
| 184 | |
| 185 | MaxAddressSpace = 0x7fffffu, |
| 186 | |
| 187 | |
| 188 | FastWidth = 3, |
| 189 | |
| 190 | |
| 191 | FastMask = (1 << FastWidth) - 1 |
| 192 | }; |
| 193 | |
| 194 | |
| 195 | |
| 196 | static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R) { |
| 197 | |
| 198 | if (!(L.Mask & ~CVRMask) && !(R.Mask & ~CVRMask)) { |
| 199 | Qualifiers Q; |
| 200 | Q.Mask = L.Mask & R.Mask; |
| 201 | L.Mask &= ~Q.Mask; |
| 202 | R.Mask &= ~Q.Mask; |
| 203 | return Q; |
| 204 | } |
| 205 | |
| 206 | Qualifiers Q; |
| 207 | unsigned CommonCRV = L.getCVRQualifiers() & R.getCVRQualifiers(); |
| 208 | Q.addCVRQualifiers(CommonCRV); |
| 209 | L.removeCVRQualifiers(CommonCRV); |
| 210 | R.removeCVRQualifiers(CommonCRV); |
| 211 | |
| 212 | if (L.getObjCGCAttr() == R.getObjCGCAttr()) { |
| 213 | Q.setObjCGCAttr(L.getObjCGCAttr()); |
| 214 | L.removeObjCGCAttr(); |
| 215 | R.removeObjCGCAttr(); |
| 216 | } |
| 217 | |
| 218 | if (L.getObjCLifetime() == R.getObjCLifetime()) { |
| 219 | Q.setObjCLifetime(L.getObjCLifetime()); |
| 220 | L.removeObjCLifetime(); |
| 221 | R.removeObjCLifetime(); |
| 222 | } |
| 223 | |
| 224 | if (L.getAddressSpace() == R.getAddressSpace()) { |
| 225 | Q.setAddressSpace(L.getAddressSpace()); |
| 226 | L.removeAddressSpace(); |
| 227 | R.removeAddressSpace(); |
| 228 | } |
| 229 | return Q; |
| 230 | } |
| 231 | |
| 232 | static Qualifiers fromFastMask(unsigned Mask) { |
| 233 | Qualifiers Qs; |
| 234 | Qs.addFastQualifiers(Mask); |
| 235 | return Qs; |
| 236 | } |
| 237 | |
| 238 | static Qualifiers fromCVRMask(unsigned CVR) { |
| 239 | Qualifiers Qs; |
| 240 | Qs.addCVRQualifiers(CVR); |
| 241 | return Qs; |
| 242 | } |
| 243 | |
| 244 | static Qualifiers fromCVRUMask(unsigned CVRU) { |
| 245 | Qualifiers Qs; |
| 246 | Qs.addCVRUQualifiers(CVRU); |
| 247 | return Qs; |
| 248 | } |
| 249 | |
| 250 | |
| 251 | static Qualifiers fromOpaqueValue(unsigned opaque) { |
| 252 | Qualifiers Qs; |
| 253 | Qs.Mask = opaque; |
| 254 | return Qs; |
| 255 | } |
| 256 | |
| 257 | |
| 258 | unsigned getAsOpaqueValue() const { |
| 259 | return Mask; |
| 260 | } |
| 261 | |
| 262 | bool hasConst() const { return Mask & Const; } |
| 263 | bool hasOnlyConst() const { return Mask == Const; } |
| 264 | void removeConst() { Mask &= ~Const; } |
| 265 | void addConst() { Mask |= Const; } |
| 266 | |
| 267 | bool hasVolatile() const { return Mask & Volatile; } |
| 268 | bool hasOnlyVolatile() const { return Mask == Volatile; } |
| 269 | void removeVolatile() { Mask &= ~Volatile; } |
| 270 | void addVolatile() { Mask |= Volatile; } |
| 271 | |
| 272 | bool hasRestrict() const { return Mask & Restrict; } |
| 273 | bool hasOnlyRestrict() const { return Mask == Restrict; } |
| 274 | void removeRestrict() { Mask &= ~Restrict; } |
| 275 | void addRestrict() { Mask |= Restrict; } |
| 276 | |
| 277 | bool hasCVRQualifiers() const { return getCVRQualifiers(); } |
| 278 | unsigned getCVRQualifiers() const { return Mask & CVRMask; } |
| 279 | unsigned getCVRUQualifiers() const { return Mask & (CVRMask | UMask); } |
| 280 | |
| 281 | void setCVRQualifiers(unsigned mask) { |
| 282 | assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); |
| 283 | Mask = (Mask & ~CVRMask) | mask; |
| 284 | } |
| 285 | void removeCVRQualifiers(unsigned mask) { |
| 286 | assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); |
| 287 | Mask &= ~mask; |
| 288 | } |
| 289 | void removeCVRQualifiers() { |
| 290 | removeCVRQualifiers(CVRMask); |
| 291 | } |
| 292 | void addCVRQualifiers(unsigned mask) { |
| 293 | assert(!(mask & ~CVRMask) && "bitmask contains non-CVR bits"); |
| 294 | Mask |= mask; |
| 295 | } |
| 296 | void addCVRUQualifiers(unsigned mask) { |
| 297 | assert(!(mask & ~CVRMask & ~UMask) && "bitmask contains non-CVRU bits"); |
| 298 | Mask |= mask; |
| 299 | } |
| 300 | |
| 301 | bool hasUnaligned() const { return Mask & UMask; } |
| 302 | void setUnaligned(bool flag) { |
| 303 | Mask = (Mask & ~UMask) | (flag ? UMask : 0); |
| 304 | } |
| 305 | void removeUnaligned() { Mask &= ~UMask; } |
| 306 | void addUnaligned() { Mask |= UMask; } |
| 307 | |
| 308 | bool hasObjCGCAttr() const { return Mask & GCAttrMask; } |
| 309 | GC getObjCGCAttr() const { return GC((Mask & GCAttrMask) >> GCAttrShift); } |
| 310 | void setObjCGCAttr(GC type) { |
| 311 | Mask = (Mask & ~GCAttrMask) | (type << GCAttrShift); |
| 312 | } |
| 313 | void removeObjCGCAttr() { setObjCGCAttr(GCNone); } |
| 314 | void addObjCGCAttr(GC type) { |
| 315 | assert(type); |
| 316 | setObjCGCAttr(type); |
| 317 | } |
| 318 | Qualifiers withoutObjCGCAttr() const { |
| 319 | Qualifiers qs = *this; |
| 320 | qs.removeObjCGCAttr(); |
| 321 | return qs; |
| 322 | } |
| 323 | Qualifiers withoutObjCLifetime() const { |
| 324 | Qualifiers qs = *this; |
| 325 | qs.removeObjCLifetime(); |
| 326 | return qs; |
| 327 | } |
| 328 | Qualifiers withoutAddressSpace() const { |
| 329 | Qualifiers qs = *this; |
| 330 | qs.removeAddressSpace(); |
| 331 | return qs; |
| 332 | } |
| 333 | |
| 334 | bool hasObjCLifetime() const { return Mask & LifetimeMask; } |
| 335 | ObjCLifetime getObjCLifetime() const { |
| 336 | return ObjCLifetime((Mask & LifetimeMask) >> LifetimeShift); |
| 337 | } |
| 338 | void setObjCLifetime(ObjCLifetime type) { |
| 339 | Mask = (Mask & ~LifetimeMask) | (type << LifetimeShift); |
| 340 | } |
| 341 | void removeObjCLifetime() { setObjCLifetime(OCL_None); } |
| 342 | void addObjCLifetime(ObjCLifetime type) { |
| 343 | assert(type); |
| 344 | assert(!hasObjCLifetime()); |
| 345 | Mask |= (type << LifetimeShift); |
| 346 | } |
| 347 | |
| 348 | |
| 349 | bool hasNonTrivialObjCLifetime() const { |
| 350 | ObjCLifetime lifetime = getObjCLifetime(); |
| 351 | return (lifetime > OCL_ExplicitNone); |
| 352 | } |
| 353 | |
| 354 | |
| 355 | bool hasStrongOrWeakObjCLifetime() const { |
| 356 | ObjCLifetime lifetime = getObjCLifetime(); |
| 357 | return (lifetime == OCL_Strong || lifetime == OCL_Weak); |
| 358 | } |
| 359 | |
| 360 | bool hasAddressSpace() const { return Mask & AddressSpaceMask; } |
| 361 | LangAS getAddressSpace() const { |
| 362 | return static_cast<LangAS>(Mask >> AddressSpaceShift); |
| 363 | } |
| 364 | bool hasTargetSpecificAddressSpace() const { |
| 365 | return isTargetAddressSpace(getAddressSpace()); |
| 366 | } |
| 367 | |
| 368 | unsigned getAddressSpaceAttributePrintValue() const { |
| 369 | auto Addr = getAddressSpace(); |
| 370 | |
| 371 | |
| 372 | |
| 373 | assert(Addr == LangAS::Default || hasTargetSpecificAddressSpace()); |
| 374 | if (Addr != LangAS::Default) |
| 375 | return toTargetAddressSpace(Addr); |
| 376 | |
| 377 | |
| 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | void setAddressSpace(LangAS space) { |
| 382 | assert((unsigned)space <= MaxAddressSpace); |
| 383 | Mask = (Mask & ~AddressSpaceMask) |
| 384 | | (((uint32_t) space) << AddressSpaceShift); |
| 385 | } |
| 386 | void removeAddressSpace() { setAddressSpace(LangAS::Default); } |
| 387 | void addAddressSpace(LangAS space) { |
| 388 | assert(space != LangAS::Default); |
| 389 | setAddressSpace(space); |
| 390 | } |
| 391 | |
| 392 | |
| 393 | |
| 394 | bool hasFastQualifiers() const { return getFastQualifiers(); } |
| 395 | unsigned getFastQualifiers() const { return Mask & FastMask; } |
| 396 | void setFastQualifiers(unsigned mask) { |
| 397 | assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); |
| 398 | Mask = (Mask & ~FastMask) | mask; |
| 399 | } |
| 400 | void removeFastQualifiers(unsigned mask) { |
| 401 | assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); |
| 402 | Mask &= ~mask; |
| 403 | } |
| 404 | void removeFastQualifiers() { |
| 405 | removeFastQualifiers(FastMask); |
| 406 | } |
| 407 | void addFastQualifiers(unsigned mask) { |
| 408 | assert(!(mask & ~FastMask) && "bitmask contains non-fast qualifier bits"); |
| 409 | Mask |= mask; |
| 410 | } |
| 411 | |
| 412 | |
| 413 | |
| 414 | bool hasNonFastQualifiers() const { return Mask & ~FastMask; } |
| 415 | Qualifiers getNonFastQualifiers() const { |
| 416 | Qualifiers Quals = *this; |
| 417 | Quals.setFastQualifiers(0); |
| 418 | return Quals; |
| 419 | } |
| 420 | |
| 421 | |
| 422 | bool hasQualifiers() const { return Mask; } |
| 423 | bool empty() const { return !Mask; } |
| 424 | |
| 425 | |
| 426 | void addQualifiers(Qualifiers Q) { |
| 427 | |
| 428 | |
| 429 | if (!(Q.Mask & ~CVRMask)) |
| 430 | Mask |= Q.Mask; |
| 431 | else { |
| 432 | Mask |= (Q.Mask & CVRMask); |
| 433 | if (Q.hasAddressSpace()) |
| 434 | addAddressSpace(Q.getAddressSpace()); |
| 435 | if (Q.hasObjCGCAttr()) |
| 436 | addObjCGCAttr(Q.getObjCGCAttr()); |
| 437 | if (Q.hasObjCLifetime()) |
| 438 | addObjCLifetime(Q.getObjCLifetime()); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | |
| 443 | void removeQualifiers(Qualifiers Q) { |
| 444 | |
| 445 | |
| 446 | if (!(Q.Mask & ~CVRMask)) |
| 447 | Mask &= ~Q.Mask; |
| 448 | else { |
| 449 | Mask &= ~(Q.Mask & CVRMask); |
| 450 | if (getObjCGCAttr() == Q.getObjCGCAttr()) |
| 451 | removeObjCGCAttr(); |
| 452 | if (getObjCLifetime() == Q.getObjCLifetime()) |
| 453 | removeObjCLifetime(); |
| 454 | if (getAddressSpace() == Q.getAddressSpace()) |
| 455 | removeAddressSpace(); |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | |
| 460 | |
| 461 | void addConsistentQualifiers(Qualifiers qs) { |
| 462 | assert(getAddressSpace() == qs.getAddressSpace() || |
| 463 | !hasAddressSpace() || !qs.hasAddressSpace()); |
| 464 | assert(getObjCGCAttr() == qs.getObjCGCAttr() || |
| 465 | !hasObjCGCAttr() || !qs.hasObjCGCAttr()); |
| 466 | assert(getObjCLifetime() == qs.getObjCLifetime() || |
| 467 | !hasObjCLifetime() || !qs.hasObjCLifetime()); |
| 468 | Mask |= qs.Mask; |
| 469 | } |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | static bool isAddressSpaceSupersetOf(LangAS A, LangAS B) { |
| 479 | |
| 480 | return A == B || |
| 481 | |
| 482 | |
| 483 | (A == LangAS::opencl_generic && B != LangAS::opencl_constant) || |
| 484 | |
| 485 | |
| 486 | |
| 487 | (A == LangAS::opencl_global && (B == LangAS::opencl_global_device || |
| 488 | B == LangAS::opencl_global_host)) || |
| 489 | (A == LangAS::sycl_global && (B == LangAS::sycl_global_device || |
| 490 | B == LangAS::sycl_global_host)) || |
| 491 | |
| 492 | ((isPtrSizeAddressSpace(A) || A == LangAS::Default) && |
| 493 | (isPtrSizeAddressSpace(B) || B == LangAS::Default)) || |
| 494 | |
| 495 | (A == LangAS::Default && |
| 496 | (B == LangAS::sycl_private || B == LangAS::sycl_local || |
| 497 | B == LangAS::sycl_global || B == LangAS::sycl_global_device || |
| 498 | B == LangAS::sycl_global_host)); |
| 499 | } |
| 500 | |
| 501 | |
| 502 | |
| 503 | bool isAddressSpaceSupersetOf(Qualifiers other) const { |
| 504 | return isAddressSpaceSupersetOf(getAddressSpace(), other.getAddressSpace()); |
| 505 | } |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | bool compatiblyIncludes(Qualifiers other) const { |
| 511 | return isAddressSpaceSupersetOf(other) && |
| 512 | |
| 513 | |
| 514 | (getObjCGCAttr() == other.getObjCGCAttr() || !hasObjCGCAttr() || |
| 515 | !other.hasObjCGCAttr()) && |
| 516 | |
| 517 | getObjCLifetime() == other.getObjCLifetime() && |
| 518 | |
| 519 | (((Mask & CVRMask) | (other.Mask & CVRMask)) == (Mask & CVRMask)) && |
| 520 | |
| 521 | (!other.hasUnaligned() || hasUnaligned()); |
| 522 | } |
| 523 | |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | bool compatiblyIncludesObjCLifetime(Qualifiers other) const { |
| 532 | if (getObjCLifetime() == other.getObjCLifetime()) |
| 533 | return true; |
| 534 | |
| 535 | if (getObjCLifetime() == OCL_Weak || other.getObjCLifetime() == OCL_Weak) |
| 536 | return false; |
| 537 | |
| 538 | if (getObjCLifetime() == OCL_None || other.getObjCLifetime() == OCL_None) |
| 539 | return true; |
| 540 | |
| 541 | return hasConst(); |
| 542 | } |
| 543 | |
| 544 | |
| 545 | |
| 546 | bool isStrictSupersetOf(Qualifiers Other) const; |
| 547 | |
| 548 | bool operator==(Qualifiers Other) const { return Mask == Other.Mask; } |
| 549 | bool operator!=(Qualifiers Other) const { return Mask != Other.Mask; } |
| 550 | |
| 551 | explicit operator bool() const { return hasQualifiers(); } |
| 552 | |
| 553 | Qualifiers &operator+=(Qualifiers R) { |
| 554 | addQualifiers(R); |
| 555 | return *this; |
| 556 | } |
| 557 | |
| 558 | |
| 559 | |
| 560 | friend Qualifiers operator+(Qualifiers L, Qualifiers R) { |
| 561 | L += R; |
| 562 | return L; |
| 563 | } |
| 564 | |
| 565 | Qualifiers &operator-=(Qualifiers R) { |
| 566 | removeQualifiers(R); |
| 567 | return *this; |
| 568 | } |
| 569 | |
| 570 | |
| 571 | friend Qualifiers operator-(Qualifiers L, Qualifiers R) { |
| 572 | L -= R; |
| 573 | return L; |
| 574 | } |
| 575 | |
| 576 | std::string getAsString() const; |
| 577 | std::string getAsString(const PrintingPolicy &Policy) const; |
| 578 | |
| 579 | static std::string getAddrSpaceAsString(LangAS AS); |
| 580 | |
| 581 | bool isEmptyWhenPrinted(const PrintingPolicy &Policy) const; |
| 582 | void print(raw_ostream &OS, const PrintingPolicy &Policy, |
| 583 | bool appendSpaceIfNonEmpty = false) const; |
| 584 | |
| 585 | void Profile(llvm::FoldingSetNodeID &ID) const { |
| 586 | ID.AddInteger(Mask); |
| 587 | } |
| 588 | |
| 589 | private: |
| 590 | |
| 591 | |
| 592 | uint32_t Mask = 0; |
| 593 | |
| 594 | static const uint32_t UMask = 0x8; |
| 595 | static const uint32_t UShift = 3; |
| 596 | static const uint32_t GCAttrMask = 0x30; |
| 597 | static const uint32_t GCAttrShift = 4; |
| 598 | static const uint32_t LifetimeMask = 0x1C0; |
| 599 | static const uint32_t LifetimeShift = 6; |
| 600 | static const uint32_t AddressSpaceMask = |
| 601 | ~(CVRMask | UMask | GCAttrMask | LifetimeMask); |
| 602 | static const uint32_t AddressSpaceShift = 9; |
| 603 | }; |
| 604 | |
| 605 | |
| 606 | |
| 607 | struct SplitQualType { |
| 608 | |
| 609 | const Type *Ty = nullptr; |
| 610 | |
| 611 | |
| 612 | Qualifiers Quals; |
| 613 | |
| 614 | SplitQualType() = default; |
| 615 | SplitQualType(const Type *ty, Qualifiers qs) : Ty(ty), Quals(qs) {} |
| 616 | |
| 617 | SplitQualType getSingleStepDesugaredType() const; |
| 618 | |
| 619 | |
| 620 | std::pair<const Type *,Qualifiers> asPair() const { |
| 621 | return std::pair<const Type *, Qualifiers>(Ty, Quals); |
| 622 | } |
| 623 | |
| 624 | friend bool operator==(SplitQualType a, SplitQualType b) { |
| 625 | return a.Ty == b.Ty && a.Quals == b.Quals; |
| 626 | } |
| 627 | friend bool operator!=(SplitQualType a, SplitQualType b) { |
| 628 | return a.Ty != b.Ty || a.Quals != b.Quals; |
| 629 | } |
| 630 | }; |
| 631 | |
| 632 | |
| 633 | |
| 634 | |
| 635 | |
| 636 | |
| 637 | enum class ObjCSubstitutionContext { |
| 638 | |
| 639 | Ordinary, |
| 640 | |
| 641 | |
| 642 | Result, |
| 643 | |
| 644 | |
| 645 | Parameter, |
| 646 | |
| 647 | |
| 648 | Property, |
| 649 | |
| 650 | |
| 651 | Superclass, |
| 652 | }; |
| 653 | |
| 654 | |
| 655 | |
| 656 | |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
| 667 | |
| 668 | class QualType { |
| 669 | friend class QualifierCollector; |
| 670 | |
| 671 | |
| 672 | llvm::PointerIntPair<llvm::PointerUnion<const Type *, const ExtQuals *>, |
| 673 | Qualifiers::FastWidth> Value; |
| 674 | |
| 675 | const ExtQuals *getExtQualsUnsafe() const { |
| 676 | return Value.getPointer().get<const ExtQuals*>(); |
| 677 | } |
| 678 | |
| 679 | const Type *getTypePtrUnsafe() const { |
| 680 | return Value.getPointer().get<const Type*>(); |
| 681 | } |
| 682 | |
| 683 | const ExtQualsTypeCommonBase *getCommonPtr() const { |
| 684 | assert(!isNull() && "Cannot retrieve a NULL type pointer"); |
| 685 | auto CommonPtrVal = reinterpret_cast<uintptr_t>(Value.getOpaqueValue()); |
| 686 | CommonPtrVal &= ~(uintptr_t)((1 << TypeAlignmentInBits) - 1); |
| 687 | return reinterpret_cast<ExtQualsTypeCommonBase*>(CommonPtrVal); |
| 688 | } |
| 689 | |
| 690 | public: |
| 691 | QualType() = default; |
| 692 | QualType(const Type *Ptr, unsigned Quals) : Value(Ptr, Quals) {} |
| 693 | QualType(const ExtQuals *Ptr, unsigned Quals) : Value(Ptr, Quals) {} |
| 694 | |
| 695 | unsigned getLocalFastQualifiers() const { return Value.getInt(); } |
| 696 | void setLocalFastQualifiers(unsigned Quals) { Value.setInt(Quals); } |
| 697 | |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | const Type *getTypePtr() const; |
| 703 | |
| 704 | const Type *getTypePtrOrNull() const; |
| 705 | |
| 706 | |
| 707 | const IdentifierInfo *getBaseTypeIdentifier() const; |
| 708 | |
| 709 | |
| 710 | |
| 711 | SplitQualType split() const; |
| 712 | |
| 713 | void *getAsOpaquePtr() const { return Value.getOpaqueValue(); } |
| 714 | |
| 715 | static QualType getFromOpaquePtr(const void *Ptr) { |
| 716 | QualType T; |
| 717 | T.Value.setFromOpaqueValue(const_cast<void*>(Ptr)); |
| 718 | return T; |
| 719 | } |
| 720 | |
| 721 | const Type &operator*() const { |
| 722 | return *getTypePtr(); |
| 723 | } |
| 724 | |
| 725 | const Type *operator->() const { |
| 726 | return getTypePtr(); |
| 727 | } |
| 728 | |
| 729 | bool isCanonical() const; |
| 730 | bool isCanonicalAsParam() const; |
| 731 | |
| 732 | |
| 733 | bool isNull() const { |
| 734 | return Value.getPointer().isNull(); |
| 30 | | Calling 'PointerUnion::isNull' | |
|
| 33 | | Returning from 'PointerUnion::isNull' | |
|
| 34 | | Returning zero, which participates in a condition later | |
|
| 735 | } |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | bool isLocalConstQualified() const { |
| 741 | return (getLocalFastQualifiers() & Qualifiers::Const); |
| 742 | } |
| 743 | |
| 744 | |
| 745 | bool isConstQualified() const; |
| 746 | |
| 747 | |
| 748 | |
| 749 | |
| 750 | bool isLocalRestrictQualified() const { |
| 751 | return (getLocalFastQualifiers() & Qualifiers::Restrict); |
| 752 | } |
| 753 | |
| 754 | |
| 755 | bool isRestrictQualified() const; |
| 756 | |
| 757 | |
| 758 | |
| 759 | |
| 760 | bool isLocalVolatileQualified() const { |
| 761 | return (getLocalFastQualifiers() & Qualifiers::Volatile); |
| 762 | } |
| 763 | |
| 764 | |
| 765 | bool isVolatileQualified() const; |
| 766 | |
| 767 | |
| 768 | |
| 769 | |
| 770 | bool hasLocalQualifiers() const { |
| 771 | return getLocalFastQualifiers() || hasLocalNonFastQualifiers(); |
| 772 | } |
| 773 | |
| 774 | |
| 775 | bool hasQualifiers() const; |
| 776 | |
| 777 | |
| 778 | |
| 779 | |
| 780 | bool hasLocalNonFastQualifiers() const { |
| 781 | return Value.getPointer().is<const ExtQuals*>(); |
| 782 | } |
| 783 | |
| 784 | |
| 785 | |
| 786 | |
| 787 | Qualifiers getLocalQualifiers() const; |
| 788 | |
| 789 | |
| 790 | Qualifiers getQualifiers() const; |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | unsigned getLocalCVRQualifiers() const { |
| 796 | return getLocalFastQualifiers(); |
| 797 | } |
| 798 | |
| 799 | |
| 800 | |
| 801 | unsigned getCVRQualifiers() const; |
| 802 | |
| 803 | bool isConstant(const ASTContext& Ctx) const { |
| 804 | return QualType::isConstant(*this, Ctx); |
| 805 | } |
| 806 | |
| 807 | |
| 808 | bool isPODType(const ASTContext &Context) const; |
| 809 | |
| 810 | |
| 811 | |
| 812 | bool isCXX98PODType(const ASTContext &Context) const; |
| 813 | |
| 814 | |
| 815 | |
| 816 | |
| 817 | |
| 818 | bool isCXX11PODType(const ASTContext &Context) const; |
| 819 | |
| 820 | |
| 821 | bool isTrivialType(const ASTContext &Context) const; |
| 822 | |
| 823 | |
| 824 | bool isTriviallyCopyableType(const ASTContext &Context) const; |
| 825 | |
| 826 | |
| 827 | |
| 828 | bool mayBeDynamicClass() const; |
| 829 | |
| 830 | |
| 831 | bool mayBeNotDynamicClass() const; |
| 832 | |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | void addConst() { |
| 838 | addFastQualifiers(Qualifiers::Const); |
| 839 | } |
| 840 | QualType withConst() const { |
| 841 | return withFastQualifiers(Qualifiers::Const); |
| 842 | } |
| 843 | |
| 844 | |
| 845 | void addVolatile() { |
| 846 | addFastQualifiers(Qualifiers::Volatile); |
| 847 | } |
| 848 | QualType withVolatile() const { |
| 849 | return withFastQualifiers(Qualifiers::Volatile); |
| 850 | } |
| 851 | |
| 852 | |
| 853 | void addRestrict() { |
| 854 | addFastQualifiers(Qualifiers::Restrict); |
| 855 | } |
| 856 | QualType withRestrict() const { |
| 857 | return withFastQualifiers(Qualifiers::Restrict); |
| 858 | } |
| 859 | |
| 860 | QualType withCVRQualifiers(unsigned CVR) const { |
| 861 | return withFastQualifiers(CVR); |
| 862 | } |
| 863 | |
| 864 | void addFastQualifiers(unsigned TQs) { |
| 865 | assert(!(TQs & ~Qualifiers::FastMask) |
| 866 | && "non-fast qualifier bits set in mask!"); |
| 867 | Value.setInt(Value.getInt() | TQs); |
| 868 | } |
| 869 | |
| 870 | void removeLocalConst(); |
| 871 | void removeLocalVolatile(); |
| 872 | void removeLocalRestrict(); |
| 873 | void removeLocalCVRQualifiers(unsigned Mask); |
| 874 | |
| 875 | void removeLocalFastQualifiers() { Value.setInt(0); } |
| 876 | void removeLocalFastQualifiers(unsigned Mask) { |
| 877 | assert(!(Mask & ~Qualifiers::FastMask) && "mask has non-fast qualifiers"); |
| 878 | Value.setInt(Value.getInt() & ~Mask); |
| 879 | } |
| 880 | |
| 881 | |
| 882 | |
| 883 | QualType withFastQualifiers(unsigned TQs) const { |
| 884 | QualType T = *this; |
| 885 | T.addFastQualifiers(TQs); |
| 886 | return T; |
| 887 | } |
| 888 | |
| 889 | |
| 890 | |
| 891 | QualType withExactLocalFastQualifiers(unsigned TQs) const { |
| 892 | return withoutLocalFastQualifiers().withFastQualifiers(TQs); |
| 893 | } |
| 894 | |
| 895 | |
| 896 | QualType withoutLocalFastQualifiers() const { |
| 897 | QualType T = *this; |
| 898 | T.removeLocalFastQualifiers(); |
| 899 | return T; |
| 900 | } |
| 901 | |
| 902 | QualType getCanonicalType() const; |
| 903 | |
| 904 | |
| 905 | |
| 906 | |
| 907 | QualType getLocalUnqualifiedType() const { return QualType(getTypePtr(), 0); } |
| 908 | |
| 909 | |
| 910 | |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | |
| 916 | |
| 917 | |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | |
| 923 | |
| 924 | |
| 925 | |
| 926 | |
| 927 | inline QualType getUnqualifiedType() const; |
| 928 | |
| 929 | |
| 930 | |
| 931 | |
| 932 | |
| 933 | |
| 934 | |
| 935 | |
| 936 | |
| 937 | |
| 938 | inline SplitQualType getSplitUnqualifiedType() const; |
| 939 | |
| 940 | |
| 941 | |
| 942 | bool isMoreQualifiedThan(QualType Other) const; |
| 943 | |
| 944 | |
| 945 | |
| 946 | bool isAtLeastAsQualifiedAs(QualType Other) const; |
| 947 | |
| 948 | QualType getNonReferenceType() const; |
| 949 | |
| 950 | |
| 951 | |
| 952 | |
| 953 | |
| 954 | |
| 955 | |
| 956 | |
| 957 | |
| 958 | QualType getNonLValueExprType(const ASTContext &Context) const; |
| 959 | |
| 960 | |
| 961 | |
| 962 | |
| 963 | |
| 964 | QualType getNonPackExpansionType() const; |
| 965 | |
| 966 | |
| 967 | |
| 968 | |
| 969 | |
| 970 | |
| 971 | |
| 972 | |
| 973 | |
| 974 | QualType getDesugaredType(const ASTContext &Context) const { |
| 975 | return getDesugaredType(*this, Context); |
| 976 | } |
| 977 | |
| 978 | SplitQualType getSplitDesugaredType() const { |
| 979 | return getSplitDesugaredType(*this); |
| 980 | } |
| 981 | |
| 982 | |
| 983 | |
| 984 | |
| 985 | |
| 986 | |
| 987 | QualType getSingleStepDesugaredType(const ASTContext &Context) const { |
| 988 | return getSingleStepDesugaredTypeImpl(*this, Context); |
| 989 | } |
| 990 | |
| 991 | |
| 992 | |
| 993 | QualType IgnoreParens() const { |
| 994 | if (isa<ParenType>(*this)) |
| 995 | return QualType::IgnoreParens(*this); |
| 996 | return *this; |
| 997 | } |
| 998 | |
| 999 | |
| 1000 | friend bool operator==(const QualType &LHS, const QualType &RHS) { |
| 1001 | return LHS.Value == RHS.Value; |
| 1002 | } |
| 1003 | friend bool operator!=(const QualType &LHS, const QualType &RHS) { |
| 1004 | return LHS.Value != RHS.Value; |
| 1005 | } |
| 1006 | friend bool operator<(const QualType &LHS, const QualType &RHS) { |
| 1007 | return LHS.Value < RHS.Value; |
| 1008 | } |
| 1009 | |
| 1010 | static std::string getAsString(SplitQualType split, |
| 1011 | const PrintingPolicy &Policy) { |
| 1012 | return getAsString(split.Ty, split.Quals, Policy); |
| 1013 | } |
| 1014 | static std::string getAsString(const Type *ty, Qualifiers qs, |
| 1015 | const PrintingPolicy &Policy); |
| 1016 | |
| 1017 | std::string getAsString() const; |
| 1018 | std::string getAsString(const PrintingPolicy &Policy) const; |
| 1019 | |
| 1020 | void print(raw_ostream &OS, const PrintingPolicy &Policy, |
| 1021 | const Twine &PlaceHolder = Twine(), |
| 1022 | unsigned Indentation = 0) const; |
| 1023 | |
| 1024 | static void print(SplitQualType split, raw_ostream &OS, |
| 1025 | const PrintingPolicy &policy, const Twine &PlaceHolder, |
| 1026 | unsigned Indentation = 0) { |
| 1027 | return print(split.Ty, split.Quals, OS, policy, PlaceHolder, Indentation); |
| 1028 | } |
| 1029 | |
| 1030 | static void print(const Type *ty, Qualifiers qs, |
| 1031 | raw_ostream &OS, const PrintingPolicy &policy, |
| 1032 | const Twine &PlaceHolder, |
| 1033 | unsigned Indentation = 0); |
| 1034 | |
| 1035 | void getAsStringInternal(std::string &Str, |
| 1036 | const PrintingPolicy &Policy) const; |
| 1037 | |
| 1038 | static void getAsStringInternal(SplitQualType split, std::string &out, |
| 1039 | const PrintingPolicy &policy) { |
| 1040 | return getAsStringInternal(split.Ty, split.Quals, out, policy); |
| 1041 | } |
| 1042 | |
| 1043 | static void getAsStringInternal(const Type *ty, Qualifiers qs, |
| 1044 | std::string &out, |
| 1045 | const PrintingPolicy &policy); |
| 1046 | |
| 1047 | class StreamedQualTypeHelper { |
| 1048 | const QualType &T; |
| 1049 | const PrintingPolicy &Policy; |
| 1050 | const Twine &PlaceHolder; |
| 1051 | unsigned Indentation; |
| 1052 | |
| 1053 | public: |
| 1054 | StreamedQualTypeHelper(const QualType &T, const PrintingPolicy &Policy, |
| 1055 | const Twine &PlaceHolder, unsigned Indentation) |
| 1056 | : T(T), Policy(Policy), PlaceHolder(PlaceHolder), |
| 1057 | Indentation(Indentation) {} |
| 1058 | |
| 1059 | friend raw_ostream &operator<<(raw_ostream &OS, |
| 1060 | const StreamedQualTypeHelper &SQT) { |
| 1061 | SQT.T.print(OS, SQT.Policy, SQT.PlaceHolder, SQT.Indentation); |
| 1062 | return OS; |
| 1063 | } |
| 1064 | }; |
| 1065 | |
| 1066 | StreamedQualTypeHelper stream(const PrintingPolicy &Policy, |
| 1067 | const Twine &PlaceHolder = Twine(), |
| 1068 | unsigned Indentation = 0) const { |
| 1069 | return StreamedQualTypeHelper(*this, Policy, PlaceHolder, Indentation); |
| 1070 | } |
| 1071 | |
| 1072 | void dump(const char *s) const; |
| 1073 | void dump() const; |
| 1074 | void dump(llvm::raw_ostream &OS, const ASTContext &Context) const; |
| 1075 | |
| 1076 | void Profile(llvm::FoldingSetNodeID &ID) const { |
| 1077 | ID.AddPointer(getAsOpaquePtr()); |
| 1078 | } |
| 1079 | |
| 1080 | |
| 1081 | inline bool hasAddressSpace() const; |
| 1082 | |
| 1083 | |
| 1084 | inline LangAS getAddressSpace() const; |
| 1085 | |
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | |
| 1090 | |
| 1091 | |
| 1092 | |
| 1093 | |
| 1094 | bool isAddressSpaceOverlapping(QualType T) const { |
| 1095 | Qualifiers Q = getQualifiers(); |
| 1096 | Qualifiers TQ = T.getQualifiers(); |
| 1097 | |
| 1098 | return Q.isAddressSpaceSupersetOf(TQ) || TQ.isAddressSpaceSupersetOf(Q); |
| 1099 | } |
| 1100 | |
| 1101 | |
| 1102 | inline Qualifiers::GC getObjCGCAttr() const; |
| 1103 | |
| 1104 | |
| 1105 | bool isObjCGCWeak() const { |
| 1106 | return getObjCGCAttr() == Qualifiers::Weak; |
| 1107 | } |
| 1108 | |
| 1109 | |
| 1110 | bool isObjCGCStrong() const { |
| 1111 | return getObjCGCAttr() == Qualifiers::Strong; |
| 1112 | } |
| 1113 | |
| 1114 | |
| 1115 | Qualifiers::ObjCLifetime getObjCLifetime() const { |
| 1116 | return getQualifiers().getObjCLifetime(); |
| 1117 | } |
| 1118 | |
| 1119 | bool hasNonTrivialObjCLifetime() const { |
| 1120 | return getQualifiers().hasNonTrivialObjCLifetime(); |
| 1121 | } |
| 1122 | |
| 1123 | bool hasStrongOrWeakObjCLifetime() const { |
| 1124 | return getQualifiers().hasStrongOrWeakObjCLifetime(); |
| 1125 | } |
| 1126 | |
| 1127 | |
| 1128 | bool isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const; |
| 1129 | |
| 1130 | enum PrimitiveDefaultInitializeKind { |
| 1131 | |
| 1132 | |
| 1133 | |
| 1134 | PDIK_Trivial, |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | PDIK_ARCStrong, |
| 1139 | |
| 1140 | |
| 1141 | |
| 1142 | PDIK_ARCWeak, |
| 1143 | |
| 1144 | |
| 1145 | PDIK_Struct |
| 1146 | }; |
| 1147 | |
| 1148 | |
| 1149 | |
| 1150 | |
| 1151 | |
| 1152 | |
| 1153 | PrimitiveDefaultInitializeKind |
| 1154 | isNonTrivialToPrimitiveDefaultInitialize() const; |
| 1155 | |
| 1156 | enum PrimitiveCopyKind { |
| 1157 | |
| 1158 | |
| 1159 | |
| 1160 | PCK_Trivial, |
| 1161 | |
| 1162 | |
| 1163 | |
| 1164 | |
| 1165 | PCK_VolatileTrivial, |
| 1166 | |
| 1167 | |
| 1168 | |
| 1169 | PCK_ARCStrong, |
| 1170 | |
| 1171 | |
| 1172 | |
| 1173 | PCK_ARCWeak, |
| 1174 | |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | |
| 1180 | |
| 1181 | PCK_Struct |
| 1182 | }; |
| 1183 | |
| 1184 | |
| 1185 | |
| 1186 | |
| 1187 | PrimitiveCopyKind isNonTrivialToPrimitiveCopy() const; |
| 1188 | |
| 1189 | |
| 1190 | |
| 1191 | |
| 1192 | |
| 1193 | |
| 1194 | |
| 1195 | PrimitiveCopyKind isNonTrivialToPrimitiveDestructiveMove() const; |
| 1196 | |
| 1197 | enum DestructionKind { |
| 1198 | DK_none, |
| 1199 | DK_cxx_destructor, |
| 1200 | DK_objc_strong_lifetime, |
| 1201 | DK_objc_weak_lifetime, |
| 1202 | DK_nontrivial_c_struct |
| 1203 | }; |
| 1204 | |
| 1205 | |
| 1206 | |
| 1207 | |
| 1208 | |
| 1209 | DestructionKind isDestructedType() const { |
| 1210 | return isDestructedTypeImpl(*this); |
| 1211 | } |
| 1212 | |
| 1213 | |
| 1214 | |
| 1215 | |
| 1216 | |
| 1217 | bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const; |
| 1218 | |
| 1219 | |
| 1220 | |
| 1221 | |
| 1222 | bool hasNonTrivialToPrimitiveDestructCUnion() const; |
| 1223 | |
| 1224 | |
| 1225 | |
| 1226 | |
| 1227 | bool hasNonTrivialToPrimitiveCopyCUnion() const; |
| 1228 | |
| 1229 | |
| 1230 | |
| 1231 | |
| 1232 | |
| 1233 | |
| 1234 | |
| 1235 | |
| 1236 | |
| 1237 | |
| 1238 | |
| 1239 | bool isCForbiddenLValueType() const; |
| 1240 | |
| 1241 | |
| 1242 | |
| 1243 | |
| 1244 | |
| 1245 | |
| 1246 | |
| 1247 | |
| 1248 | |
| 1249 | |
| 1250 | |
| 1251 | |
| 1252 | |
| 1253 | |
| 1254 | |
| 1255 | QualType substObjCTypeArgs(ASTContext &ctx, |
| 1256 | ArrayRef<QualType> typeArgs, |
| 1257 | ObjCSubstitutionContext context) const; |
| 1258 | |
| 1259 | |
| 1260 | |
| 1261 | |
| 1262 | |
| 1263 | |
| 1264 | |
| 1265 | |
| 1266 | |
| 1267 | |
| 1268 | |
| 1269 | |
| 1270 | |
| 1271 | |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | |
| 1276 | |
| 1277 | |
| 1278 | |
| 1279 | QualType substObjCMemberType(QualType objectType, |
| 1280 | const DeclContext *dc, |
| 1281 | ObjCSubstitutionContext context) const; |
| 1282 | |
| 1283 | |
| 1284 | QualType stripObjCKindOfType(const ASTContext &ctx) const; |
| 1285 | |
| 1286 | |
| 1287 | QualType getAtomicUnqualifiedType() const; |
| 1288 | |
| 1289 | private: |
| 1290 | |
| 1291 | |
| 1292 | |
| 1293 | static bool isConstant(QualType T, const ASTContext& Ctx); |
| 1294 | static QualType getDesugaredType(QualType T, const ASTContext &Context); |
| 1295 | static SplitQualType getSplitDesugaredType(QualType T); |
| 1296 | static SplitQualType getSplitUnqualifiedTypeImpl(QualType type); |
| 1297 | static QualType getSingleStepDesugaredTypeImpl(QualType type, |
| 1298 | const ASTContext &C); |
| 1299 | static QualType IgnoreParens(QualType T); |
| 1300 | static DestructionKind isDestructedTypeImpl(QualType type); |
| 1301 | |
| 1302 | |
| 1303 | static bool hasNonTrivialToPrimitiveDefaultInitializeCUnion(const RecordDecl *RD); |
| 1304 | static bool hasNonTrivialToPrimitiveDestructCUnion(const RecordDecl *RD); |
| 1305 | static bool hasNonTrivialToPrimitiveCopyCUnion(const RecordDecl *RD); |
| 1306 | }; |
| 1307 | |
| 1308 | } |
| 1309 | |
| 1310 | namespace llvm { |
| 1311 | |
| 1312 | |
| 1313 | |
| 1314 | template<> struct simplify_type< ::clang::QualType> { |
| 1315 | using SimpleType = const ::clang::Type *; |
| 1316 | |
| 1317 | static SimpleType getSimplifiedValue(::clang::QualType Val) { |
| 1318 | return Val.getTypePtr(); |
| 1319 | } |
| 1320 | }; |
| 1321 | |
| 1322 | |
| 1323 | template<> |
| 1324 | struct PointerLikeTypeTraits<clang::QualType> { |
| 1325 | static inline void *getAsVoidPointer(clang::QualType P) { |
| 1326 | return P.getAsOpaquePtr(); |
| 1327 | } |
| 1328 | |
| 1329 | static inline clang::QualType getFromVoidPointer(void *P) { |
| 1330 | return clang::QualType::getFromOpaquePtr(P); |
| 1331 | } |
| 1332 | |
| 1333 | |
| 1334 | static constexpr int NumLowBitsAvailable = 0; |
| 1335 | }; |
| 1336 | |
| 1337 | } |
| 1338 | |
| 1339 | namespace clang { |
| 1340 | |
| 1341 | |
| 1342 | |
| 1343 | |
| 1344 | class ExtQualsTypeCommonBase { |
| 1345 | friend class ExtQuals; |
| 1346 | friend class QualType; |
| 1347 | friend class Type; |
| 1348 | |
| 1349 | |
| 1350 | |
| 1351 | |
| 1352 | |
| 1353 | |
| 1354 | const Type *const BaseType; |
| 1355 | |
| 1356 | |
| 1357 | QualType CanonicalType; |
| 1358 | |
| 1359 | ExtQualsTypeCommonBase(const Type *baseType, QualType canon) |
| 1360 | : BaseType(baseType), CanonicalType(canon) {} |
| 1361 | }; |
| 1362 | |
| 1363 | |
| 1364 | |
| 1365 | |
| 1366 | |
| 1367 | |
| 1368 | |
| 1369 | |
| 1370 | |
| 1371 | |
| 1372 | |
| 1373 | class ExtQuals : public ExtQualsTypeCommonBase, public llvm::FoldingSetNode { |
| 1374 | |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | |
| 1379 | |
| 1380 | |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | |
| 1385 | |
| 1386 | |
| 1387 | |
| 1388 | |
| 1389 | Qualifiers Quals; |
| 1390 | |
| 1391 | ExtQuals *this_() { return this; } |
| 1392 | |
| 1393 | public: |
| 1394 | ExtQuals(const Type *baseType, QualType canon, Qualifiers quals) |
| 1395 | : ExtQualsTypeCommonBase(baseType, |
| 1396 | canon.isNull() ? QualType(this_(), 0) : canon), |
| 1397 | Quals(quals) { |
| 1398 | assert(Quals.hasNonFastQualifiers() |
| 1399 | && "ExtQuals created with no fast qualifiers"); |
| 1400 | assert(!Quals.hasFastQualifiers() |
| 1401 | && "ExtQuals created with fast qualifiers"); |
| 1402 | } |
| 1403 | |
| 1404 | Qualifiers getQualifiers() const { return Quals; } |
| 1405 | |
| 1406 | bool hasObjCGCAttr() const { return Quals.hasObjCGCAttr(); } |
| 1407 | Qualifiers::GC getObjCGCAttr() const { return Quals.getObjCGCAttr(); } |
| 1408 | |
| 1409 | bool hasObjCLifetime() const { return Quals.hasObjCLifetime(); } |
| 1410 | Qualifiers::ObjCLifetime getObjCLifetime() const { |
| 1411 | return Quals.getObjCLifetime(); |
| 1412 | } |
| 1413 | |
| 1414 | bool hasAddressSpace() const { return Quals.hasAddressSpace(); } |
| 1415 | LangAS getAddressSpace() const { return Quals.getAddressSpace(); } |
| 1416 | |
| 1417 | const Type *getBaseType() const { return BaseType; } |
| 1418 | |
| 1419 | public: |
| 1420 | void Profile(llvm::FoldingSetNodeID &ID) const { |
| 1421 | Profile(ID, getBaseType(), Quals); |
| 1422 | } |
| 1423 | |
| 1424 | static void Profile(llvm::FoldingSetNodeID &ID, |
| 1425 | const Type *BaseType, |
| 1426 | Qualifiers Quals) { |
| 1427 | assert(!Quals.hasFastQualifiers() && "fast qualifiers in ExtQuals hash!"); |
| 1428 | ID.AddPointer(BaseType); |
| 1429 | Quals.Profile(ID); |
| 1430 | } |
| 1431 | }; |
| 1432 | |
| 1433 | |
| 1434 | |
| 1435 | |
| 1436 | enum RefQualifierKind { |
| 1437 | |
| 1438 | RQ_None = 0, |
| 1439 | |
| 1440 | |
| 1441 | RQ_LValue, |
| 1442 | |
| 1443 | |
| 1444 | RQ_RValue |
| 1445 | }; |
| 1446 | |
| 1447 | |
| 1448 | enum class AutoTypeKeyword { |
| 1449 | |
| 1450 | Auto, |
| 1451 | |
| 1452 | |
| 1453 | DecltypeAuto, |
| 1454 | |
| 1455 | |
| 1456 | GNUAutoType |
| 1457 | }; |
| 1458 | |
| 1459 | |
| 1460 | |
| 1461 | |
| 1462 | |
| 1463 | |
| 1464 | |
| 1465 | |
| 1466 | |
| 1467 | |
| 1468 | |
| 1469 | |
| 1470 | |
| 1471 | |
| 1472 | |
| 1473 | |
| 1474 | |
| 1475 | |
| 1476 | |
| 1477 | |
| 1478 | |
| 1479 | |
| 1480 | |
| 1481 | |
| 1482 | |
| 1483 | |
| 1484 | |
| 1485 | class alignas(8) Type : public ExtQualsTypeCommonBase { |
| 1486 | public: |
| 1487 | enum TypeClass { |
| 1488 | #define TYPE(Class, Base) Class, |
| 1489 | #define LAST_TYPE(Class) TypeLast = Class |
| 1490 | #define ABSTRACT_TYPE(Class, Base) |
| 1491 | #include "clang/AST/TypeNodes.inc" |
| 1492 | }; |
| 1493 | |
| 1494 | private: |
| 1495 | |
| 1496 | class TypeBitfields { |
| 1497 | friend class Type; |
| 1498 | template <class T> friend class TypePropertyCache; |
| 1499 | |
| 1500 | |
| 1501 | unsigned TC : 8; |
| 1502 | |
| 1503 | |
| 1504 | unsigned Dependence : llvm::BitWidth<TypeDependence>; |
| 1505 | |
| 1506 | |
| 1507 | |
| 1508 | mutable unsigned CacheValid : 1; |
| 1509 | |
| 1510 | |
| 1511 | mutable unsigned CachedLinkage : 3; |
| 1512 | |
| 1513 | |
| 1514 | mutable unsigned CachedLocalOrUnnamed : 1; |
| 1515 | |
| 1516 | |
| 1517 | mutable unsigned FromAST : 1; |
| 1518 | |
| 1519 | bool isCacheValid() const { |
| 1520 | return CacheValid; |
| 1521 | } |
| 1522 | |
| 1523 | Linkage getLinkage() const { |
| 1524 | assert(isCacheValid() && "getting linkage from invalid cache"); |
| 1525 | return static_cast<Linkage>(CachedLinkage); |
| 1526 | } |
| 1527 | |
| 1528 | bool hasLocalOrUnnamedType() const { |
| 1529 | assert(isCacheValid() && "getting linkage from invalid cache"); |
| 1530 | return CachedLocalOrUnnamed; |
| 1531 | } |
| 1532 | }; |
| 1533 | enum { NumTypeBits = 8 + llvm::BitWidth<TypeDependence> + 6 }; |
| 1534 | |
| 1535 | protected: |
| 1536 | |
| 1537 | |
| 1538 | |
| 1539 | class ArrayTypeBitfields { |
| 1540 | friend class ArrayType; |
| 1541 | |
| 1542 | unsigned : NumTypeBits; |
| 1543 | |
| 1544 | |
| 1545 | |
| 1546 | unsigned IndexTypeQuals : 3; |
| 1547 | |
| 1548 | |
| 1549 | |
| 1550 | |
| 1551 | unsigned SizeModifier : 3; |
| 1552 | }; |
| 1553 | |
| 1554 | class ConstantArrayTypeBitfields { |
| 1555 | friend class ConstantArrayType; |
| 1556 | |
| 1557 | unsigned : NumTypeBits + 3 + 3; |
| 1558 | |
| 1559 | |
| 1560 | unsigned HasStoredSizeExpr : 1; |
| 1561 | }; |
| 1562 | |
| 1563 | class BuiltinTypeBitfields { |
| 1564 | friend class BuiltinType; |
| 1565 | |
| 1566 | unsigned : NumTypeBits; |
| 1567 | |
| 1568 | |
| 1569 | unsigned Kind : 8; |
| 1570 | }; |
| 1571 | |
| 1572 | |
| 1573 | |
| 1574 | |
| 1575 | class FunctionTypeBitfields { |
| 1576 | friend class FunctionProtoType; |
| 1577 | friend class FunctionType; |
| 1578 | |
| 1579 | unsigned : NumTypeBits; |
| 1580 | |
| 1581 | |
| 1582 | |
| 1583 | unsigned ExtInfo : 13; |
| 1584 | |
| 1585 | |
| 1586 | |
| 1587 | |
| 1588 | unsigned RefQualifier : 2; |
| 1589 | |
| 1590 | |
| 1591 | |
| 1592 | |
| 1593 | |
| 1594 | |
| 1595 | |
| 1596 | unsigned FastTypeQuals : Qualifiers::FastWidth; |
| 1597 | |
| 1598 | unsigned HasExtQuals : 1; |
| 1599 | |
| 1600 | |
| 1601 | |
| 1602 | |
| 1603 | |
| 1604 | unsigned NumParams : 16; |
| 1605 | |
| 1606 | |
| 1607 | unsigned ExceptionSpecType : 4; |
| 1608 | |
| 1609 | |
| 1610 | unsigned HasExtParameterInfos : 1; |
| 1611 | |
| 1612 | |
| 1613 | unsigned Variadic : 1; |
| 1614 | |
| 1615 | |
| 1616 | unsigned HasTrailingReturn : 1; |
| 1617 | }; |
| 1618 | |
| 1619 | class ObjCObjectTypeBitfields { |
| 1620 | friend class ObjCObjectType; |
| 1621 | |
| 1622 | unsigned : NumTypeBits; |
| 1623 | |
| 1624 | |
| 1625 | unsigned NumTypeArgs : 7; |
| 1626 | |
| 1627 | |
| 1628 | unsigned NumProtocols : 6; |
| 1629 | |
| 1630 | |
| 1631 | unsigned IsKindOf : 1; |
| 1632 | }; |
| 1633 | |
| 1634 | class ReferenceTypeBitfields { |
| 1635 | friend class ReferenceType; |
| 1636 | |
| 1637 | unsigned : NumTypeBits; |
| 1638 | |
| 1639 | |
| 1640 | |
| 1641 | |
| 1642 | |
| 1643 | |
| 1644 | |
| 1645 | |
| 1646 | |
| 1647 | |
| 1648 | |
| 1649 | |
| 1650 | unsigned SpelledAsLValue : 1; |
| 1651 | |
| 1652 | |
| 1653 | |
| 1654 | unsigned InnerRef : 1; |
| 1655 | }; |
| 1656 | |
| 1657 | class TypeWithKeywordBitfields { |
| 1658 | friend class TypeWithKeyword; |
| 1659 | |
| 1660 | unsigned : NumTypeBits; |
| 1661 | |
| 1662 | |
| 1663 | unsigned Keyword : 8; |
| 1664 | }; |
| 1665 | |
| 1666 | enum { NumTypeWithKeywordBits = 8 }; |
| 1667 | |
| 1668 | class ElaboratedTypeBitfields { |
| 1669 | friend class ElaboratedType; |
| 1670 | |
| 1671 | unsigned : NumTypeBits; |
| 1672 | unsigned : NumTypeWithKeywordBits; |
| 1673 | |
| 1674 | |
| 1675 | unsigned HasOwnedTagDecl : 1; |
| 1676 | }; |
| 1677 | |
| 1678 | class VectorTypeBitfields { |
| 1679 | friend class VectorType; |
| 1680 | friend class DependentVectorType; |
| 1681 | |
| 1682 | unsigned : NumTypeBits; |
| 1683 | |
| 1684 | |
| 1685 | |
| 1686 | unsigned VecKind : 3; |
| 1687 | |
| 1688 | uint32_t NumElements; |
| 1689 | }; |
| 1690 | |
| 1691 | class AttributedTypeBitfields { |
| 1692 | friend class AttributedType; |
| 1693 | |
| 1694 | unsigned : NumTypeBits; |
| 1695 | |
| 1696 | |
| 1697 | unsigned AttrKind : 32 - NumTypeBits; |
| 1698 | }; |
| 1699 | |
| 1700 | class AutoTypeBitfields { |
| 1701 | friend class AutoType; |
| 1702 | |
| 1703 | unsigned : NumTypeBits; |
| 1704 | |
| 1705 | |
| 1706 | |
| 1707 | unsigned Keyword : 2; |
| 1708 | |
| 1709 | |
| 1710 | |
| 1711 | |
| 1712 | |
| 1713 | |
| 1714 | |
| 1715 | |
| 1716 | unsigned NumArgs; |
| 1717 | }; |
| 1718 | |
| 1719 | class SubstTemplateTypeParmPackTypeBitfields { |
| 1720 | friend class SubstTemplateTypeParmPackType; |
| 1721 | |
| 1722 | unsigned : NumTypeBits; |
| 1723 | |
| 1724 | |
| 1725 | |
| 1726 | |
| 1727 | |
| 1728 | |
| 1729 | |
| 1730 | |
| 1731 | unsigned NumArgs; |
| 1732 | }; |
| 1733 | |
| 1734 | class TemplateSpecializationTypeBitfields { |
| 1735 | friend class TemplateSpecializationType; |
| 1736 | |
| 1737 | unsigned : NumTypeBits; |
| 1738 | |
| 1739 | |
| 1740 | unsigned TypeAlias : 1; |
| 1741 | |
| 1742 | |
| 1743 | |
| 1744 | |
| 1745 | |
| 1746 | |
| 1747 | |
| 1748 | |
| 1749 | unsigned NumArgs; |
| 1750 | }; |
| 1751 | |
| 1752 | class DependentTemplateSpecializationTypeBitfields { |
| 1753 | friend class DependentTemplateSpecializationType; |
| 1754 | |
| 1755 | unsigned : NumTypeBits; |
| 1756 | unsigned : NumTypeWithKeywordBits; |
| 1757 | |
| 1758 | |
| 1759 | |
| 1760 | |
| 1761 | |
| 1762 | |
| 1763 | |
| 1764 | |
| 1765 | unsigned NumArgs; |
| 1766 | }; |
| 1767 | |
| 1768 | class PackExpansionTypeBitfields { |
| 1769 | friend class PackExpansionType; |
| 1770 | |
| 1771 | unsigned : NumTypeBits; |
| 1772 | |
| 1773 | |
| 1774 | |
| 1775 | |
| 1776 | |
| 1777 | |
| 1778 | |
| 1779 | |
| 1780 | |
| 1781 | |
| 1782 | |
| 1783 | |
| 1784 | unsigned NumExpansions; |
| 1785 | }; |
| 1786 | |
| 1787 | union { |
| 1788 | TypeBitfields TypeBits; |
| 1789 | ArrayTypeBitfields ArrayTypeBits; |
| 1790 | ConstantArrayTypeBitfields ConstantArrayTypeBits; |
| 1791 | AttributedTypeBitfields AttributedTypeBits; |
| 1792 | AutoTypeBitfields AutoTypeBits; |
| 1793 | BuiltinTypeBitfields BuiltinTypeBits; |
| 1794 | FunctionTypeBitfields FunctionTypeBits; |
| 1795 | ObjCObjectTypeBitfields ObjCObjectTypeBits; |
| 1796 | ReferenceTypeBitfields ReferenceTypeBits; |
| 1797 | TypeWithKeywordBitfields TypeWithKeywordBits; |
| 1798 | ElaboratedTypeBitfields ElaboratedTypeBits; |
| 1799 | VectorTypeBitfields VectorTypeBits; |
| 1800 | SubstTemplateTypeParmPackTypeBitfields SubstTemplateTypeParmPackTypeBits; |
| 1801 | TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits; |
| 1802 | DependentTemplateSpecializationTypeBitfields |
| 1803 | DependentTemplateSpecializationTypeBits; |
| 1804 | PackExpansionTypeBitfields PackExpansionTypeBits; |
| 1805 | }; |
| 1806 | |
| 1807 | private: |
| 1808 | template <class T> friend class TypePropertyCache; |
| 1809 | |
| 1810 | |
| 1811 | void setFromAST(bool V = true) const { |
| 1812 | TypeBits.FromAST = V; |
| 1813 | } |
| 1814 | |
| 1815 | protected: |
| 1816 | friend class ASTContext; |
| 1817 | |
| 1818 | Type(TypeClass tc, QualType canon, TypeDependence Dependence) |
| 1819 | : ExtQualsTypeCommonBase(this, |
| 1820 | canon.isNull() ? QualType(this_(), 0) : canon) { |
| 1821 | static_assert(sizeof(*this) <= 8 + sizeof(ExtQualsTypeCommonBase), |
| 1822 | "changing bitfields changed sizeof(Type)!"); |
| 1823 | static_assert(alignof(decltype(*this)) % sizeof(void *) == 0, |
| 1824 | "Insufficient alignment!"); |
| 1825 | TypeBits.TC = tc; |
| 1826 | TypeBits.Dependence = static_cast<unsigned>(Dependence); |
| 1827 | TypeBits.CacheValid = false; |
| 1828 | TypeBits.CachedLocalOrUnnamed = false; |
| 1829 | TypeBits.CachedLinkage = NoLinkage; |
| 1830 | TypeBits.FromAST = false; |
| 1831 | } |
| 1832 | |
| 1833 | |
| 1834 | Type *this_() { return this; } |
| 1835 | |
| 1836 | void setDependence(TypeDependence D) { |
| 1837 | TypeBits.Dependence = static_cast<unsigned>(D); |
| 1838 | } |
| 1839 | |
| 1840 | void addDependence(TypeDependence D) { setDependence(getDependence() | D); } |
| 1841 | |
| 1842 | public: |
| 1843 | friend class ASTReader; |
| 1844 | friend class ASTWriter; |
| 1845 | template <class T> friend class serialization::AbstractTypeReader; |
| 1846 | template <class T> friend class serialization::AbstractTypeWriter; |
| 1847 | |
| 1848 | Type(const Type &) = delete; |
| 1849 | Type(Type &&) = delete; |
| 1850 | Type &operator=(const Type &) = delete; |
| 1851 | Type &operator=(Type &&) = delete; |
| 1852 | |
| 1853 | TypeClass getTypeClass() const { return static_cast<TypeClass>(TypeBits.TC); } |
| 1854 | |
| 1855 | |
| 1856 | bool isFromAST() const { return TypeBits.FromAST; } |
| 1857 | |
| 1858 | |
| 1859 | |
| 1860 | |
| 1861 | |
| 1862 | |
| 1863 | |
| 1864 | |
| 1865 | |
| 1866 | |
| 1867 | |
| 1868 | |
| 1869 | |
| 1870 | |
| 1871 | |
| 1872 | |
| 1873 | bool containsUnexpandedParameterPack() const { |
| 1874 | return getDependence() & TypeDependence::UnexpandedPack; |
| 1875 | } |
| 1876 | |
| 1877 | |
| 1878 | |
| 1879 | bool isCanonicalUnqualified() const { |
| 1880 | return CanonicalType == QualType(this, 0); |
| 1881 | } |
| 1882 | |
| 1883 | |
| 1884 | |
| 1885 | |
| 1886 | QualType getLocallyUnqualifiedSingleStepDesugaredType() const; |
| 1887 | |
| 1888 | |
| 1889 | |
| 1890 | |
| 1891 | |
| 1892 | |
| 1893 | |
| 1894 | bool isSizelessType() const; |
| 1895 | bool isSizelessBuiltinType() const; |
| 1896 | |
| 1897 | |
| 1898 | |
| 1899 | |
| 1900 | bool isVLSTBuiltinType() const; |
| 1901 | |
| 1902 | |
| 1903 | |
| 1904 | |
| 1905 | QualType getSveEltType(const ASTContext &Ctx) const; |
| 1906 | |
| 1907 | |
| 1908 | |
| 1909 | |
| 1910 | |
| 1911 | |
| 1912 | |
| 1913 | |
| 1914 | |
| 1915 | |
| 1916 | |
| 1917 | |
| 1918 | bool isIncompleteType(NamedDecl **Def = nullptr) const; |
| 1919 | |
| 1920 | |
| 1921 | |
| 1922 | bool isIncompleteOrObjectType() const { |
| 1923 | return !isFunctionType(); |
| 1924 | } |
| 1925 | |
| 1926 | |
| 1927 | bool isObjectType() const { |
| 1928 | |
| 1929 | |
| 1930 | |
| 1931 | return !isReferenceType() && !isFunctionType() && !isVoidType(); |
| 1932 | } |
| 1933 | |
| 1934 | |
| 1935 | |
| 1936 | bool isLiteralType(const ASTContext &Ctx) const; |
| 1937 | |
| 1938 | |
| 1939 | bool isStructuralType() const; |
| 1940 | |
| 1941 | |
| 1942 | |
| 1943 | bool isStandardLayoutType() const; |
| 1944 | |
| 1945 | |
| 1946 | |
| 1947 | |
| 1948 | |
| 1949 | bool isBuiltinType() const; |
| 1950 | |
| 1951 | |
| 1952 | bool isSpecificBuiltinType(unsigned K) const; |
| 1953 | |
| 1954 | |
| 1955 | |
| 1956 | |
| 1957 | bool isPlaceholderType() const; |
| 1958 | const BuiltinType *getAsPlaceholderType() const; |
| 1959 | |
| 1960 | |
| 1961 | bool isSpecificPlaceholderType(unsigned K) const; |
| 1962 | |
| 1963 | |
| 1964 | |
| 1965 | bool isNonOverloadPlaceholderType() const; |
| 1966 | |
| 1967 | |
| 1968 | |
| 1969 | bool isIntegerType() const; |
| 1970 | bool isEnumeralType() const; |
| 1971 | |
| 1972 | |
| 1973 | bool isScopedEnumeralType() const; |
| 1974 | bool isBooleanType() const; |
| 1975 | bool isCharType() const; |
| 1976 | bool isWideCharType() const; |
| 1977 | bool isChar8Type() const; |
| 1978 | bool isChar16Type() const; |
| 1979 | bool isChar32Type() const; |
| 1980 | bool isAnyCharacterType() const; |
| 1981 | bool isIntegralType(const ASTContext &Ctx) const; |
| 1982 | |
| 1983 | |
| 1984 | bool isIntegralOrEnumerationType() const; |
| 1985 | |
| 1986 | |
| 1987 | bool isIntegralOrUnscopedEnumerationType() const; |
| 1988 | bool isUnscopedEnumerationType() const; |
| 1989 | |
| 1990 | |
| 1991 | bool isRealFloatingType() const; |
| 1992 | |
| 1993 | |
| 1994 | bool isComplexType() const; |
| 1995 | bool isAnyComplexType() const; |
| 1996 | bool isFloatingType() const; |
| 1997 | bool isHalfType() const; |
| 1998 | bool isFloat16Type() const; |
| 1999 | bool isBFloat16Type() const; |
| 2000 | bool isFloat128Type() const; |
| 2001 | bool isRealType() const; |
| 2002 | bool isArithmeticType() const; |
| 2003 | bool isVoidType() const; |
| 2004 | bool isScalarType() const; |
| 2005 | bool isAggregateType() const; |
| 2006 | bool isFundamentalType() const; |
| 2007 | bool isCompoundType() const; |
| 2008 | |
| 2009 | |
| 2010 | |
| 2011 | bool isFunctionType() const; |
| 2012 | bool isFunctionNoProtoType() const { return getAs<FunctionNoProtoType>(); } |
| 2013 | bool isFunctionProtoType() const { return getAs<FunctionProtoType>(); } |
| 2014 | bool isPointerType() const; |
| 2015 | bool isAnyPointerType() const; |
| 2016 | bool isBlockPointerType() const; |
| 2017 | bool isVoidPointerType() const; |
| 2018 | bool isReferenceType() const; |
| 2019 | bool isLValueReferenceType() const; |
| 2020 | bool isRValueReferenceType() const; |
| 2021 | bool isObjectPointerType() const; |
| 2022 | bool isFunctionPointerType() const; |
| 2023 | bool isFunctionReferenceType() const; |
| 2024 | bool isMemberPointerType() const; |
| 2025 | bool isMemberFunctionPointerType() const; |
| 2026 | bool isMemberDataPointerType() const; |
| 2027 | bool isArrayType() const; |
| 2028 | bool isConstantArrayType() const; |
| 2029 | bool isIncompleteArrayType() const; |
| 2030 | bool isVariableArrayType() const; |
| 2031 | bool isDependentSizedArrayType() const; |
| 2032 | bool isRecordType() const; |
| 2033 | bool isClassType() const; |
| 2034 | bool isStructureType() const; |
| 2035 | bool isObjCBoxableRecordType() const; |
| 2036 | bool isInterfaceType() const; |
| 2037 | bool isStructureOrClassType() const; |
| 2038 | bool isUnionType() const; |
| 2039 | bool isComplexIntegerType() const; |
| 2040 | bool isVectorType() const; |
| 2041 | bool isExtVectorType() const; |
| 2042 | bool isMatrixType() const; |
| 2043 | bool isConstantMatrixType() const; |
| 2044 | bool isDependentAddressSpaceType() const; |
| 2045 | bool isObjCObjectPointerType() const; |
| 2046 | bool isObjCRetainableType() const; |
| 2047 | bool isObjCLifetimeType() const; |
| 2048 | bool isObjCIndirectLifetimeType() const; |
| 2049 | bool isObjCNSObjectType() const; |
| 2050 | bool isObjCIndependentClassType() const; |
| 2051 | |
| 2052 | |
| 2053 | bool isObjCObjectType() const; |
| 2054 | bool isObjCQualifiedInterfaceType() const; |
| 2055 | bool isObjCQualifiedIdType() const; |
| 2056 | bool isObjCQualifiedClassType() const; |
| 2057 | bool isObjCObjectOrInterfaceType() const; |
| 2058 | bool isObjCIdType() const; |
| 2059 | bool isDecltypeType() const; |
| 2060 | |
| 2061 | |
| 2062 | |
| 2063 | |
| 2064 | |
| 2065 | |
| 2066 | bool isObjCInertUnsafeUnretainedType() const { |
| 2067 | return hasAttr(attr::ObjCInertUnsafeUnretained); |
| 2068 | } |
| 2069 | |
| 2070 | |
| 2071 | |
| 2072 | |
| 2073 | |
| 2074 | |
| 2075 | |
| 2076 | |
| 2077 | bool isObjCIdOrObjectKindOfType(const ASTContext &ctx, |
| 2078 | const ObjCObjectType *&bound) const; |
| 2079 | |
| 2080 | bool isObjCClassType() const; |
| 2081 | |
| 2082 | |
| 2083 | |
| 2084 | |
| 2085 | |
| 2086 | |
| 2087 | |
| 2088 | bool isObjCClassOrClassKindOfType() const; |
| 2089 | |
| 2090 | bool isBlockCompatibleObjCPointerType(ASTContext &ctx) const; |
| 2091 | bool isObjCSelType() const; |
| 2092 | bool isObjCBuiltinType() const; |
| 2093 | bool isObjCARCBridgableType() const; |
| 2094 | bool isCARCBridgableType() const; |
| 2095 | bool isTemplateTypeParmType() const; |
| 2096 | bool isNullPtrType() const; |
| 2097 | bool isNothrowT() const; |
| 2098 | bool isAlignValT() const; |
| 2099 | bool isStdByteType() const; |
| 2100 | bool isAtomicType() const; |
| 2101 | bool isUndeducedAutoType() const; |
| 2102 | |
| 2103 | bool isTypedefNameType() const; |
| 2104 | |
| 2105 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 2106 | bool is##Id##Type() const; |
| 2107 | #include "clang/Basic/OpenCLImageTypes.def" |
| 2108 | |
| 2109 | bool isImageType() const; |
| 2110 | |
| 2111 | bool isSamplerT() const; |
| 2112 | bool isEventT() const; |
| 2113 | bool isClkEventT() const; |
| 2114 | bool isQueueT() const; |
| 2115 | bool isReserveIDT() const; |
| 2116 | |
| 2117 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 2118 | bool is##Id##Type() const; |
| 2119 | #include "clang/Basic/OpenCLExtensionTypes.def" |
| 2120 | |
| 2121 | bool isOCLIntelSubgroupAVCType() const; |
| 2122 | bool isOCLExtOpaqueType() const; |
| 2123 | |
| 2124 | bool isPipeType() const; |
| 2125 | bool isExtIntType() const; |
| 2126 | bool isOpenCLSpecificType() const; |
| 2127 | |
| 2128 | |
| 2129 | |
| 2130 | |
| 2131 | bool isObjCARCImplicitlyUnretainedType() const; |
| 2132 | |
| 2133 | |
| 2134 | bool isCUDADeviceBuiltinSurfaceType() const; |
| 2135 | |
| 2136 | bool isCUDADeviceBuiltinTextureType() const; |
| 2137 | |
| 2138 | |
| 2139 | Qualifiers::ObjCLifetime getObjCARCImplicitLifetime() const; |
| 2140 | |
| 2141 | enum ScalarTypeKind { |
| 2142 | STK_CPointer, |
| 2143 | STK_BlockPointer, |
| 2144 | STK_ObjCObjectPointer, |
| 2145 | STK_MemberPointer, |
| 2146 | STK_Bool, |
| 2147 | STK_Integral, |
| 2148 | STK_Floating, |
| 2149 | STK_IntegralComplex, |
| 2150 | STK_FloatingComplex, |
| 2151 | STK_FixedPoint |
| 2152 | }; |
| 2153 | |
| 2154 | |
| 2155 | ScalarTypeKind getScalarTypeKind() const; |
| 2156 | |
| 2157 | TypeDependence getDependence() const { |
| 2158 | return static_cast<TypeDependence>(TypeBits.Dependence); |
| 2159 | } |
| 2160 | |
| 2161 | |
| 2162 | bool containsErrors() const { |
| 2163 | return getDependence() & TypeDependence::Error; |
| 2164 | } |
| 2165 | |
| 2166 | |
| 2167 | |
| 2168 | bool isDependentType() const { |
| 2169 | return getDependence() & TypeDependence::Dependent; |
| 2170 | } |
| 2171 | |
| 2172 | |
| 2173 | |
| 2174 | |
| 2175 | |
| 2176 | bool isInstantiationDependentType() const { |
| 2177 | return getDependence() & TypeDependence::Instantiation; |
| 2178 | } |
| 2179 | |
| 2180 | |
| 2181 | |
| 2182 | |
| 2183 | bool isUndeducedType() const; |
| 2184 | |
| 2185 | |
| 2186 | bool isVariablyModifiedType() const { |
| 2187 | return getDependence() & TypeDependence::VariablyModified; |
| 2188 | } |
| 2189 | |
| 2190 | |
| 2191 | |
| 2192 | bool hasSizedVLAType() const; |
| 2193 | |
| 2194 | |
| 2195 | bool hasUnnamedOrLocalType() const; |
| 2196 | |
| 2197 | bool isOverloadableType() const; |
| 2198 | |
| 2199 | |
| 2200 | bool isElaboratedTypeSpecifier() const; |
| 2201 | |
| 2202 | bool canDecayToPointerType() const; |
| 2203 | |
| 2204 | |
| 2205 | |
| 2206 | |
| 2207 | bool hasPointerRepresentation() const; |
| 2208 | |
| 2209 | |
| 2210 | |
| 2211 | bool hasObjCPointerRepresentation() const; |
| 2212 | |
| 2213 | |
| 2214 | |
| 2215 | bool hasIntegerRepresentation() const; |
| 2216 | |
| 2217 | |
| 2218 | |
| 2219 | bool hasSignedIntegerRepresentation() const; |
| 2220 | |
| 2221 | |
| 2222 | |
| 2223 | bool hasUnsignedIntegerRepresentation() const; |
| 2224 | |
| 2225 | |
| 2226 | |
| 2227 | bool hasFloatingRepresentation() const; |
| 2228 | |
| 2229 | |
| 2230 | |
| 2231 | |
| 2232 | const RecordType *getAsStructureType() const; |
| 2233 | |
| 2234 | const RecordType *getAsUnionType() const; |
| 2235 | const ComplexType *getAsComplexIntegerType() const; |
| 2236 | const ObjCObjectType *getAsObjCInterfaceType() const; |
| 2237 | |
| 2238 | |
| 2239 | |
| 2240 | const ObjCObjectPointerType *getAsObjCInterfacePointerType() const; |
| 2241 | const ObjCObjectPointerType *getAsObjCQualifiedIdType() const; |
| 2242 | const ObjCObjectPointerType *getAsObjCQualifiedClassType() const; |
| 2243 | const ObjCObjectType *getAsObjCQualifiedInterfaceType() const; |
| 2244 | |
| 2245 | |
| 2246 | |
| 2247 | |
| 2248 | CXXRecordDecl *getAsCXXRecordDecl() const; |
| 2249 | |
| 2250 | |
| 2251 | RecordDecl *getAsRecordDecl() const; |
| 2252 | |
| 2253 | |
| 2254 | |
| 2255 | |
| 2256 | TagDecl *getAsTagDecl() const; |
| 2257 | |
| 2258 | |
| 2259 | |
| 2260 | |
| 2261 | |
| 2262 | |
| 2263 | const CXXRecordDecl *getPointeeCXXRecordDecl() const; |
| 2264 | |
| 2265 | |
| 2266 | |
| 2267 | |
| 2268 | DeducedType *getContainedDeducedType() const; |
| 2269 | |
| 2270 | |
| 2271 | |
| 2272 | |
| 2273 | AutoType *getContainedAutoType() const { |
| 2274 | return dyn_cast_or_null<AutoType>(getContainedDeducedType()); |
| 2275 | } |
| 2276 | |
| 2277 | |
| 2278 | |
| 2279 | |
| 2280 | bool hasAutoForTrailingReturnType() const; |
| 2281 | |
| 2282 | |
| 2283 | |
| 2284 | |
| 2285 | |
| 2286 | |
| 2287 | |
| 2288 | template <typename T> const T *getAs() const; |
| 2289 | |
| 2290 | |
| 2291 | |
| 2292 | |
| 2293 | |
| 2294 | |
| 2295 | template <typename T> const T *getAsAdjusted() const; |
| 2296 | |
| 2297 | |
| 2298 | |
| 2299 | const ArrayType *getAsArrayTypeUnsafe() const; |
| 2300 | |
| 2301 | |
| 2302 | |
| 2303 | |
| 2304 | |
| 2305 | |
| 2306 | |
| 2307 | template <typename T> const T *castAs() const; |
| 2308 | |
| 2309 | |
| 2310 | |
| 2311 | const ArrayType *castAsArrayTypeUnsafe() const; |
| 2312 | |
| 2313 | |
| 2314 | |
| 2315 | bool hasAttr(attr::Kind AK) const; |
| 2316 | |
| 2317 | |
| 2318 | |
| 2319 | |
| 2320 | const Type *getBaseElementTypeUnsafe() const; |
| 2321 | |
| 2322 | |
| 2323 | |
| 2324 | |
| 2325 | const Type *getArrayElementTypeNoTypeQual() const; |
| 2326 | |
| 2327 | |
| 2328 | |
| 2329 | |
| 2330 | const Type *getPointeeOrArrayElementType() const; |
| 2331 | |
| 2332 | |
| 2333 | |
| 2334 | QualType getPointeeType() const; |
| 2335 | |
| 2336 | |
| 2337 | |
| 2338 | const Type *getUnqualifiedDesugaredType() const; |
| 2339 | |
| 2340 | |
| 2341 | bool isPromotableIntegerType() const; |
| 2342 | |
| 2343 | |
| 2344 | |
| 2345 | |
| 2346 | bool isSignedIntegerType() const; |
| 2347 | |
| 2348 | |
| 2349 | |
| 2350 | |
| 2351 | bool isUnsignedIntegerType() const; |
| 2352 | |
| 2353 | |
| 2354 | |
| 2355 | bool isSignedIntegerOrEnumerationType() const; |
| 2356 | |
| 2357 | |
| 2358 | |
| 2359 | bool isUnsignedIntegerOrEnumerationType() const; |
| 2360 | |
| 2361 | |
| 2362 | |
| 2363 | bool isFixedPointType() const; |
| 2364 | |
| 2365 | |
| 2366 | bool isFixedPointOrIntegerType() const; |
| 2367 | |
| 2368 | |
| 2369 | |
| 2370 | bool isSaturatedFixedPointType() const; |
| 2371 | |
| 2372 | |
| 2373 | |
| 2374 | bool isUnsaturatedFixedPointType() const; |
| 2375 | |
| 2376 | |
| 2377 | |
| 2378 | bool isSignedFixedPointType() const; |
| 2379 | |
| 2380 | |
| 2381 | |
| 2382 | bool isUnsignedFixedPointType() const; |
| 2383 | |
| 2384 | |
| 2385 | |
| 2386 | |
| 2387 | bool isConstantSizeType() const; |
| 2388 | |
| 2389 | |
| 2390 | |
| 2391 | bool isSpecifierType() const; |
| 2392 | |
| 2393 | |
| 2394 | Linkage getLinkage() const; |
| 2395 | |
| 2396 | |
| 2397 | Visibility getVisibility() const { |
| 2398 | return getLinkageAndVisibility().getVisibility(); |
| 2399 | } |
| 2400 | |
| 2401 | |
| 2402 | bool isVisibilityExplicit() const { |
| 2403 | return getLinkageAndVisibility().isVisibilityExplicit(); |
| 2404 | } |
| 2405 | |
| 2406 | |
| 2407 | LinkageInfo getLinkageAndVisibility() const; |
| 2408 | |
| 2409 | |
| 2410 | |
| 2411 | bool isLinkageValid() const; |
| 2412 | |
| 2413 | |
| 2414 | |
| 2415 | |
| 2416 | |
| 2417 | |
| 2418 | Optional<NullabilityKind> getNullability(const ASTContext &context) const; |
| 2419 | |
| 2420 | |
| 2421 | |
| 2422 | |
| 2423 | |
| 2424 | |
| 2425 | bool canHaveNullability(bool ResultIfUnknown = true) const; |
| 2426 | |
| 2427 | |
| 2428 | |
| 2429 | |
| 2430 | |
| 2431 | |
| 2432 | |
| 2433 | |
| 2434 | |
| 2435 | |
| 2436 | |
| 2437 | |
| 2438 | |
| 2439 | |
| 2440 | |
| 2441 | |
| 2442 | Optional<ArrayRef<QualType>> |
| 2443 | getObjCSubstitutions(const DeclContext *dc) const; |
| 2444 | |
| 2445 | |
| 2446 | |
| 2447 | bool acceptsObjCTypeParams() const; |
| 2448 | |
| 2449 | const char *getTypeClassName() const; |
| 2450 | |
| 2451 | QualType getCanonicalTypeInternal() const { |
| 2452 | return CanonicalType; |
| 2453 | } |
| 2454 | |
| 2455 | CanQualType getCanonicalTypeUnqualified() const; |
| 2456 | void dump() const; |
| 2457 | void dump(llvm::raw_ostream &OS, const ASTContext &Context) const; |
| 2458 | }; |
| 2459 | |
| 2460 | |
| 2461 | |
| 2462 | template <> const TypedefType *Type::getAs() const; |
| 2463 | |
| 2464 | |
| 2465 | |
| 2466 | |
| 2467 | template <> const TemplateSpecializationType *Type::getAs() const; |
| 2468 | |
| 2469 | |
| 2470 | |
| 2471 | template <> const AttributedType *Type::getAs() const; |
| 2472 | |
| 2473 | |
| 2474 | |
| 2475 | #define TYPE(Class, Base) |
| 2476 | #define LEAF_TYPE(Class) \ |
| 2477 | template <> inline const Class##Type *Type::getAs() const { \ |
| 2478 | return dyn_cast<Class##Type>(CanonicalType); \ |
| 2479 | } \ |
| 2480 | template <> inline const Class##Type *Type::castAs() const { \ |
| 2481 | return cast<Class##Type>(CanonicalType); \ |
| 2482 | } |
| 2483 | #include "clang/AST/TypeNodes.inc" |
| 2484 | |
| 2485 | |
| 2486 | |
| 2487 | class BuiltinType : public Type { |
| 2488 | public: |
| 2489 | enum Kind { |
| 2490 | |
| 2491 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) Id, |
| 2492 | #include "clang/Basic/OpenCLImageTypes.def" |
| 2493 | |
| 2494 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) Id, |
| 2495 | #include "clang/Basic/OpenCLExtensionTypes.def" |
| 2496 | |
| 2497 | #define SVE_TYPE(Name, Id, SingletonId) Id, |
| 2498 | #include "clang/Basic/AArch64SVEACLETypes.def" |
| 2499 | |
| 2500 | #define PPC_VECTOR_TYPE(Name, Id, Size) Id, |
| 2501 | #include "clang/Basic/PPCTypes.def" |
| 2502 | |
| 2503 | #define RVV_TYPE(Name, Id, SingletonId) Id, |
| 2504 | #include "clang/Basic/RISCVVTypes.def" |
| 2505 | |
| 2506 | #define BUILTIN_TYPE(Id, SingletonId) Id, |
| 2507 | #define LAST_BUILTIN_TYPE(Id) LastKind = Id |
| 2508 | #include "clang/AST/BuiltinTypes.def" |
| 2509 | }; |
| 2510 | |
| 2511 | private: |
| 2512 | friend class ASTContext; |
| 2513 | |
| 2514 | BuiltinType(Kind K) |
| 2515 | : Type(Builtin, QualType(), |
| 2516 | K == Dependent ? TypeDependence::DependentInstantiation |
| 2517 | : TypeDependence::None) { |
| 2518 | BuiltinTypeBits.Kind = K; |
| 2519 | } |
| 2520 | |
| 2521 | public: |
| 2522 | Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); } |
| 2523 | StringRef getName(const PrintingPolicy &Policy) const; |
| 2524 | |
| 2525 | const char *getNameAsCString(const PrintingPolicy &Policy) const { |
| 2526 | |
| 2527 | StringRef str = getName(Policy); |
| 2528 | assert(!str.empty() && str.data()[str.size()] == '\0'); |
| 2529 | return str.data(); |
| 2530 | } |
| 2531 | |
| 2532 | bool isSugared() const { return false; } |
| 2533 | QualType desugar() const { return QualType(this, 0); } |
| 2534 | |
| 2535 | bool isInteger() const { |
| 2536 | return getKind() >= Bool && getKind() <= Int128; |
| 2537 | } |
| 2538 | |
| 2539 | bool isSignedInteger() const { |
| 2540 | return getKind() >= Char_S && getKind() <= Int128; |
| 2541 | } |
| 2542 | |
| 2543 | bool isUnsignedInteger() const { |
| 2544 | return getKind() >= Bool && getKind() <= UInt128; |
| 2545 | } |
| 2546 | |
| 2547 | bool isFloatingPoint() const { |
| 2548 | return getKind() >= Half && getKind() <= Float128; |
| 2549 | } |
| 2550 | |
| 2551 | |
| 2552 | static bool isPlaceholderTypeKind(Kind K) { |
| 2553 | return K >= Overload; |
| 2554 | } |
| 2555 | |
| 2556 | |
| 2557 | |
| 2558 | |
| 2559 | bool isPlaceholderType() const { |
| 2560 | return isPlaceholderTypeKind(getKind()); |
| 2561 | } |
| 2562 | |
| 2563 | |
| 2564 | |
| 2565 | |
| 2566 | |
| 2567 | |
| 2568 | |
| 2569 | |
| 2570 | |
| 2571 | |
| 2572 | bool isNonOverloadPlaceholderType() const { |
| 2573 | return getKind() > Overload; |
| 2574 | } |
| 2575 | |
| 2576 | static bool classof(const Type *T) { return T->getTypeClass() == Builtin; } |
| 2577 | }; |
| 2578 | |
| 2579 | |
| 2580 | |
| 2581 | class ComplexType : public Type, public llvm::FoldingSetNode { |
| 2582 | friend class ASTContext; |
| 2583 | |
| 2584 | QualType ElementType; |
| 2585 | |
| 2586 | ComplexType(QualType Element, QualType CanonicalPtr) |
| 2587 | : Type(Complex, CanonicalPtr, Element->getDependence()), |
| 2588 | ElementType(Element) {} |
| 2589 | |
| 2590 | public: |
| 2591 | QualType getElementType() const { return ElementType; } |
| 2592 | |
| 2593 | bool isSugared() const { return false; } |
| 2594 | QualType desugar() const { return QualType(this, 0); } |
| 2595 | |
| 2596 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 2597 | Profile(ID, getElementType()); |
| 2598 | } |
| 2599 | |
| 2600 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Element) { |
| 2601 | ID.AddPointer(Element.getAsOpaquePtr()); |
| 2602 | } |
| 2603 | |
| 2604 | static bool classof(const Type *T) { return T->getTypeClass() == Complex; } |
| 2605 | }; |
| 2606 | |
| 2607 | |
| 2608 | class ParenType : public Type, public llvm::FoldingSetNode { |
| 2609 | friend class ASTContext; |
| 2610 | |
| 2611 | QualType Inner; |
| 2612 | |
| 2613 | ParenType(QualType InnerType, QualType CanonType) |
| 2614 | : Type(Paren, CanonType, InnerType->getDependence()), Inner(InnerType) {} |
| 2615 | |
| 2616 | public: |
| 2617 | QualType getInnerType() const { return Inner; } |
| 2618 | |
| 2619 | bool isSugared() const { return true; } |
| 2620 | QualType desugar() const { return getInnerType(); } |
| 2621 | |
| 2622 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 2623 | Profile(ID, getInnerType()); |
| 2624 | } |
| 2625 | |
| 2626 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Inner) { |
| 2627 | Inner.Profile(ID); |
| 2628 | } |
| 2629 | |
| 2630 | static bool classof(const Type *T) { return T->getTypeClass() == Paren; } |
| 2631 | }; |
| 2632 | |
| 2633 | |
| 2634 | class PointerType : public Type, public llvm::FoldingSetNode { |
| 2635 | friend class ASTContext; |
| 2636 | |
| 2637 | QualType PointeeType; |
| 2638 | |
| 2639 | PointerType(QualType Pointee, QualType CanonicalPtr) |
| 2640 | : Type(Pointer, CanonicalPtr, Pointee->getDependence()), |
| 2641 | PointeeType(Pointee) {} |
| 2642 | |
| 2643 | public: |
| 2644 | QualType getPointeeType() const { return PointeeType; } |
| 2645 | |
| 2646 | bool isSugared() const { return false; } |
| 2647 | QualType desugar() const { return QualType(this, 0); } |
| 2648 | |
| 2649 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 2650 | Profile(ID, getPointeeType()); |
| 2651 | } |
| 2652 | |
| 2653 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { |
| 2654 | ID.AddPointer(Pointee.getAsOpaquePtr()); |
| 2655 | } |
| 2656 | |
| 2657 | static bool classof(const Type *T) { return T->getTypeClass() == Pointer; } |
| 2658 | }; |
| 2659 | |
| 2660 | |
| 2661 | |
| 2662 | |
| 2663 | class AdjustedType : public Type, public llvm::FoldingSetNode { |
| 2664 | QualType OriginalTy; |
| 2665 | QualType AdjustedTy; |
| 2666 | |
| 2667 | protected: |
| 2668 | friend class ASTContext; |
| 2669 | |
| 2670 | AdjustedType(TypeClass TC, QualType OriginalTy, QualType AdjustedTy, |
| 2671 | QualType CanonicalPtr) |
| 2672 | : Type(TC, CanonicalPtr, OriginalTy->getDependence()), |
| 2673 | OriginalTy(OriginalTy), AdjustedTy(AdjustedTy) {} |
| 2674 | |
| 2675 | public: |
| 2676 | QualType getOriginalType() const { return OriginalTy; } |
| 2677 | QualType getAdjustedType() const { return AdjustedTy; } |
| 2678 | |
| 2679 | bool isSugared() const { return true; } |
| 2680 | QualType desugar() const { return AdjustedTy; } |
| 2681 | |
| 2682 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 2683 | Profile(ID, OriginalTy, AdjustedTy); |
| 2684 | } |
| 2685 | |
| 2686 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Orig, QualType New) { |
| 2687 | ID.AddPointer(Orig.getAsOpaquePtr()); |
| 2688 | ID.AddPointer(New.getAsOpaquePtr()); |
| 2689 | } |
| 2690 | |
| 2691 | static bool classof(const Type *T) { |
| 2692 | return T->getTypeClass() == Adjusted || T->getTypeClass() == Decayed; |
| 2693 | } |
| 2694 | }; |
| 2695 | |
| 2696 | |
| 2697 | class DecayedType : public AdjustedType { |
| 2698 | friend class ASTContext; |
| 2699 | |
| 2700 | inline |
| 2701 | DecayedType(QualType OriginalType, QualType Decayed, QualType Canonical); |
| 2702 | |
| 2703 | public: |
| 2704 | QualType getDecayedType() const { return getAdjustedType(); } |
| 2705 | |
| 2706 | inline QualType getPointeeType() const; |
| 2707 | |
| 2708 | static bool classof(const Type *T) { return T->getTypeClass() == Decayed; } |
| 2709 | }; |
| 2710 | |
| 2711 | |
| 2712 | |
| 2713 | |
| 2714 | class BlockPointerType : public Type, public llvm::FoldingSetNode { |
| 2715 | friend class ASTContext; |
| 2716 | |
| 2717 | |
| 2718 | QualType PointeeType; |
| 2719 | |
| 2720 | BlockPointerType(QualType Pointee, QualType CanonicalCls) |
| 2721 | : Type(BlockPointer, CanonicalCls, Pointee->getDependence()), |
| 2722 | PointeeType(Pointee) {} |
| 2723 | |
| 2724 | public: |
| 2725 | |
| 2726 | QualType getPointeeType() const { return PointeeType; } |
| 2727 | |
| 2728 | bool isSugared() const { return false; } |
| 2729 | QualType desugar() const { return QualType(this, 0); } |
| 2730 | |
| 2731 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 2732 | Profile(ID, getPointeeType()); |
| 2733 | } |
| 2734 | |
| 2735 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee) { |
| 2736 | ID.AddPointer(Pointee.getAsOpaquePtr()); |
| 2737 | } |
| 2738 | |
| 2739 | static bool classof(const Type *T) { |
| 2740 | return T->getTypeClass() == BlockPointer; |
| 2741 | } |
| 2742 | }; |
| 2743 | |
| 2744 | |
| 2745 | class ReferenceType : public Type, public llvm::FoldingSetNode { |
| 2746 | QualType PointeeType; |
| 2747 | |
| 2748 | protected: |
| 2749 | ReferenceType(TypeClass tc, QualType Referencee, QualType CanonicalRef, |
| 2750 | bool SpelledAsLValue) |
| 2751 | : Type(tc, CanonicalRef, Referencee->getDependence()), |
| 2752 | PointeeType(Referencee) { |
| 2753 | ReferenceTypeBits.SpelledAsLValue = SpelledAsLValue; |
| 2754 | ReferenceTypeBits.InnerRef = Referencee->isReferenceType(); |
| 2755 | } |
| 2756 | |
| 2757 | public: |
| 2758 | bool isSpelledAsLValue() const { return ReferenceTypeBits.SpelledAsLValue; } |
| 2759 | bool isInnerRef() const { return ReferenceTypeBits.InnerRef; } |
| 2760 | |
| 2761 | QualType getPointeeTypeAsWritten() const { return PointeeType; } |
| 2762 | |
| 2763 | QualType getPointeeType() const { |
| 2764 | |
| 2765 | const ReferenceType *T = this; |
| 2766 | while (T->isInnerRef()) |
| 2767 | T = T->PointeeType->castAs<ReferenceType>(); |
| 2768 | return T->PointeeType; |
| 2769 | } |
| 2770 | |
| 2771 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 2772 | Profile(ID, PointeeType, isSpelledAsLValue()); |
| 2773 | } |
| 2774 | |
| 2775 | static void Profile(llvm::FoldingSetNodeID &ID, |
| 2776 | QualType Referencee, |
| 2777 | bool SpelledAsLValue) { |
| 2778 | ID.AddPointer(Referencee.getAsOpaquePtr()); |
| 2779 | ID.AddBoolean(SpelledAsLValue); |
| 2780 | } |
| 2781 | |
| 2782 | static bool classof(const Type *T) { |
| 2783 | return T->getTypeClass() == LValueReference || |
| 2784 | T->getTypeClass() == RValueReference; |
| 2785 | } |
| 2786 | }; |
| 2787 | |
| 2788 | |
| 2789 | class LValueReferenceType : public ReferenceType { |
| 2790 | friend class ASTContext; |
| 2791 | |
| 2792 | LValueReferenceType(QualType Referencee, QualType CanonicalRef, |
| 2793 | bool SpelledAsLValue) |
| 2794 | : ReferenceType(LValueReference, Referencee, CanonicalRef, |
| 2795 | SpelledAsLValue) {} |
| 2796 | |
| 2797 | public: |
| 2798 | bool isSugared() const { return false; } |
| 2799 | QualType desugar() const { return QualType(this, 0); } |
| 2800 | |
| 2801 | static bool classof(const Type *T) { |
| 2802 | return T->getTypeClass() == LValueReference; |
| 2803 | } |
| 2804 | }; |
| 2805 | |
| 2806 | |
| 2807 | class RValueReferenceType : public ReferenceType { |
| 2808 | friend class ASTContext; |
| 2809 | |
| 2810 | RValueReferenceType(QualType Referencee, QualType CanonicalRef) |
| 2811 | : ReferenceType(RValueReference, Referencee, CanonicalRef, false) {} |
| 2812 | |
| 2813 | public: |
| 2814 | bool isSugared() const { return false; } |
| 2815 | QualType desugar() const { return QualType(this, 0); } |
| 2816 | |
| 2817 | static bool classof(const Type *T) { |
| 2818 | return T->getTypeClass() == RValueReference; |
| 2819 | } |
| 2820 | }; |
| 2821 | |
| 2822 | |
| 2823 | |
| 2824 | |
| 2825 | class MemberPointerType : public Type, public llvm::FoldingSetNode { |
| 2826 | friend class ASTContext; |
| 2827 | |
| 2828 | QualType PointeeType; |
| 2829 | |
| 2830 | |
| 2831 | |
| 2832 | const Type *Class; |
| 2833 | |
| 2834 | MemberPointerType(QualType Pointee, const Type *Cls, QualType CanonicalPtr) |
| 2835 | : Type(MemberPointer, CanonicalPtr, |
| 2836 | (Cls->getDependence() & ~TypeDependence::VariablyModified) | |
| 2837 | Pointee->getDependence()), |
| 2838 | PointeeType(Pointee), Class(Cls) {} |
| 2839 | |
| 2840 | public: |
| 2841 | QualType getPointeeType() const { return PointeeType; } |
| 2842 | |
| 2843 | |
| 2844 | |
| 2845 | bool isMemberFunctionPointer() const { |
| 2846 | return PointeeType->isFunctionProtoType(); |
| 2847 | } |
| 2848 | |
| 2849 | |
| 2850 | |
| 2851 | bool isMemberDataPointer() const { |
| 2852 | return !PointeeType->isFunctionProtoType(); |
| 2853 | } |
| 2854 | |
| 2855 | const Type *getClass() const { return Class; } |
| 2856 | CXXRecordDecl *getMostRecentCXXRecordDecl() const; |
| 2857 | |
| 2858 | bool isSugared() const { return false; } |
| 2859 | QualType desugar() const { return QualType(this, 0); } |
| 2860 | |
| 2861 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 2862 | Profile(ID, getPointeeType(), getClass()); |
| 2863 | } |
| 2864 | |
| 2865 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Pointee, |
| 2866 | const Type *Class) { |
| 2867 | ID.AddPointer(Pointee.getAsOpaquePtr()); |
| 2868 | ID.AddPointer(Class); |
| 2869 | } |
| 2870 | |
| 2871 | static bool classof(const Type *T) { |
| 2872 | return T->getTypeClass() == MemberPointer; |
| 2873 | } |
| 2874 | }; |
| 2875 | |
| 2876 | |
| 2877 | class ArrayType : public Type, public llvm::FoldingSetNode { |
| 2878 | public: |
| 2879 | |
| 2880 | |
| 2881 | |
| 2882 | |
| 2883 | enum ArraySizeModifier { |
| 2884 | Normal, Static, Star |
| 2885 | }; |
| 2886 | |
| 2887 | private: |
| 2888 | |
| 2889 | QualType ElementType; |
| 2890 | |
| 2891 | protected: |
| 2892 | friend class ASTContext; |
| 2893 | |
| 2894 | ArrayType(TypeClass tc, QualType et, QualType can, ArraySizeModifier sm, |
| 2895 | unsigned tq, const Expr *sz = nullptr); |
| 2896 | |
| 2897 | public: |
| 2898 | QualType getElementType() const { return ElementType; } |
| 2899 | |
| 2900 | ArraySizeModifier getSizeModifier() const { |
| 2901 | return ArraySizeModifier(ArrayTypeBits.SizeModifier); |
| 2902 | } |
| 2903 | |
| 2904 | Qualifiers getIndexTypeQualifiers() const { |
| 2905 | return Qualifiers::fromCVRMask(getIndexTypeCVRQualifiers()); |
| 2906 | } |
| 2907 | |
| 2908 | unsigned getIndexTypeCVRQualifiers() const { |
| 2909 | return ArrayTypeBits.IndexTypeQuals; |
| 2910 | } |
| 2911 | |
| 2912 | static bool classof(const Type *T) { |
| 2913 | return T->getTypeClass() == ConstantArray || |
| 2914 | T->getTypeClass() == VariableArray || |
| 2915 | T->getTypeClass() == IncompleteArray || |
| 2916 | T->getTypeClass() == DependentSizedArray; |
| 2917 | } |
| 2918 | }; |
| 2919 | |
| 2920 | |
| 2921 | |
| 2922 | |
| 2923 | class ConstantArrayType final |
| 2924 | : public ArrayType, |
| 2925 | private llvm::TrailingObjects<ConstantArrayType, const Expr *> { |
| 2926 | friend class ASTContext; |
| 2927 | friend TrailingObjects; |
| 2928 | |
| 2929 | llvm::APInt Size; |
| 2930 | |
| 2931 | ConstantArrayType(QualType et, QualType can, const llvm::APInt &size, |
| 2932 | const Expr *sz, ArraySizeModifier sm, unsigned tq) |
| 2933 | : ArrayType(ConstantArray, et, can, sm, tq, sz), Size(size) { |
| 2934 | ConstantArrayTypeBits.HasStoredSizeExpr = sz != nullptr; |
| 2935 | if (ConstantArrayTypeBits.HasStoredSizeExpr) { |
| 2936 | assert(!can.isNull() && "canonical constant array should not have size"); |
| 2937 | *getTrailingObjects<const Expr*>() = sz; |
| 2938 | } |
| 2939 | } |
| 2940 | |
| 2941 | unsigned numTrailingObjects(OverloadToken<const Expr*>) const { |
| 2942 | return ConstantArrayTypeBits.HasStoredSizeExpr; |
| 2943 | } |
| 2944 | |
| 2945 | public: |
| 2946 | const llvm::APInt &getSize() const { return Size; } |
| 2947 | const Expr *getSizeExpr() const { |
| 2948 | return ConstantArrayTypeBits.HasStoredSizeExpr |
| 2949 | ? *getTrailingObjects<const Expr *>() |
| 2950 | : nullptr; |
| 2951 | } |
| 2952 | bool isSugared() const { return false; } |
| 2953 | QualType desugar() const { return QualType(this, 0); } |
| 2954 | |
| 2955 | |
| 2956 | |
| 2957 | static unsigned getNumAddressingBits(const ASTContext &Context, |
| 2958 | QualType ElementType, |
| 2959 | const llvm::APInt &NumElements); |
| 2960 | |
| 2961 | |
| 2962 | |
| 2963 | static unsigned getMaxSizeBits(const ASTContext &Context); |
| 2964 | |
| 2965 | void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) { |
| 2966 | Profile(ID, Ctx, getElementType(), getSize(), getSizeExpr(), |
| 2967 | getSizeModifier(), getIndexTypeCVRQualifiers()); |
| 2968 | } |
| 2969 | |
| 2970 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx, |
| 2971 | QualType ET, const llvm::APInt &ArraySize, |
| 2972 | const Expr *SizeExpr, ArraySizeModifier SizeMod, |
| 2973 | unsigned TypeQuals); |
| 2974 | |
| 2975 | static bool classof(const Type *T) { |
| 2976 | return T->getTypeClass() == ConstantArray; |
| 2977 | } |
| 2978 | }; |
| 2979 | |
| 2980 | |
| 2981 | |
| 2982 | |
| 2983 | class IncompleteArrayType : public ArrayType { |
| 2984 | friend class ASTContext; |
| 2985 | |
| 2986 | IncompleteArrayType(QualType et, QualType can, |
| 2987 | ArraySizeModifier sm, unsigned tq) |
| 2988 | : ArrayType(IncompleteArray, et, can, sm, tq) {} |
| 2989 | |
| 2990 | public: |
| 2991 | friend class StmtIteratorBase; |
| 2992 | |
| 2993 | bool isSugared() const { return false; } |
| 2994 | QualType desugar() const { return QualType(this, 0); } |
| 2995 | |
| 2996 | static bool classof(const Type *T) { |
| 2997 | return T->getTypeClass() == IncompleteArray; |
| 2998 | } |
| 2999 | |
| 3000 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 3001 | Profile(ID, getElementType(), getSizeModifier(), |
| 3002 | getIndexTypeCVRQualifiers()); |
| 3003 | } |
| 3004 | |
| 3005 | static void Profile(llvm::FoldingSetNodeID &ID, QualType ET, |
| 3006 | ArraySizeModifier SizeMod, unsigned TypeQuals) { |
| 3007 | ID.AddPointer(ET.getAsOpaquePtr()); |
| 3008 | ID.AddInteger(SizeMod); |
| 3009 | ID.AddInteger(TypeQuals); |
| 3010 | } |
| 3011 | }; |
| 3012 | |
| 3013 | |
| 3014 | |
| 3015 | |
| 3016 | |
| 3017 | |
| 3018 | |
| 3019 | |
| 3020 | |
| 3021 | |
| 3022 | |
| 3023 | |
| 3024 | |
| 3025 | |
| 3026 | |
| 3027 | class VariableArrayType : public ArrayType { |
| 3028 | friend class ASTContext; |
| 3029 | |
| 3030 | |
| 3031 | |
| 3032 | Stmt *SizeExpr; |
| 3033 | |
| 3034 | |
| 3035 | SourceRange Brackets; |
| 3036 | |
| 3037 | VariableArrayType(QualType et, QualType can, Expr *e, |
| 3038 | ArraySizeModifier sm, unsigned tq, |
| 3039 | SourceRange brackets) |
| 3040 | : ArrayType(VariableArray, et, can, sm, tq, e), |
| 3041 | SizeExpr((Stmt*) e), Brackets(brackets) {} |
| 3042 | |
| 3043 | public: |
| 3044 | friend class StmtIteratorBase; |
| 3045 | |
| 3046 | Expr *getSizeExpr() const { |
| 3047 | |
| 3048 | |
| 3049 | return (Expr*) SizeExpr; |
| 3050 | } |
| 3051 | |
| 3052 | SourceRange getBracketsRange() const { return Brackets; } |
| 3053 | SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } |
| 3054 | SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } |
| 3055 | |
| 3056 | bool isSugared() const { return false; } |
| 3057 | QualType desugar() const { return QualType(this, 0); } |
| 3058 | |
| 3059 | static bool classof(const Type *T) { |
| 3060 | return T->getTypeClass() == VariableArray; |
| 3061 | } |
| 3062 | |
| 3063 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 3064 | llvm_unreachable("Cannot unique VariableArrayTypes."); |
| 3065 | } |
| 3066 | }; |
| 3067 | |
| 3068 | |
| 3069 | |
| 3070 | |
| 3071 | |
| 3072 | |
| 3073 | |
| 3074 | |
| 3075 | |
| 3076 | |
| 3077 | |
| 3078 | |
| 3079 | |
| 3080 | |
| 3081 | class DependentSizedArrayType : public ArrayType { |
| 3082 | friend class ASTContext; |
| 3083 | |
| 3084 | const ASTContext &Context; |
| 3085 | |
| 3086 | |
| 3087 | |
| 3088 | |
| 3089 | |
| 3090 | |
| 3091 | Stmt *SizeExpr; |
| 3092 | |
| 3093 | |
| 3094 | SourceRange Brackets; |
| 3095 | |
| 3096 | DependentSizedArrayType(const ASTContext &Context, QualType et, QualType can, |
| 3097 | Expr *e, ArraySizeModifier sm, unsigned tq, |
| 3098 | SourceRange brackets); |
| 3099 | |
| 3100 | public: |
| 3101 | friend class StmtIteratorBase; |
| 3102 | |
| 3103 | Expr *getSizeExpr() const { |
| 3104 | |
| 3105 | |
| 3106 | return (Expr*) SizeExpr; |
| 3107 | } |
| 3108 | |
| 3109 | SourceRange getBracketsRange() const { return Brackets; } |
| 3110 | SourceLocation getLBracketLoc() const { return Brackets.getBegin(); } |
| 3111 | SourceLocation getRBracketLoc() const { return Brackets.getEnd(); } |
| 3112 | |
| 3113 | bool isSugared() const { return false; } |
| 3114 | QualType desugar() const { return QualType(this, 0); } |
| 3115 | |
| 3116 | static bool classof(const Type *T) { |
| 3117 | return T->getTypeClass() == DependentSizedArray; |
| 3118 | } |
| 3119 | |
| 3120 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 3121 | Profile(ID, Context, getElementType(), |
| 3122 | getSizeModifier(), getIndexTypeCVRQualifiers(), getSizeExpr()); |
| 3123 | } |
| 3124 | |
| 3125 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
| 3126 | QualType ET, ArraySizeModifier SizeMod, |
| 3127 | unsigned TypeQuals, Expr *E); |
| 3128 | }; |
| 3129 | |
| 3130 | |
| 3131 | |
| 3132 | |
| 3133 | |
| 3134 | |
| 3135 | |
| 3136 | |
| 3137 | |
| 3138 | |
| 3139 | |
| 3140 | |
| 3141 | class DependentAddressSpaceType : public Type, public llvm::FoldingSetNode { |
| 3142 | friend class ASTContext; |
| 3143 | |
| 3144 | const ASTContext &Context; |
| 3145 | Expr *AddrSpaceExpr; |
| 3146 | QualType PointeeType; |
| 3147 | SourceLocation loc; |
| 3148 | |
| 3149 | DependentAddressSpaceType(const ASTContext &Context, QualType PointeeType, |
| 3150 | QualType can, Expr *AddrSpaceExpr, |
| 3151 | SourceLocation loc); |
| 3152 | |
| 3153 | public: |
| 3154 | Expr *getAddrSpaceExpr() const { return AddrSpaceExpr; } |
| 3155 | QualType getPointeeType() const { return PointeeType; } |
| 3156 | SourceLocation getAttributeLoc() const { return loc; } |
| 3157 | |
| 3158 | bool isSugared() const { return false; } |
| 3159 | QualType desugar() const { return QualType(this, 0); } |
| 3160 | |
| 3161 | static bool classof(const Type *T) { |
| 3162 | return T->getTypeClass() == DependentAddressSpace; |
| 3163 | } |
| 3164 | |
| 3165 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 3166 | Profile(ID, Context, getPointeeType(), getAddrSpaceExpr()); |
| 3167 | } |
| 3168 | |
| 3169 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
| 3170 | QualType PointeeType, Expr *AddrSpaceExpr); |
| 3171 | }; |
| 3172 | |
| 3173 | |
| 3174 | |
| 3175 | |
| 3176 | |
| 3177 | |
| 3178 | |
| 3179 | |
| 3180 | |
| 3181 | |
| 3182 | |
| 3183 | class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode { |
| 3184 | friend class ASTContext; |
| 3185 | |
| 3186 | const ASTContext &Context; |
| 3187 | Expr *SizeExpr; |
| 3188 | |
| 3189 | |
| 3190 | QualType ElementType; |
| 3191 | |
| 3192 | SourceLocation loc; |
| 3193 | |
| 3194 | DependentSizedExtVectorType(const ASTContext &Context, QualType ElementType, |
| 3195 | QualType can, Expr *SizeExpr, SourceLocation loc); |
| 3196 | |
| 3197 | public: |
| 3198 | Expr *getSizeExpr() const { return SizeExpr; } |
| 3199 | QualType getElementType() const { return ElementType; } |
| 3200 | SourceLocation getAttributeLoc() const { return loc; } |
| 3201 | |
| 3202 | bool isSugared() const { return false; } |
| 3203 | QualType desugar() const { return QualType(this, 0); } |
| 3204 | |
| 3205 | static bool classof(const Type *T) { |
| 3206 | return T->getTypeClass() == DependentSizedExtVector; |
| 3207 | } |
| 3208 | |
| 3209 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 3210 | Profile(ID, Context, getElementType(), getSizeExpr()); |
| 3211 | } |
| 3212 | |
| 3213 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
| 3214 | QualType ElementType, Expr *SizeExpr); |
| 3215 | }; |
| 3216 | |
| 3217 | |
| 3218 | |
| 3219 | |
| 3220 | |
| 3221 | |
| 3222 | |
| 3223 | class VectorType : public Type, public llvm::FoldingSetNode { |
| 3224 | public: |
| 3225 | enum VectorKind { |
| 3226 | |
| 3227 | GenericVector, |
| 3228 | |
| 3229 | |
| 3230 | AltiVecVector, |
| 3231 | |
| 3232 | |
| 3233 | AltiVecPixel, |
| 3234 | |
| 3235 | |
| 3236 | AltiVecBool, |
| 3237 | |
| 3238 | |
| 3239 | NeonVector, |
| 3240 | |
| 3241 | |
| 3242 | NeonPolyVector, |
| 3243 | |
| 3244 | |
| 3245 | SveFixedLengthDataVector, |
| 3246 | |
| 3247 | |
| 3248 | SveFixedLengthPredicateVector |
| 3249 | }; |
| 3250 | |
| 3251 | protected: |
| 3252 | friend class ASTContext; |
| 3253 | |
| 3254 | |
| 3255 | QualType ElementType; |
| 3256 | |
| 3257 | VectorType(QualType vecType, unsigned nElements, QualType canonType, |
| 3258 | VectorKind vecKind); |
| 3259 | |
| 3260 | VectorType(TypeClass tc, QualType vecType, unsigned nElements, |
| 3261 | QualType canonType, VectorKind vecKind); |
| 3262 | |
| 3263 | public: |
| 3264 | QualType getElementType() const { return ElementType; } |
| 3265 | unsigned getNumElements() const { return VectorTypeBits.NumElements; } |
| 3266 | |
| 3267 | bool isSugared() const { return false; } |
| 3268 | QualType desugar() const { return QualType(this, 0); } |
| 3269 | |
| 3270 | VectorKind getVectorKind() const { |
| 3271 | return VectorKind(VectorTypeBits.VecKind); |
| 3272 | } |
| 3273 | |
| 3274 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 3275 | Profile(ID, getElementType(), getNumElements(), |
| 3276 | getTypeClass(), getVectorKind()); |
| 3277 | } |
| 3278 | |
| 3279 | static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, |
| 3280 | unsigned NumElements, TypeClass TypeClass, |
| 3281 | VectorKind VecKind) { |
| 3282 | ID.AddPointer(ElementType.getAsOpaquePtr()); |
| 3283 | ID.AddInteger(NumElements); |
| 3284 | ID.AddInteger(TypeClass); |
| 3285 | ID.AddInteger(VecKind); |
| 3286 | } |
| 3287 | |
| 3288 | static bool classof(const Type *T) { |
| 3289 | return T->getTypeClass() == Vector || T->getTypeClass() == ExtVector; |
| 3290 | } |
| 3291 | }; |
| 3292 | |
| 3293 | |
| 3294 | |
| 3295 | |
| 3296 | |
| 3297 | |
| 3298 | |
| 3299 | |
| 3300 | |
| 3301 | |
| 3302 | class DependentVectorType : public Type, public llvm::FoldingSetNode { |
| 3303 | friend class ASTContext; |
| 3304 | |
| 3305 | const ASTContext &Context; |
| 3306 | QualType ElementType; |
| 3307 | Expr *SizeExpr; |
| 3308 | SourceLocation Loc; |
| 3309 | |
| 3310 | DependentVectorType(const ASTContext &Context, QualType ElementType, |
| 3311 | QualType CanonType, Expr *SizeExpr, |
| 3312 | SourceLocation Loc, VectorType::VectorKind vecKind); |
| 3313 | |
| 3314 | public: |
| 3315 | Expr *getSizeExpr() const { return SizeExpr; } |
| 3316 | QualType getElementType() const { return ElementType; } |
| 3317 | SourceLocation getAttributeLoc() const { return Loc; } |
| 3318 | VectorType::VectorKind getVectorKind() const { |
| 3319 | return VectorType::VectorKind(VectorTypeBits.VecKind); |
| 3320 | } |
| 3321 | |
| 3322 | bool isSugared() const { return false; } |
| 3323 | QualType desugar() const { return QualType(this, 0); } |
| 3324 | |
| 3325 | static bool classof(const Type *T) { |
| 3326 | return T->getTypeClass() == DependentVector; |
| 3327 | } |
| 3328 | |
| 3329 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 3330 | Profile(ID, Context, getElementType(), getSizeExpr(), getVectorKind()); |
| 3331 | } |
| 3332 | |
| 3333 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
| 3334 | QualType ElementType, const Expr *SizeExpr, |
| 3335 | VectorType::VectorKind VecKind); |
| 3336 | }; |
| 3337 | |
| 3338 | |
| 3339 | |
| 3340 | |
| 3341 | |
| 3342 | |
| 3343 | |
| 3344 | class ExtVectorType : public VectorType { |
| 3345 | friend class ASTContext; |
| 3346 | |
| 3347 | ExtVectorType(QualType vecType, unsigned nElements, QualType canonType) |
| 3348 | : VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {} |
| 3349 | |
| 3350 | public: |
| 3351 | static int getPointAccessorIdx(char c) { |
| 3352 | switch (c) { |
| 3353 | default: return -1; |
| 3354 | case 'x': case 'r': return 0; |
| 3355 | case 'y': case 'g': return 1; |
| 3356 | case 'z': case 'b': return 2; |
| 3357 | case 'w': case 'a': return 3; |
| 3358 | } |
| 3359 | } |
| 3360 | |
| 3361 | static int getNumericAccessorIdx(char c) { |
| 3362 | switch (c) { |
| 3363 | default: return -1; |
| 3364 | case '0': return 0; |
| 3365 | case '1': return 1; |
| 3366 | case '2': return 2; |
| 3367 | case '3': return 3; |
| 3368 | case '4': return 4; |
| 3369 | case '5': return 5; |
| 3370 | case '6': return 6; |
| 3371 | case '7': return 7; |
| 3372 | case '8': return 8; |
| 3373 | case '9': return 9; |
| 3374 | case 'A': |
| 3375 | case 'a': return 10; |
| 3376 | case 'B': |
| 3377 | case 'b': return 11; |
| 3378 | case 'C': |
| 3379 | case 'c': return 12; |
| 3380 | case 'D': |
| 3381 | case 'd': return 13; |
| 3382 | case 'E': |
| 3383 | case 'e': return 14; |
| 3384 | case 'F': |
| 3385 | case 'f': return 15; |
| 3386 | } |
| 3387 | } |
| 3388 | |
| 3389 | static int getAccessorIdx(char c, bool isNumericAccessor) { |
| 3390 | if (isNumericAccessor) |
| 3391 | return getNumericAccessorIdx(c); |
| 3392 | else |
| 3393 | return getPointAccessorIdx(c); |
| 3394 | } |
| 3395 | |
| 3396 | bool isAccessorWithinNumElements(char c, bool isNumericAccessor) const { |
| 3397 | if (int idx = getAccessorIdx(c, isNumericAccessor)+1) |
| 3398 | return unsigned(idx-1) < getNumElements(); |
| 3399 | return false; |
| 3400 | } |
| 3401 | |
| 3402 | bool isSugared() const { return false; } |
| 3403 | QualType desugar() const { return QualType(this, 0); } |
| 3404 | |
| 3405 | static bool classof(const Type *T) { |
| 3406 | return T->getTypeClass() == ExtVector; |
| 3407 | } |
| 3408 | }; |
| 3409 | |
| 3410 | |
| 3411 | |
| 3412 | |
| 3413 | class MatrixType : public Type, public llvm::FoldingSetNode { |
| 3414 | protected: |
| 3415 | friend class ASTContext; |
| 3416 | |
| 3417 | |
| 3418 | QualType ElementType; |
| 3419 | |
| 3420 | MatrixType(QualType ElementTy, QualType CanonElementTy); |
| 3421 | |
| 3422 | MatrixType(TypeClass TypeClass, QualType ElementTy, QualType CanonElementTy, |
| 3423 | const Expr *RowExpr = nullptr, const Expr *ColumnExpr = nullptr); |
| 3424 | |
| 3425 | public: |
| 3426 | |
| 3427 | QualType getElementType() const { return ElementType; } |
| 3428 | |
| 3429 | |
| 3430 | |
| 3431 | |
| 3432 | |
| 3433 | |
| 3434 | static bool isValidElementType(QualType T) { |
| 3435 | return T->isDependentType() || |
| 3436 | (T->isRealType() && !T->isBooleanType() && !T->isEnumeralType()); |
| 3437 | } |
| 3438 | |
| 3439 | bool isSugared() const { return false; } |
| 3440 | QualType desugar() const { return QualType(this, 0); } |
| 3441 | |
| 3442 | static bool classof(const Type *T) { |
| 3443 | return T->getTypeClass() == ConstantMatrix || |
| 3444 | T->getTypeClass() == DependentSizedMatrix; |
| 3445 | } |
| 3446 | }; |
| 3447 | |
| 3448 | |
| 3449 | class ConstantMatrixType final : public MatrixType { |
| 3450 | protected: |
| 3451 | friend class ASTContext; |
| 3452 | |
| 3453 | |
| 3454 | |
| 3455 | QualType ElementType; |
| 3456 | |
| 3457 | |
| 3458 | unsigned NumRows; |
| 3459 | unsigned NumColumns; |
| 3460 | |
| 3461 | static constexpr unsigned MaxElementsPerDimension = (1 << 20) - 1; |
| 3462 | |
| 3463 | ConstantMatrixType(QualType MatrixElementType, unsigned NRows, |
| 3464 | unsigned NColumns, QualType CanonElementType); |
| 3465 | |
| 3466 | ConstantMatrixType(TypeClass typeClass, QualType MatrixType, unsigned NRows, |
| 3467 | unsigned NColumns, QualType CanonElementType); |
| 3468 | |
| 3469 | public: |
| 3470 | |
| 3471 | unsigned getNumRows() const { return NumRows; } |
| 3472 | |
| 3473 | |
| 3474 | unsigned getNumColumns() const { return NumColumns; } |
| 3475 | |
| 3476 | |
| 3477 | unsigned getNumElementsFlattened() const { |
| 3478 | return getNumRows() * getNumColumns(); |
| 3479 | } |
| 3480 | |
| 3481 | |
| 3482 | static constexpr bool isDimensionValid(size_t NumElements) { |
| 3483 | return NumElements > 0 && NumElements <= MaxElementsPerDimension; |
| 3484 | } |
| 3485 | |
| 3486 | |
| 3487 | static constexpr unsigned getMaxElementsPerDimension() { |
| 3488 | return MaxElementsPerDimension; |
| 3489 | } |
| 3490 | |
| 3491 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 3492 | Profile(ID, getElementType(), getNumRows(), getNumColumns(), |
| 3493 | getTypeClass()); |
| 3494 | } |
| 3495 | |
| 3496 | static void Profile(llvm::FoldingSetNodeID &ID, QualType ElementType, |
| 3497 | unsigned NumRows, unsigned NumColumns, |
| 3498 | TypeClass TypeClass) { |
| 3499 | ID.AddPointer(ElementType.getAsOpaquePtr()); |
| 3500 | ID.AddInteger(NumRows); |
| 3501 | ID.AddInteger(NumColumns); |
| 3502 | ID.AddInteger(TypeClass); |
| 3503 | } |
| 3504 | |
| 3505 | static bool classof(const Type *T) { |
| 3506 | return T->getTypeClass() == ConstantMatrix; |
| 3507 | } |
| 3508 | }; |
| 3509 | |
| 3510 | |
| 3511 | |
| 3512 | class DependentSizedMatrixType final : public MatrixType { |
| 3513 | friend class ASTContext; |
| 3514 | |
| 3515 | const ASTContext &Context; |
| 3516 | Expr *RowExpr; |
| 3517 | Expr *ColumnExpr; |
| 3518 | |
| 3519 | SourceLocation loc; |
| 3520 | |
| 3521 | DependentSizedMatrixType(const ASTContext &Context, QualType ElementType, |
| 3522 | QualType CanonicalType, Expr *RowExpr, |
| 3523 | Expr *ColumnExpr, SourceLocation loc); |
| 3524 | |
| 3525 | public: |
| 3526 | QualType getElementType() const { return ElementType; } |
| 3527 | Expr *getRowExpr() const { return RowExpr; } |
| 3528 | Expr *getColumnExpr() const { return ColumnExpr; } |
| 3529 | SourceLocation getAttributeLoc() const { return loc; } |
| 3530 | |
| 3531 | bool isSugared() const { return false; } |
| 3532 | QualType desugar() const { return QualType(this, 0); } |
| 3533 | |
| 3534 | static bool classof(const Type *T) { |
| 3535 | return T->getTypeClass() == DependentSizedMatrix; |
| 3536 | } |
| 3537 | |
| 3538 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 3539 | Profile(ID, Context, getElementType(), getRowExpr(), getColumnExpr()); |
| 3540 | } |
| 3541 | |
| 3542 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
| 3543 | QualType ElementType, Expr *RowExpr, Expr *ColumnExpr); |
| 3544 | }; |
| 3545 | |
| 3546 | |
| 3547 | |
| 3548 | class FunctionType : public Type { |
| 3549 | |
| 3550 | QualType ResultType; |
| 3551 | |
| 3552 | public: |
| 3553 | |
| 3554 | |
| 3555 | |
| 3556 | |
| 3557 | |
| 3558 | |
| 3559 | |
| 3560 | |
| 3561 | |
| 3562 | |
| 3563 | |
| 3564 | |
| 3565 | |
| 3566 | |
| 3567 | |
| 3568 | |
| 3569 | |
| 3570 | |
| 3571 | |
| 3572 | |
| 3573 | |
| 3574 | class ExtParameterInfo { |
| 3575 | enum { |
| 3576 | ABIMask = 0x0F, |
| 3577 | IsConsumed = 0x10, |
| 3578 | HasPassObjSize = 0x20, |
| 3579 | IsNoEscape = 0x40, |
| 3580 | }; |
| 3581 | unsigned char Data = 0; |
| 3582 | |
| 3583 | public: |
| 3584 | ExtParameterInfo() = default; |
| 3585 | |
| 3586 | |
| 3587 | ParameterABI getABI() const { return ParameterABI(Data & ABIMask); } |
| 3588 | ExtParameterInfo withABI(ParameterABI kind) const { |
| 3589 | ExtParameterInfo copy = *this; |
| 3590 | copy.Data = (copy.Data & ~ABIMask) | unsigned(kind); |
| 3591 | return copy; |
| 3592 | } |
| 3593 | |
| 3594 | |
| 3595 | |
| 3596 | bool isConsumed() const { return (Data & IsConsumed); } |
| 3597 | ExtParameterInfo withIsConsumed(bool consumed) const { |
| 3598 | ExtParameterInfo copy = *this; |
| 3599 | if (consumed) |
| 3600 | copy.Data |= IsConsumed; |
| 3601 | else |
| 3602 | copy.Data &= ~IsConsumed; |
| 3603 | return copy; |
| 3604 | } |
| 3605 | |
| 3606 | bool hasPassObjectSize() const { return Data & HasPassObjSize; } |
| 3607 | ExtParameterInfo withHasPassObjectSize() const { |
| 3608 | ExtParameterInfo Copy = *this; |
| 3609 | Copy.Data |= HasPassObjSize; |
| 3610 | return Copy; |
| 3611 | } |
| 3612 | |
| 3613 | bool isNoEscape() const { return Data & IsNoEscape; } |
| 3614 | ExtParameterInfo withIsNoEscape(bool NoEscape) const { |
| 3615 | ExtParameterInfo Copy = *this; |
| 3616 | if (NoEscape) |
| 3617 | Copy.Data |= IsNoEscape; |
| 3618 | else |
| 3619 | Copy.Data &= ~IsNoEscape; |
| 3620 | return Copy; |
| 3621 | } |
| 3622 | |
| 3623 | unsigned char getOpaqueValue() const { return Data; } |
| 3624 | static ExtParameterInfo getFromOpaqueValue(unsigned char data) { |
| 3625 | ExtParameterInfo result; |
| 3626 | result.Data = data; |
| 3627 | return result; |
| 3628 | } |
| 3629 | |
| 3630 | friend bool operator==(ExtParameterInfo lhs, ExtParameterInfo rhs) { |
| 3631 | return lhs.Data == rhs.Data; |
| 3632 | } |
| 3633 | |
| 3634 | friend bool operator!=(ExtParameterInfo lhs, ExtParameterInfo rhs) { |
| 3635 | return lhs.Data != rhs.Data; |
| 3636 | } |
| 3637 | }; |
| 3638 | |
| 3639 | |
| 3640 | |
| 3641 | |
| 3642 | |
| 3643 | |
| 3644 | |
| 3645 | |
| 3646 | |
| 3647 | |
| 3648 | |
| 3649 | |
| 3650 | |
| 3651 | |
| 3652 | |
| 3653 | |
| 3654 | |
| 3655 | |
| 3656 | |
| 3657 | |
| 3658 | |
| 3659 | class ExtInfo { |
| 3660 | friend class FunctionType; |
| 3661 | |
| 3662 | |
| 3663 | |
| 3664 | |
| 3665 | |
| 3666 | |
| 3667 | |
| 3668 | |
| 3669 | |
| 3670 | enum { CallConvMask = 0x1F }; |
| 3671 | enum { NoReturnMask = 0x20 }; |
| 3672 | enum { ProducesResultMask = 0x40 }; |
| 3673 | enum { NoCallerSavedRegsMask = 0x80 }; |
| 3674 | enum { |
| 3675 | RegParmMask = 0x700, |
| 3676 | RegParmOffset = 8 |
| 3677 | }; |
| 3678 | enum { NoCfCheckMask = 0x800 }; |
| 3679 | enum { CmseNSCallMask = 0x1000 }; |
| 3680 | uint16_t Bits = CC_C; |
| 3681 | |
| 3682 | ExtInfo(unsigned Bits) : Bits(static_cast<uint16_t>(Bits)) {} |
| 3683 | |
| 3684 | public: |
| 3685 | |
| 3686 | |
| 3687 | ExtInfo(bool noReturn, bool hasRegParm, unsigned regParm, CallingConv cc, |
| 3688 | bool producesResult, bool noCallerSavedRegs, bool NoCfCheck, |
| 3689 | bool cmseNSCall) { |
| 3690 | assert((!hasRegParm || regParm < 7) && "Invalid regparm value"); |
| 3691 | Bits = ((unsigned)cc) | (noReturn ? NoReturnMask : 0) | |
| 3692 | (producesResult ? ProducesResultMask : 0) | |
| 3693 | (noCallerSavedRegs ? NoCallerSavedRegsMask : 0) | |
| 3694 | (hasRegParm ? ((regParm + 1) << RegParmOffset) : 0) | |
| 3695 | (NoCfCheck ? NoCfCheckMask : 0) | |
| 3696 | (cmseNSCall ? CmseNSCallMask : 0); |
| 3697 | } |
| 3698 | |
| 3699 | |
| 3700 | |
| 3701 | ExtInfo() = default; |
| 3702 | |
| 3703 | |
| 3704 | |
| 3705 | ExtInfo(CallingConv CC) : Bits(CC) {} |
| 3706 | |
| 3707 | bool getNoReturn() const { return Bits & NoReturnMask; } |
| 3708 | bool getProducesResult() const { return Bits & ProducesResultMask; } |
| 3709 | bool getCmseNSCall() const { return Bits & CmseNSCallMask; } |
| 3710 | bool getNoCallerSavedRegs() const { return Bits & NoCallerSavedRegsMask; } |
| 3711 | bool getNoCfCheck() const { return Bits & NoCfCheckMask; } |
| 3712 | bool getHasRegParm() const { return ((Bits & RegParmMask) >> RegParmOffset) != 0; } |
| 3713 | |
| 3714 | unsigned getRegParm() const { |
| 3715 | unsigned RegParm = (Bits & RegParmMask) >> RegParmOffset; |
| 3716 | if (RegParm > 0) |
| 3717 | --RegParm; |
| 3718 | return RegParm; |
| 3719 | } |
| 3720 | |
| 3721 | CallingConv getCC() const { return CallingConv(Bits & CallConvMask); } |
| 3722 | |
| 3723 | bool operator==(ExtInfo Other) const { |
| 3724 | return Bits == Other.Bits; |
| 3725 | } |
| 3726 | bool operator!=(ExtInfo Other) const { |
| 3727 | return Bits != Other.Bits; |
| 3728 | } |
| 3729 | |
| 3730 | |
| 3731 | |
| 3732 | |
| 3733 | ExtInfo withNoReturn(bool noReturn) const { |
| 3734 | if (noReturn) |
| 3735 | return ExtInfo(Bits | NoReturnMask); |
| 3736 | else |
| 3737 | return ExtInfo(Bits & ~NoReturnMask); |
| 3738 | } |
| 3739 | |
| 3740 | ExtInfo withProducesResult(bool producesResult) const { |
| 3741 | if (producesResult) |
| 3742 | return ExtInfo(Bits | ProducesResultMask); |
| 3743 | else |
| 3744 | return ExtInfo(Bits & ~ProducesResultMask); |
| 3745 | } |
| 3746 | |
| 3747 | ExtInfo withCmseNSCall(bool cmseNSCall) const { |
| 3748 | if (cmseNSCall) |
| 3749 | return ExtInfo(Bits | CmseNSCallMask); |
| 3750 | else |
| 3751 | return ExtInfo(Bits & ~CmseNSCallMask); |
| 3752 | } |
| 3753 | |
| 3754 | ExtInfo withNoCallerSavedRegs(bool noCallerSavedRegs) const { |
| 3755 | if (noCallerSavedRegs) |
| 3756 | return ExtInfo(Bits | NoCallerSavedRegsMask); |
| 3757 | else |
| 3758 | return ExtInfo(Bits & ~NoCallerSavedRegsMask); |
| 3759 | } |
| 3760 | |
| 3761 | ExtInfo withNoCfCheck(bool noCfCheck) const { |
| 3762 | if (noCfCheck) |
| 3763 | return ExtInfo(Bits | NoCfCheckMask); |
| 3764 | else |
| 3765 | return ExtInfo(Bits & ~NoCfCheckMask); |
| 3766 | } |
| 3767 | |
| 3768 | ExtInfo withRegParm(unsigned RegParm) const { |
| 3769 | assert(RegParm < 7 && "Invalid regparm value"); |
| 3770 | return ExtInfo((Bits & ~RegParmMask) | |
| 3771 | ((RegParm + 1) << RegParmOffset)); |
| 3772 | } |
| 3773 | |
| 3774 | ExtInfo withCallingConv(CallingConv cc) const { |
| 3775 | return ExtInfo((Bits & ~CallConvMask) | (unsigned) cc); |
| 3776 | } |
| 3777 | |
| 3778 | void Profile(llvm::FoldingSetNodeID &ID) const { |
| 3779 | ID.AddInteger(Bits); |
| 3780 | } |
| 3781 | }; |
| 3782 | |
| 3783 | |
| 3784 | |
| 3785 | |
| 3786 | struct ExceptionType { QualType Type; }; |
| 3787 | |
| 3788 | |
| 3789 | |
| 3790 | |
| 3791 | |
| 3792 | struct alignas(void *) FunctionTypeExtraBitfields { |
| 3793 | |
| 3794 | |
| 3795 | |
| 3796 | unsigned NumExceptionType; |
| 3797 | }; |
| 3798 | |
| 3799 | protected: |
| 3800 | FunctionType(TypeClass tc, QualType res, QualType Canonical, |
| 3801 | TypeDependence Dependence, ExtInfo Info) |
| 3802 | : Type(tc, Canonical, Dependence), ResultType(res) { |
| 3803 | FunctionTypeBits.ExtInfo = Info.Bits; |
| 3804 | } |
| 3805 | |
| 3806 | Qualifiers getFastTypeQuals() const { |
| 3807 | return Qualifiers::fromFastMask(FunctionTypeBits.FastTypeQuals); |
| 3808 | } |
| 3809 | |
| 3810 | public: |
| 3811 | QualType getReturnType() const { return ResultType; } |
| 3812 | |
| 3813 | bool getHasRegParm() const { return getExtInfo().getHasRegParm(); } |
| 3814 | unsigned getRegParmType() const { return getExtInfo().getRegParm(); } |
| 3815 | |
| 3816 | |
| 3817 | |
| 3818 | |
| 3819 | bool getNoReturnAttr() const { return getExtInfo().getNoReturn(); } |
| 3820 | |
| 3821 | bool getCmseNSCallAttr() const { return getExtInfo().getCmseNSCall(); } |
| 3822 | CallingConv getCallConv() const { return getExtInfo().getCC(); } |
| 3823 | ExtInfo getExtInfo() const { return ExtInfo(FunctionTypeBits.ExtInfo); } |
| 3824 | |
| 3825 | static_assert((~Qualifiers::FastMask & Qualifiers::CVRMask) == 0, |
| 3826 | "Const, volatile and restrict are assumed to be a subset of " |
| 3827 | "the fast qualifiers."); |
| 3828 | |
| 3829 | bool isConst() const { return getFastTypeQuals().hasConst(); } |
| 3830 | bool isVolatile() const { return getFastTypeQuals().hasVolatile(); } |
| 3831 | bool isRestrict() const { return getFastTypeQuals().hasRestrict(); } |
| 3832 | |
| 3833 | |
| 3834 | |
| 3835 | QualType getCallResultType(const ASTContext &Context) const { |
| 3836 | return getReturnType().getNonLValueExprType(Context); |
| 3837 | } |
| 3838 | |
| 3839 | static StringRef getNameForCallConv(CallingConv CC); |
| 3840 | |
| 3841 | static bool classof(const Type *T) { |
| 3842 | return T->getTypeClass() == FunctionNoProto || |
| 3843 | T->getTypeClass() == FunctionProto; |
| 3844 | } |
| 3845 | }; |
| 3846 | |
| 3847 | |
| 3848 | |
| 3849 | class FunctionNoProtoType : public FunctionType, public llvm::FoldingSetNode { |
| 3850 | friend class ASTContext; |
| 3851 | |
| 3852 | FunctionNoProtoType(QualType Result, QualType Canonical, ExtInfo Info) |
| 3853 | : FunctionType(FunctionNoProto, Result, Canonical, |
| 3854 | Result->getDependence() & |
| 3855 | ~(TypeDependence::DependentInstantiation | |
| 3856 | TypeDependence::UnexpandedPack), |
| 3857 | Info) {} |
| 3858 | |
| 3859 | public: |
| 3860 | |
| 3861 | |
| 3862 | bool isSugared() const { return false; } |
| 3863 | QualType desugar() const { return QualType(this, 0); } |
| 3864 | |
| 3865 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 3866 | Profile(ID, getReturnType(), getExtInfo()); |
| 3867 | } |
| 3868 | |
| 3869 | static void Profile(llvm::FoldingSetNodeID &ID, QualType ResultType, |
| 3870 | ExtInfo Info) { |
| 3871 | Info.Profile(ID); |
| 3872 | ID.AddPointer(ResultType.getAsOpaquePtr()); |
| 3873 | } |
| 3874 | |
| 3875 | static bool classof(const Type *T) { |
| 3876 | return T->getTypeClass() == FunctionNoProto; |
| 3877 | } |
| 3878 | }; |
| 3879 | |
| 3880 | |
| 3881 | |
| 3882 | |
| 3883 | |
| 3884 | |
| 3885 | |
| 3886 | |
| 3887 | class FunctionProtoType final |
| 3888 | : public FunctionType, |
| 3889 | public llvm::FoldingSetNode, |
| 3890 | private llvm::TrailingObjects< |
| 3891 | FunctionProtoType, QualType, SourceLocation, |
| 3892 | FunctionType::FunctionTypeExtraBitfields, FunctionType::ExceptionType, |
| 3893 | Expr *, FunctionDecl *, FunctionType::ExtParameterInfo, Qualifiers> { |
| 3894 | friend class ASTContext; |
| 3895 | friend TrailingObjects; |
| 3896 | |
| 3897 | |
| 3898 | |
| 3899 | |
| 3900 | |
| 3901 | |
| 3902 | |
| 3903 | |
| 3904 | |
| 3905 | |
| 3906 | |
| 3907 | |
| 3908 | |
| 3909 | |
| 3910 | |
| 3911 | |
| 3912 | |
| 3913 | |
| 3914 | |
| 3915 | |
| 3916 | |
| 3917 | |
| 3918 | |
| 3919 | |
| 3920 | |
| 3921 | |
| 3922 | |
| 3923 | |
| 3924 | |
| 3925 | |
| 3926 | |
| 3927 | |
| 3928 | |
| 3929 | |
| 3930 | |
| 3931 | |
| 3932 | |
| 3933 | |
| 3934 | |
| 3935 | |
| 3936 | |
| 3937 | |
| 3938 | |
| 3939 | public: |
| 3940 | |
| 3941 | |
| 3942 | |
| 3943 | |
| 3944 | struct ExceptionSpecInfo { |
| 3945 | |
| 3946 | ExceptionSpecificationType Type = EST_None; |
| 3947 | |
| 3948 | |
| 3949 | ArrayRef<QualType> Exceptions; |
| 3950 | |
| 3951 | |
| 3952 | Expr *NoexceptExpr = nullptr; |
| 3953 | |
| 3954 | |
| 3955 | |
| 3956 | FunctionDecl *SourceDecl = nullptr; |
| 3957 | |
| 3958 | |
| 3959 | |
| 3960 | FunctionDecl *SourceTemplate = nullptr; |
| 3961 | |
| 3962 | ExceptionSpecInfo() = default; |
| 3963 | |
| 3964 | ExceptionSpecInfo(ExceptionSpecificationType EST) : Type(EST) {} |
| 3965 | }; |
| 3966 | |
| 3967 | |
| 3968 | |
| 3969 | |
| 3970 | struct ExtProtoInfo { |
| 3971 | FunctionType::ExtInfo ExtInfo; |
| 3972 | bool Variadic : 1; |
| 3973 | bool HasTrailingReturn : 1; |
| 3974 | Qualifiers TypeQuals; |
| 3975 | RefQualifierKind RefQualifier = RQ_None; |
| 3976 | ExceptionSpecInfo ExceptionSpec; |
| 3977 | const ExtParameterInfo *ExtParameterInfos = nullptr; |
| 3978 | SourceLocation EllipsisLoc; |
| 3979 | |
| 3980 | ExtProtoInfo() : Variadic(false), HasTrailingReturn(false) {} |
| 3981 | |
| 3982 | ExtProtoInfo(CallingConv CC) |
| 3983 | : ExtInfo(CC), Variadic(false), HasTrailingReturn(false) {} |
| 3984 | |
| 3985 | ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &ESI) { |
| 3986 | ExtProtoInfo Result(*this); |
| 3987 | Result.ExceptionSpec = ESI; |
| 3988 | return Result; |
| 3989 | } |
| 3990 | }; |
| 3991 | |
| 3992 | private: |
| 3993 | unsigned numTrailingObjects(OverloadToken<QualType>) const { |
| 3994 | return getNumParams(); |
| 3995 | } |
| 3996 | |
| 3997 | unsigned numTrailingObjects(OverloadToken<SourceLocation>) const { |
| 3998 | return isVariadic(); |
| 3999 | } |
| 4000 | |
| 4001 | unsigned numTrailingObjects(OverloadToken<FunctionTypeExtraBitfields>) const { |
| 4002 | return hasExtraBitfields(); |
| 4003 | } |
| 4004 | |
| 4005 | unsigned numTrailingObjects(OverloadToken<ExceptionType>) const { |
| 4006 | return getExceptionSpecSize().NumExceptionType; |
| 4007 | } |
| 4008 | |
| 4009 | unsigned numTrailingObjects(OverloadToken<Expr *>) const { |
| 4010 | return getExceptionSpecSize().NumExprPtr; |
| 4011 | } |
| 4012 | |
| 4013 | unsigned numTrailingObjects(OverloadToken<FunctionDecl *>) const { |
| 4014 | return getExceptionSpecSize().NumFunctionDeclPtr; |
| 4015 | } |
| 4016 | |
| 4017 | unsigned numTrailingObjects(OverloadToken<ExtParameterInfo>) const { |
| 4018 | return hasExtParameterInfos() ? getNumParams() : 0; |
| 4019 | } |
| 4020 | |
| 4021 | |
| 4022 | |
| 4023 | static bool containsAnyUnexpandedParameterPack(const QualType *ArgArray, |
| 4024 | unsigned numArgs) { |
| 4025 | for (unsigned Idx = 0; Idx < numArgs; ++Idx) |
| 4026 | if (ArgArray[Idx]->containsUnexpandedParameterPack()) |
| 4027 | return true; |
| 4028 | |
| 4029 | return false; |
| 4030 | } |
| 4031 | |
| 4032 | FunctionProtoType(QualType result, ArrayRef<QualType> params, |
| 4033 | QualType canonical, const ExtProtoInfo &epi); |
| 4034 | |
| 4035 | |
| 4036 | |
| 4037 | |
| 4038 | struct ExceptionSpecSizeHolder { |
| 4039 | unsigned NumExceptionType; |
| 4040 | unsigned NumExprPtr; |
| 4041 | unsigned NumFunctionDeclPtr; |
| 4042 | }; |
| 4043 | |
| 4044 | |
| 4045 | |
| 4046 | static ExceptionSpecSizeHolder |
| 4047 | getExceptionSpecSize(ExceptionSpecificationType EST, unsigned NumExceptions) { |
| 4048 | switch (EST) { |
| 4049 | case EST_None: |
| 4050 | case EST_DynamicNone: |
| 4051 | case EST_MSAny: |
| 4052 | case EST_BasicNoexcept: |
| 4053 | case EST_Unparsed: |
| 4054 | case EST_NoThrow: |
| 4055 | return {0, 0, 0}; |
| 4056 | |
| 4057 | case EST_Dynamic: |
| 4058 | return {NumExceptions, 0, 0}; |
| 4059 | |
| 4060 | case EST_DependentNoexcept: |
| 4061 | case EST_NoexceptFalse: |
| 4062 | case EST_NoexceptTrue: |
| 4063 | return {0, 1, 0}; |
| 4064 | |
| 4065 | case EST_Uninstantiated: |
| 4066 | return {0, 0, 2}; |
| 4067 | |
| 4068 | case EST_Unevaluated: |
| 4069 | return {0, 0, 1}; |
| 4070 | } |
| 4071 | llvm_unreachable("bad exception specification kind"); |
| 4072 | } |
| 4073 | |
| 4074 | |
| 4075 | |
| 4076 | ExceptionSpecSizeHolder getExceptionSpecSize() const { |
| 4077 | return getExceptionSpecSize(getExceptionSpecType(), getNumExceptions()); |
| 4078 | } |
| 4079 | |
| 4080 | |
| 4081 | static bool hasExtraBitfields(ExceptionSpecificationType EST) { |
| 4082 | |
| 4083 | |
| 4084 | return EST == EST_Dynamic; |
| 4085 | } |
| 4086 | |
| 4087 | |
| 4088 | bool hasExtraBitfields() const { |
| 4089 | return hasExtraBitfields(getExceptionSpecType()); |
| 4090 | } |
| 4091 | |
| 4092 | bool hasExtQualifiers() const { |
| 4093 | return FunctionTypeBits.HasExtQuals; |
| 4094 | } |
| 4095 | |
| 4096 | public: |
| 4097 | unsigned getNumParams() const { return FunctionTypeBits.NumParams; } |
| 4098 | |
| 4099 | QualType getParamType(unsigned i) const { |
| 4100 | assert(i < getNumParams() && "invalid parameter index"); |
| 4101 | return param_type_begin()[i]; |
| 4102 | } |
| 4103 | |
| 4104 | ArrayRef<QualType> getParamTypes() const { |
| 4105 | return llvm::makeArrayRef(param_type_begin(), param_type_end()); |
| 4106 | } |
| 4107 | |
| 4108 | ExtProtoInfo getExtProtoInfo() const { |
| 4109 | ExtProtoInfo EPI; |
| 4110 | EPI.ExtInfo = getExtInfo(); |
| 4111 | EPI.Variadic = isVariadic(); |
| 4112 | EPI.EllipsisLoc = getEllipsisLoc(); |
| 4113 | EPI.HasTrailingReturn = hasTrailingReturn(); |
| 4114 | EPI.ExceptionSpec = getExceptionSpecInfo(); |
| 4115 | EPI.TypeQuals = getMethodQuals(); |
| 4116 | EPI.RefQualifier = getRefQualifier(); |
| 4117 | EPI.ExtParameterInfos = getExtParameterInfosOrNull(); |
| 4118 | return EPI; |
| 4119 | } |
| 4120 | |
| 4121 | |
| 4122 | ExceptionSpecificationType getExceptionSpecType() const { |
| 4123 | return static_cast<ExceptionSpecificationType>( |
| 4124 | FunctionTypeBits.ExceptionSpecType); |
| 4125 | } |
| 4126 | |
| 4127 | |
| 4128 | bool hasExceptionSpec() const { return getExceptionSpecType() != EST_None; } |
| 4129 | |
| 4130 | |
| 4131 | bool hasDynamicExceptionSpec() const { |
| 4132 | return isDynamicExceptionSpec(getExceptionSpecType()); |
| 4133 | } |
| 4134 | |
| 4135 | |
| 4136 | bool hasNoexceptExceptionSpec() const { |
| 4137 | return isNoexceptExceptionSpec(getExceptionSpecType()); |
| 4138 | } |
| 4139 | |
| 4140 | |
| 4141 | bool hasDependentExceptionSpec() const; |
| 4142 | |
| 4143 | |
| 4144 | |
| 4145 | bool hasInstantiationDependentExceptionSpec() const; |
| 4146 | |
| 4147 | |
| 4148 | ExceptionSpecInfo getExceptionSpecInfo() const { |
| 4149 | ExceptionSpecInfo Result; |
| 4150 | Result.Type = getExceptionSpecType(); |
| 4151 | if (Result.Type == EST_Dynamic) { |
| 4152 | Result.Exceptions = exceptions(); |
| 4153 | } else if (isComputedNoexcept(Result.Type)) { |
| 4154 | Result.NoexceptExpr = getNoexceptExpr(); |
| 4155 | } else if (Result.Type == EST_Uninstantiated) { |
| 4156 | Result.SourceDecl = getExceptionSpecDecl(); |
| 4157 | Result.SourceTemplate = getExceptionSpecTemplate(); |
| 4158 | } else if (Result.Type == EST_Unevaluated) { |
| 4159 | Result.SourceDecl = getExceptionSpecDecl(); |
| 4160 | } |
| 4161 | return Result; |
| 4162 | } |
| 4163 | |
| 4164 | |
| 4165 | unsigned getNumExceptions() const { |
| 4166 | return getExceptionSpecType() == EST_Dynamic |
| 4167 | ? getTrailingObjects<FunctionTypeExtraBitfields>() |
| 4168 | ->NumExceptionType |
| 4169 | : 0; |
| 4170 | } |
| 4171 | |
| 4172 | |
| 4173 | QualType getExceptionType(unsigned i) const { |
| 4174 | assert(i < getNumExceptions() && "Invalid exception number!"); |
| 4175 | return exception_begin()[i]; |
| 4176 | } |
| 4177 | |
| 4178 | |
| 4179 | |
| 4180 | Expr *getNoexceptExpr() const { |
| 4181 | if (!isComputedNoexcept(getExceptionSpecType())) |
| 4182 | return nullptr; |
| 4183 | return *getTrailingObjects<Expr *>(); |
| 4184 | } |
| 4185 | |
| 4186 | |
| 4187 | |
| 4188 | |
| 4189 | |
| 4190 | FunctionDecl *getExceptionSpecDecl() const { |
| 4191 | if (getExceptionSpecType() != EST_Uninstantiated && |
| 4192 | getExceptionSpecType() != EST_Unevaluated) |
| 4193 | return nullptr; |
| 4194 | return getTrailingObjects<FunctionDecl *>()[0]; |
| 4195 | } |
| 4196 | |
| 4197 | |
| 4198 | |
| 4199 | |
| 4200 | |
| 4201 | FunctionDecl *getExceptionSpecTemplate() const { |
| 4202 | if (getExceptionSpecType() != EST_Uninstantiated) |
| 4203 | return nullptr; |
| 4204 | return getTrailingObjects<FunctionDecl *>()[1]; |
| 4205 | } |
| 4206 | |
| 4207 | |
| 4208 | |
| 4209 | CanThrowResult canThrow() const; |
| 4210 | |
| 4211 | |
| 4212 | |
| 4213 | |
| 4214 | bool isNothrow(bool ResultIfDependent = false) const { |
| 4215 | return ResultIfDependent ? canThrow() != CT_Can : canThrow() == CT_Cannot; |
| 4216 | } |
| 4217 | |
| 4218 | |
| 4219 | bool isVariadic() const { return FunctionTypeBits.Variadic; } |
| 4220 | |
| 4221 | SourceLocation getEllipsisLoc() const { |
| 4222 | return isVariadic() ? *getTrailingObjects<SourceLocation>() |
| 4223 | : SourceLocation(); |
| 4224 | } |
| 4225 | |
| 4226 | |
| 4227 | |
| 4228 | |
| 4229 | |
| 4230 | |
| 4231 | |
| 4232 | bool isTemplateVariadic() const; |
| 4233 | |
| 4234 | |
| 4235 | bool hasTrailingReturn() const { return FunctionTypeBits.HasTrailingReturn; } |
| 4236 | |
| 4237 | Qualifiers getMethodQuals() const { |
| 4238 | if (hasExtQualifiers()) |
| 4239 | return *getTrailingObjects<Qualifiers>(); |
| 4240 | else |
| 4241 | return getFastTypeQuals(); |
| 4242 | } |
| 4243 | |
| 4244 | |
| 4245 | RefQualifierKind getRefQualifier() const { |
| 4246 | return static_cast<RefQualifierKind>(FunctionTypeBits.RefQualifier); |
| 4247 | } |
| 4248 | |
| 4249 | using param_type_iterator = const QualType *; |
| 4250 | using param_type_range = llvm::iterator_range<param_type_iterator>; |
| 4251 | |
| 4252 | param_type_range param_types() const { |
| 4253 | return param_type_range(param_type_begin(), param_type_end()); |
| 4254 | } |
| 4255 | |
| 4256 | param_type_iterator param_type_begin() const { |
| 4257 | return getTrailingObjects<QualType>(); |
| 4258 | } |
| 4259 | |
| 4260 | param_type_iterator param_type_end() const { |
| 4261 | return param_type_begin() + getNumParams(); |
| 4262 | } |
| 4263 | |
| 4264 | using exception_iterator = const QualType *; |
| 4265 | |
| 4266 | ArrayRef<QualType> exceptions() const { |
| 4267 | return llvm::makeArrayRef(exception_begin(), exception_end()); |
| 4268 | } |
| 4269 | |
| 4270 | exception_iterator exception_begin() const { |
| 4271 | return reinterpret_cast<exception_iterator>( |
| 4272 | getTrailingObjects<ExceptionType>()); |
| 4273 | } |
| 4274 | |
| 4275 | exception_iterator exception_end() const { |
| 4276 | return exception_begin() + getNumExceptions(); |
| 4277 | } |
| 4278 | |
| 4279 | |
| 4280 | |
| 4281 | bool hasExtParameterInfos() const { |
| 4282 | return FunctionTypeBits.HasExtParameterInfos; |
| 4283 | } |
| 4284 | |
| 4285 | ArrayRef<ExtParameterInfo> getExtParameterInfos() const { |
| 4286 | assert(hasExtParameterInfos()); |
| 4287 | return ArrayRef<ExtParameterInfo>(getTrailingObjects<ExtParameterInfo>(), |
| 4288 | getNumParams()); |
| 4289 | } |
| 4290 | |
| 4291 | |
| 4292 | |
| 4293 | |
| 4294 | const ExtParameterInfo *getExtParameterInfosOrNull() const { |
| 4295 | if (!hasExtParameterInfos()) |
| 4296 | return nullptr; |
| 4297 | return getTrailingObjects<ExtParameterInfo>(); |
| 4298 | } |
| 4299 | |
| 4300 | ExtParameterInfo getExtParameterInfo(unsigned I) const { |
| 4301 | assert(I < getNumParams() && "parameter index out of range"); |
| 4302 | if (hasExtParameterInfos()) |
| 4303 | return getTrailingObjects<ExtParameterInfo>()[I]; |
| 4304 | return ExtParameterInfo(); |
| 4305 | } |
| 4306 | |
| 4307 | ParameterABI getParameterABI(unsigned I) const { |
| 4308 | assert(I < getNumParams() && "parameter index out of range"); |
| 4309 | if (hasExtParameterInfos()) |
| 4310 | return getTrailingObjects<ExtParameterInfo>()[I].getABI(); |
| 4311 | return ParameterABI::Ordinary; |
| 4312 | } |
| 4313 | |
| 4314 | bool isParamConsumed(unsigned I) const { |
| 4315 | assert(I < getNumParams() && "parameter index out of range"); |
| 4316 | if (hasExtParameterInfos()) |
| 4317 | return getTrailingObjects<ExtParameterInfo>()[I].isConsumed(); |
| 4318 | return false; |
| 4319 | } |
| 4320 | |
| 4321 | bool isSugared() const { return false; } |
| 4322 | QualType desugar() const { return QualType(this, 0); } |
| 4323 | |
| 4324 | void printExceptionSpecification(raw_ostream &OS, |
| 4325 | const PrintingPolicy &Policy) const; |
| 4326 | |
| 4327 | static bool classof(const Type *T) { |
| 4328 | return T->getTypeClass() == FunctionProto; |
| 4329 | } |
| 4330 | |
| 4331 | void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx); |
| 4332 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Result, |
| 4333 | param_type_iterator ArgTys, unsigned NumArgs, |
| 4334 | const ExtProtoInfo &EPI, const ASTContext &Context, |
| 4335 | bool Canonical); |
| 4336 | }; |
| 4337 | |
| 4338 | |
| 4339 | |
| 4340 | |
| 4341 | |
| 4342 | |
| 4343 | class UnresolvedUsingType : public Type { |
| 4344 | friend class ASTContext; |
| 4345 | |
| 4346 | UnresolvedUsingTypenameDecl *Decl; |
| 4347 | |
| 4348 | UnresolvedUsingType(const UnresolvedUsingTypenameDecl *D) |
| 4349 | : Type(UnresolvedUsing, QualType(), |
| 4350 | TypeDependence::DependentInstantiation), |
| 4351 | Decl(const_cast<UnresolvedUsingTypenameDecl *>(D)) {} |
| 4352 | |
| 4353 | public: |
| 4354 | UnresolvedUsingTypenameDecl *getDecl() const { return Decl; } |
| 4355 | |
| 4356 | bool isSugared() const { return false; } |
| 4357 | QualType desugar() const { return QualType(this, 0); } |
| 4358 | |
| 4359 | static bool classof(const Type *T) { |
| 4360 | return T->getTypeClass() == UnresolvedUsing; |
| 4361 | } |
| 4362 | |
| 4363 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 4364 | return Profile(ID, Decl); |
| 4365 | } |
| 4366 | |
| 4367 | static void Profile(llvm::FoldingSetNodeID &ID, |
| 4368 | UnresolvedUsingTypenameDecl *D) { |
| 4369 | ID.AddPointer(D); |
| 4370 | } |
| 4371 | }; |
| 4372 | |
| 4373 | class TypedefType : public Type { |
| 4374 | TypedefNameDecl *Decl; |
| 4375 | |
| 4376 | private: |
| 4377 | friend class ASTContext; |
| 4378 | |
| 4379 | TypedefType(TypeClass tc, const TypedefNameDecl *D, QualType underlying, |
| 4380 | QualType can); |
| 4381 | |
| 4382 | public: |
| 4383 | TypedefNameDecl *getDecl() const { return Decl; } |
| 4384 | |
| 4385 | bool isSugared() const { return true; } |
| 4386 | QualType desugar() const; |
| 4387 | |
| 4388 | static bool classof(const Type *T) { return T->getTypeClass() == Typedef; } |
| 4389 | }; |
| 4390 | |
| 4391 | |
| 4392 | |
| 4393 | class MacroQualifiedType : public Type { |
| 4394 | friend class ASTContext; |
| 4395 | |
| 4396 | QualType UnderlyingTy; |
| 4397 | const IdentifierInfo *MacroII; |
| 4398 | |
| 4399 | MacroQualifiedType(QualType UnderlyingTy, QualType CanonTy, |
| 4400 | const IdentifierInfo *MacroII) |
| 4401 | : Type(MacroQualified, CanonTy, UnderlyingTy->getDependence()), |
| 4402 | UnderlyingTy(UnderlyingTy), MacroII(MacroII) { |
| 4403 | assert(isa<AttributedType>(UnderlyingTy) && |
| 4404 | "Expected a macro qualified type to only wrap attributed types."); |
| 4405 | } |
| 4406 | |
| 4407 | public: |
| 4408 | const IdentifierInfo *getMacroIdentifier() const { return MacroII; } |
| 4409 | QualType getUnderlyingType() const { return UnderlyingTy; } |
| 4410 | |
| 4411 | |
| 4412 | |
| 4413 | QualType getModifiedType() const; |
| 4414 | |
| 4415 | bool isSugared() const { return true; } |
| 4416 | QualType desugar() const; |
| 4417 | |
| 4418 | static bool classof(const Type *T) { |
| 4419 | return T->getTypeClass() == MacroQualified; |
| 4420 | } |
| 4421 | }; |
| 4422 | |
| 4423 | |
| 4424 | class TypeOfExprType : public Type { |
| 4425 | Expr *TOExpr; |
| 4426 | |
| 4427 | protected: |
| 4428 | friend class ASTContext; |
| 4429 | |
| 4430 | TypeOfExprType(Expr *E, QualType can = QualType()); |
| 4431 | |
| 4432 | public: |
| 4433 | Expr *getUnderlyingExpr() const { return TOExpr; } |
| 4434 | |
| 4435 | |
| 4436 | QualType desugar() const; |
| 4437 | |
| 4438 | |
| 4439 | bool isSugared() const; |
| 4440 | |
| 4441 | static bool classof(const Type *T) { return T->getTypeClass() == TypeOfExpr; } |
| 4442 | }; |
| 4443 | |
| 4444 | |
| 4445 | |
| 4446 | |
| 4447 | |
| 4448 | |
| 4449 | |
| 4450 | class DependentTypeOfExprType |
| 4451 | : public TypeOfExprType, public llvm::FoldingSetNode { |
| 4452 | const ASTContext &Context; |
| 4453 | |
| 4454 | public: |
| 4455 | DependentTypeOfExprType(const ASTContext &Context, Expr *E) |
| 4456 | : TypeOfExprType(E), Context(Context) {} |
| 4457 | |
| 4458 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 4459 | Profile(ID, Context, getUnderlyingExpr()); |
| 4460 | } |
| 4461 | |
| 4462 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
| 4463 | Expr *E); |
| 4464 | }; |
| 4465 | |
| 4466 | |
| 4467 | class TypeOfType : public Type { |
| 4468 | friend class ASTContext; |
| 4469 | |
| 4470 | QualType TOType; |
| 4471 | |
| 4472 | TypeOfType(QualType T, QualType can) |
| 4473 | : Type(TypeOf, can, T->getDependence()), TOType(T) { |
| 4474 | assert(!isa<TypedefType>(can) && "Invalid canonical type"); |
| 4475 | } |
| 4476 | |
| 4477 | public: |
| 4478 | QualType getUnderlyingType() const { return TOType; } |
| 4479 | |
| 4480 | |
| 4481 | QualType desugar() const { return getUnderlyingType(); } |
| 4482 | |
| 4483 | |
| 4484 | bool isSugared() const { return true; } |
| 4485 | |
| 4486 | static bool classof(const Type *T) { return T->getTypeClass() == TypeOf; } |
| 4487 | }; |
| 4488 | |
| 4489 | |
| 4490 | class DecltypeType : public Type { |
| 4491 | Expr *E; |
| 4492 | QualType UnderlyingType; |
| 4493 | |
| 4494 | protected: |
| 4495 | friend class ASTContext; |
| 4496 | |
| 4497 | DecltypeType(Expr *E, QualType underlyingType, QualType can = QualType()); |
| 4498 | |
| 4499 | public: |
| 4500 | Expr *getUnderlyingExpr() const { return E; } |
| 4501 | QualType getUnderlyingType() const { return UnderlyingType; } |
| 4502 | |
| 4503 | |
| 4504 | QualType desugar() const; |
| 4505 | |
| 4506 | |
| 4507 | bool isSugared() const; |
| 4508 | |
| 4509 | static bool classof(const Type *T) { return T->getTypeClass() == Decltype; } |
| 4510 | }; |
| 4511 | |
| 4512 | |
| 4513 | |
| 4514 | |
| 4515 | |
| 4516 | |
| 4517 | |
| 4518 | class DependentDecltypeType : public DecltypeType, public llvm::FoldingSetNode { |
| 4519 | const ASTContext &Context; |
| 4520 | |
| 4521 | public: |
| 4522 | DependentDecltypeType(const ASTContext &Context, Expr *E); |
| 4523 | |
| 4524 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 4525 | Profile(ID, Context, getUnderlyingExpr()); |
| 4526 | } |
| 4527 | |
| 4528 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
| 4529 | Expr *E); |
| 4530 | }; |
| 4531 | |
| 4532 | |
| 4533 | class UnaryTransformType : public Type { |
| 4534 | public: |
| 4535 | enum UTTKind { |
| 4536 | EnumUnderlyingType |
| 4537 | }; |
| 4538 | |
| 4539 | private: |
| 4540 | |
| 4541 | QualType BaseType; |
| 4542 | |
| 4543 | |
| 4544 | QualType UnderlyingType; |
| 4545 | |
| 4546 | UTTKind UKind; |
| 4547 | |
| 4548 | protected: |
| 4549 | friend class ASTContext; |
| 4550 | |
| 4551 | UnaryTransformType(QualType BaseTy, QualType UnderlyingTy, UTTKind UKind, |
| 4552 | QualType CanonicalTy); |
| 4553 | |
| 4554 | public: |
| 4555 | bool isSugared() const { return !isDependentType(); } |
| 4556 | QualType desugar() const { return UnderlyingType; } |
| 4557 | |
| 4558 | QualType getUnderlyingType() const { return UnderlyingType; } |
| 4559 | QualType getBaseType() const { return BaseType; } |
| 4560 | |
| 4561 | UTTKind getUTTKind() const { return UKind; } |
| 4562 | |
| 4563 | static bool classof(const Type *T) { |
| 4564 | return T->getTypeClass() == UnaryTransform; |
| 4565 | } |
| 4566 | }; |
| 4567 | |
| 4568 | |
| 4569 | |
| 4570 | |
| 4571 | |
| 4572 | |
| 4573 | |
| 4574 | class DependentUnaryTransformType : public UnaryTransformType, |
| 4575 | public llvm::FoldingSetNode { |
| 4576 | public: |
| 4577 | DependentUnaryTransformType(const ASTContext &C, QualType BaseType, |
| 4578 | UTTKind UKind); |
| 4579 | |
| 4580 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 4581 | Profile(ID, getBaseType(), getUTTKind()); |
| 4582 | } |
| 4583 | |
| 4584 | static void Profile(llvm::FoldingSetNodeID &ID, QualType BaseType, |
| 4585 | UTTKind UKind) { |
| 4586 | ID.AddPointer(BaseType.getAsOpaquePtr()); |
| 4587 | ID.AddInteger((unsigned)UKind); |
| 4588 | } |
| 4589 | }; |
| 4590 | |
| 4591 | class TagType : public Type { |
| 4592 | friend class ASTReader; |
| 4593 | template <class T> friend class serialization::AbstractTypeReader; |
| 4594 | |
| 4595 | |
| 4596 | |
| 4597 | TagDecl *decl; |
| 4598 | |
| 4599 | protected: |
| 4600 | TagType(TypeClass TC, const TagDecl *D, QualType can); |
| 4601 | |
| 4602 | public: |
| 4603 | TagDecl *getDecl() const; |
| 4604 | |
| 4605 | |
| 4606 | bool isBeingDefined() const; |
| 4607 | |
| 4608 | static bool classof(const Type *T) { |
| 4609 | return T->getTypeClass() == Enum || T->getTypeClass() == Record; |
| 4610 | } |
| 4611 | }; |
| 4612 | |
| 4613 | |
| 4614 | |
| 4615 | class RecordType : public TagType { |
| 4616 | protected: |
| 4617 | friend class ASTContext; |
| 4618 | |
| 4619 | explicit RecordType(const RecordDecl *D) |
| 4620 | : TagType(Record, reinterpret_cast<const TagDecl*>(D), QualType()) {} |
| 4621 | explicit RecordType(TypeClass TC, RecordDecl *D) |
| 4622 | : TagType(TC, reinterpret_cast<const TagDecl*>(D), QualType()) {} |
| 4623 | |
| 4624 | public: |
| 4625 | RecordDecl *getDecl() const { |
| 4626 | return reinterpret_cast<RecordDecl*>(TagType::getDecl()); |
| 4627 | } |
| 4628 | |
| 4629 | |
| 4630 | |
| 4631 | bool hasConstFields() const; |
| 4632 | |
| 4633 | bool isSugared() const { return false; } |
| 4634 | QualType desugar() const { return QualType(this, 0); } |
| 4635 | |
| 4636 | static bool classof(const Type *T) { return T->getTypeClass() == Record; } |
| 4637 | }; |
| 4638 | |
| 4639 | |
| 4640 | |
| 4641 | class EnumType : public TagType { |
| 4642 | friend class ASTContext; |
| 4643 | |
| 4644 | explicit EnumType(const EnumDecl *D) |
| 4645 | : TagType(Enum, reinterpret_cast<const TagDecl*>(D), QualType()) {} |
| 4646 | |
| 4647 | public: |
| 4648 | EnumDecl *getDecl() const { |
| 4649 | return reinterpret_cast<EnumDecl*>(TagType::getDecl()); |
| 4650 | } |
| 4651 | |
| 4652 | bool isSugared() const { return false; } |
| 4653 | QualType desugar() const { return QualType(this, 0); } |
| 4654 | |
| 4655 | static bool classof(const Type *T) { return T->getTypeClass() == Enum; } |
| 4656 | }; |
| 4657 | |
| 4658 | |
| 4659 | |
| 4660 | |
| 4661 | |
| 4662 | |
| 4663 | |
| 4664 | |
| 4665 | |
| 4666 | |
| 4667 | |
| 4668 | |
| 4669 | |
| 4670 | class AttributedType : public Type, public llvm::FoldingSetNode { |
| 4671 | public: |
| 4672 | using Kind = attr::Kind; |
| 4673 | |
| 4674 | private: |
| 4675 | friend class ASTContext; |
| 4676 | |
| 4677 | QualType ModifiedType; |
| 4678 | QualType EquivalentType; |
| 4679 | |
| 4680 | AttributedType(QualType canon, attr::Kind attrKind, QualType modified, |
| 4681 | QualType equivalent) |
| 4682 | : Type(Attributed, canon, equivalent->getDependence()), |
| 4683 | ModifiedType(modified), EquivalentType(equivalent) { |
| 4684 | AttributedTypeBits.AttrKind = attrKind; |
| 4685 | } |
| 4686 | |
| 4687 | public: |
| 4688 | Kind getAttrKind() const { |
| 4689 | return static_cast<Kind>(AttributedTypeBits.AttrKind); |
| 4690 | } |
| 4691 | |
| 4692 | QualType getModifiedType() const { return ModifiedType; } |
| 4693 | QualType getEquivalentType() const { return EquivalentType; } |
| 4694 | |
| 4695 | bool isSugared() const { return true; } |
| 4696 | QualType desugar() const { return getEquivalentType(); } |
| 4697 | |
| 4698 | |
| 4699 | |
| 4700 | |
| 4701 | |
| 4702 | |
| 4703 | |
| 4704 | |
| 4705 | |
| 4706 | |
| 4707 | |
| 4708 | |
| 4709 | |
| 4710 | |
| 4711 | |
| 4712 | |
| 4713 | bool isQualifier() const; |
| 4714 | |
| 4715 | bool isMSTypeSpec() const; |
| 4716 | |
| 4717 | bool isCallingConv() const; |
| 4718 | |
| 4719 | llvm::Optional<NullabilityKind> getImmediateNullability() const; |
| 4720 | |
| 4721 | |
| 4722 | |
| 4723 | static Kind getNullabilityAttrKind(NullabilityKind kind) { |
| 4724 | switch (kind) { |
| 4725 | case NullabilityKind::NonNull: |
| 4726 | return attr::TypeNonNull; |
| 4727 | |
| 4728 | case NullabilityKind::Nullable: |
| 4729 | return attr::TypeNullable; |
| 4730 | |
| 4731 | case NullabilityKind::NullableResult: |
| 4732 | return attr::TypeNullableResult; |
| 4733 | |
| 4734 | case NullabilityKind::Unspecified: |
| 4735 | return attr::TypeNullUnspecified; |
| 4736 | } |
| 4737 | llvm_unreachable("Unknown nullability kind."); |
| 4738 | } |
| 4739 | |
| 4740 | |
| 4741 | |
| 4742 | |
| 4743 | |
| 4744 | |
| 4745 | |
| 4746 | |
| 4747 | |
| 4748 | |
| 4749 | static Optional<NullabilityKind> stripOuterNullability(QualType &T); |
| 4750 | |
| 4751 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 4752 | Profile(ID, getAttrKind(), ModifiedType, EquivalentType); |
| 4753 | } |
| 4754 | |
| 4755 | static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind, |
| 4756 | QualType modified, QualType equivalent) { |
| 4757 | ID.AddInteger(attrKind); |
| 4758 | ID.AddPointer(modified.getAsOpaquePtr()); |
| 4759 | ID.AddPointer(equivalent.getAsOpaquePtr()); |
| 4760 | } |
| 4761 | |
| 4762 | static bool classof(const Type *T) { |
| 4763 | return T->getTypeClass() == Attributed; |
| 4764 | } |
| 4765 | }; |
| 4766 | |
| 4767 | class TemplateTypeParmType : public Type, public llvm::FoldingSetNode { |
| 4768 | friend class ASTContext; |
| 4769 | |
| 4770 | |
| 4771 | struct CanonicalTTPTInfo { |
| 4772 | unsigned Depth : 15; |
| 4773 | unsigned ParameterPack : 1; |
| 4774 | unsigned Index : 16; |
| 4775 | }; |
| 4776 | |
| 4777 | union { |
| 4778 | |
| 4779 | CanonicalTTPTInfo CanTTPTInfo; |
| 4780 | |
| 4781 | |
| 4782 | TemplateTypeParmDecl *TTPDecl; |
| 4783 | }; |
| 4784 | |
| 4785 | |
| 4786 | TemplateTypeParmType(TemplateTypeParmDecl *TTPDecl, QualType Canon) |
| 4787 | : Type(TemplateTypeParm, Canon, |
| 4788 | TypeDependence::DependentInstantiation | |
| 4789 | (Canon->getDependence() & TypeDependence::UnexpandedPack)), |
| 4790 | TTPDecl(TTPDecl) {} |
| 4791 | |
| 4792 | |
| 4793 | TemplateTypeParmType(unsigned D, unsigned I, bool PP) |
| 4794 | : Type(TemplateTypeParm, QualType(this, 0), |
| 4795 | TypeDependence::DependentInstantiation | |
| 4796 | (PP ? TypeDependence::UnexpandedPack : TypeDependence::None)) { |
| 4797 | CanTTPTInfo.Depth = D; |
| 4798 | CanTTPTInfo.Index = I; |
| 4799 | CanTTPTInfo.ParameterPack = PP; |
| 4800 | } |
| 4801 | |
| 4802 | const CanonicalTTPTInfo& getCanTTPTInfo() const { |
| 4803 | QualType Can = getCanonicalTypeInternal(); |
| 4804 | return Can->castAs<TemplateTypeParmType>()->CanTTPTInfo; |
| 4805 | } |
| 4806 | |
| 4807 | public: |
| 4808 | unsigned getDepth() const { return getCanTTPTInfo().Depth; } |
| 4809 | unsigned getIndex() const { return getCanTTPTInfo().Index; } |
| 4810 | bool isParameterPack() const { return getCanTTPTInfo().ParameterPack; } |
| 4811 | |
| 4812 | TemplateTypeParmDecl *getDecl() const { |
| 4813 | return isCanonicalUnqualified() ? nullptr : TTPDecl; |
| 4814 | } |
| 4815 | |
| 4816 | IdentifierInfo *getIdentifier() const; |
| 4817 | |
| 4818 | bool isSugared() const { return false; } |
| 4819 | QualType desugar() const { return QualType(this, 0); } |
| 4820 | |
| 4821 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 4822 | Profile(ID, getDepth(), getIndex(), isParameterPack(), getDecl()); |
| 4823 | } |
| 4824 | |
| 4825 | static void Profile(llvm::FoldingSetNodeID &ID, unsigned Depth, |
| 4826 | unsigned Index, bool ParameterPack, |
| 4827 | TemplateTypeParmDecl *TTPDecl) { |
| 4828 | ID.AddInteger(Depth); |
| 4829 | ID.AddInteger(Index); |
| 4830 | ID.AddBoolean(ParameterPack); |
| 4831 | ID.AddPointer(TTPDecl); |
| 4832 | } |
| 4833 | |
| 4834 | static bool classof(const Type *T) { |
| 4835 | return T->getTypeClass() == TemplateTypeParm; |
| 4836 | } |
| 4837 | }; |
| 4838 | |
| 4839 | |
| 4840 | |
| 4841 | |
| 4842 | |
| 4843 | |
| 4844 | |
| 4845 | |
| 4846 | class SubstTemplateTypeParmType : public Type, public llvm::FoldingSetNode { |
| 4847 | friend class ASTContext; |
| 4848 | |
| 4849 | |
| 4850 | const TemplateTypeParmType *Replaced; |
| 4851 | |
| 4852 | SubstTemplateTypeParmType(const TemplateTypeParmType *Param, QualType Canon) |
| 4853 | : Type(SubstTemplateTypeParm, Canon, Canon->getDependence()), |
| 4854 | Replaced(Param) {} |
| 4855 | |
| 4856 | public: |
| 4857 | |
| 4858 | const TemplateTypeParmType *getReplacedParameter() const { |
| 4859 | return Replaced; |
| 4860 | } |
| 4861 | |
| 4862 | |
| 4863 | |
| 4864 | QualType getReplacementType() const { |
| 4865 | return getCanonicalTypeInternal(); |
| 4866 | } |
| 4867 | |
| 4868 | bool isSugared() const { return true; } |
| 4869 | QualType desugar() const { return getReplacementType(); } |
| 4870 | |
| 4871 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 4872 | Profile(ID, getReplacedParameter(), getReplacementType()); |
| 4873 | } |
| 4874 | |
| 4875 | static void Profile(llvm::FoldingSetNodeID &ID, |
| 4876 | const TemplateTypeParmType *Replaced, |
| 4877 | QualType Replacement) { |
| 4878 | ID.AddPointer(Replaced); |
| 4879 | ID.AddPointer(Replacement.getAsOpaquePtr()); |
| 4880 | } |
| 4881 | |
| 4882 | static bool classof(const Type *T) { |
| 4883 | return T->getTypeClass() == SubstTemplateTypeParm; |
| 4884 | } |
| 4885 | }; |
| 4886 | |
| 4887 | |
| 4888 | |
| 4889 | |
| 4890 | |
| 4891 | |
| 4892 | |
| 4893 | |
| 4894 | |
| 4895 | |
| 4896 | |
| 4897 | |
| 4898 | |
| 4899 | class SubstTemplateTypeParmPackType : public Type, public llvm::FoldingSetNode { |
| 4900 | friend class ASTContext; |
| 4901 | |
| 4902 | |
| 4903 | const TemplateTypeParmType *Replaced; |
| 4904 | |
| 4905 | |
| 4906 | |
| 4907 | const TemplateArgument *Arguments; |
| 4908 | |
| 4909 | SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param, |
| 4910 | QualType Canon, |
| 4911 | const TemplateArgument &ArgPack); |
| 4912 | |
| 4913 | public: |
| 4914 | IdentifierInfo *getIdentifier() const { return Replaced->getIdentifier(); } |
| 4915 | |
| 4916 | |
| 4917 | const TemplateTypeParmType *getReplacedParameter() const { |
| 4918 | return Replaced; |
| 4919 | } |
| 4920 | |
| 4921 | unsigned getNumArgs() const { |
| 4922 | return SubstTemplateTypeParmPackTypeBits.NumArgs; |
| 4923 | } |
| 4924 | |
| 4925 | bool isSugared() const { return false; } |
| 4926 | QualType desugar() const { return QualType(this, 0); } |
| 4927 | |
| 4928 | TemplateArgument getArgumentPack() const; |
| 4929 | |
| 4930 | void Profile(llvm::FoldingSetNodeID &ID); |
| 4931 | static void Profile(llvm::FoldingSetNodeID &ID, |
| 4932 | const TemplateTypeParmType *Replaced, |
| 4933 | const TemplateArgument &ArgPack); |
| 4934 | |
| 4935 | static bool classof(const Type *T) { |
| 4936 | return T->getTypeClass() == SubstTemplateTypeParmPack; |
| 4937 | } |
| 4938 | }; |
| 4939 | |
| 4940 | |
| 4941 | |
| 4942 | |
| 4943 | |
| 4944 | |
| 4945 | |
| 4946 | |
| 4947 | |
| 4948 | class DeducedType : public Type { |
| 4949 | protected: |
| 4950 | DeducedType(TypeClass TC, QualType DeducedAsType, |
| 4951 | TypeDependence ExtraDependence) |
| 4952 | : Type(TC, |
| 4953 | |
| 4954 | DeducedAsType.isNull() ? QualType(this, 0) |
| 4955 | : DeducedAsType.getCanonicalType(), |
| 4956 | ExtraDependence | (DeducedAsType.isNull() |
| 4957 | ? TypeDependence::None |
| 4958 | : DeducedAsType->getDependence() & |
| 4959 | ~TypeDependence::VariablyModified)) {} |
| 4960 | |
| 4961 | public: |
| 4962 | bool isSugared() const { return !isCanonicalUnqualified(); } |
| 4963 | QualType desugar() const { return getCanonicalTypeInternal(); } |
| 4964 | |
| 4965 | |
| 4966 | |
| 4967 | QualType getDeducedType() const { |
| 4968 | return !isCanonicalUnqualified() ? getCanonicalTypeInternal() : QualType(); |
| 4969 | } |
| 4970 | bool isDeduced() const { |
| 4971 | return !isCanonicalUnqualified() || isDependentType(); |
| 4972 | } |
| 4973 | |
| 4974 | static bool classof(const Type *T) { |
| 4975 | return T->getTypeClass() == Auto || |
| 4976 | T->getTypeClass() == DeducedTemplateSpecialization; |
| 4977 | } |
| 4978 | }; |
| 4979 | |
| 4980 | |
| 4981 | |
| 4982 | class alignas(8) AutoType : public DeducedType, public llvm::FoldingSetNode { |
| 4983 | friend class ASTContext; |
| 4984 | |
| 4985 | ConceptDecl *TypeConstraintConcept; |
| 4986 | |
| 4987 | AutoType(QualType DeducedAsType, AutoTypeKeyword Keyword, |
| 4988 | TypeDependence ExtraDependence, ConceptDecl *CD, |
| 4989 | ArrayRef<TemplateArgument> TypeConstraintArgs); |
| 4990 | |
| 4991 | const TemplateArgument *getArgBuffer() const { |
| 4992 | return reinterpret_cast<const TemplateArgument*>(this+1); |
| 4993 | } |
| 4994 | |
| 4995 | TemplateArgument *getArgBuffer() { |
| 4996 | return reinterpret_cast<TemplateArgument*>(this+1); |
| 4997 | } |
| 4998 | |
| 4999 | public: |
| 5000 | |
| 5001 | const TemplateArgument *getArgs() const { |
| 5002 | return getArgBuffer(); |
| 5003 | } |
| 5004 | |
| 5005 | |
| 5006 | unsigned getNumArgs() const { |
| 5007 | return AutoTypeBits.NumArgs; |
| 5008 | } |
| 5009 | |
| 5010 | const TemplateArgument &getArg(unsigned Idx) const; |
| 5011 | |
| 5012 | ArrayRef<TemplateArgument> getTypeConstraintArguments() const { |
| 5013 | return {getArgs(), getNumArgs()}; |
| 5014 | } |
| 5015 | |
| 5016 | ConceptDecl *getTypeConstraintConcept() const { |
| 5017 | return TypeConstraintConcept; |
| 5018 | } |
| 5019 | |
| 5020 | bool isConstrained() const { |
| 5021 | return TypeConstraintConcept != nullptr; |
| 5022 | } |
| 5023 | |
| 5024 | bool isDecltypeAuto() const { |
| 5025 | return getKeyword() == AutoTypeKeyword::DecltypeAuto; |
| 5026 | } |
| 5027 | |
| 5028 | AutoTypeKeyword getKeyword() const { |
| 5029 | return (AutoTypeKeyword)AutoTypeBits.Keyword; |
| 5030 | } |
| 5031 | |
| 5032 | void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) { |
| 5033 | Profile(ID, Context, getDeducedType(), getKeyword(), isDependentType(), |
| 5034 | getTypeConstraintConcept(), getTypeConstraintArguments()); |
| 5035 | } |
| 5036 | |
| 5037 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
| 5038 | QualType Deduced, AutoTypeKeyword Keyword, |
| 5039 | bool IsDependent, ConceptDecl *CD, |
| 5040 | ArrayRef<TemplateArgument> Arguments); |
| 5041 | |
| 5042 | static bool classof(const Type *T) { |
| 5043 | return T->getTypeClass() == Auto; |
| 5044 | } |
| 5045 | }; |
| 5046 | |
| 5047 | |
| 5048 | class DeducedTemplateSpecializationType : public DeducedType, |
| 5049 | public llvm::FoldingSetNode { |
| 5050 | friend class ASTContext; |
| 5051 | |
| 5052 | |
| 5053 | TemplateName Template; |
| 5054 | |
| 5055 | DeducedTemplateSpecializationType(TemplateName Template, |
| 5056 | QualType DeducedAsType, |
| 5057 | bool IsDeducedAsDependent) |
| 5058 | : DeducedType(DeducedTemplateSpecialization, DeducedAsType, |
| 5059 | toTypeDependence(Template.getDependence()) | |
| 5060 | (IsDeducedAsDependent |
| 5061 | ? TypeDependence::DependentInstantiation |
| 5062 | : TypeDependence::None)), |
| 5063 | Template(Template) {} |
| 5064 | |
| 5065 | public: |
| 5066 | |
| 5067 | TemplateName getTemplateName() const { return Template;} |
| 5068 | |
| 5069 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 5070 | Profile(ID, getTemplateName(), getDeducedType(), isDependentType()); |
| 5071 | } |
| 5072 | |
| 5073 | static void Profile(llvm::FoldingSetNodeID &ID, TemplateName Template, |
| 5074 | QualType Deduced, bool IsDependent) { |
| 5075 | Template.Profile(ID); |
| 5076 | ID.AddPointer(Deduced.getAsOpaquePtr()); |
| 5077 | ID.AddBoolean(IsDependent); |
| 5078 | } |
| 5079 | |
| 5080 | static bool classof(const Type *T) { |
| 5081 | return T->getTypeClass() == DeducedTemplateSpecialization; |
| 5082 | } |
| 5083 | }; |
| 5084 | |
| 5085 | |
| 5086 | |
| 5087 | |
| 5088 | |
| 5089 | |
| 5090 | |
| 5091 | |
| 5092 | |
| 5093 | |
| 5094 | |
| 5095 | |
| 5096 | |
| 5097 | |
| 5098 | |
| 5099 | |
| 5100 | |
| 5101 | |
| 5102 | |
| 5103 | |
| 5104 | |
| 5105 | class alignas(8) TemplateSpecializationType |
| 5106 | : public Type, |
| 5107 | public llvm::FoldingSetNode { |
| 5108 | friend class ASTContext; |
| 5109 | |
| 5110 | |
| 5111 | |
| 5112 | |
| 5113 | |
| 5114 | |
| 5115 | |
| 5116 | |
| 5117 | TemplateName Template; |
| 5118 | |
| 5119 | TemplateSpecializationType(TemplateName T, |
| 5120 | ArrayRef<TemplateArgument> Args, |
| 5121 | QualType Canon, |
| 5122 | QualType Aliased); |
| 5123 | |
| 5124 | public: |
| 5125 | |
| 5126 | |
| 5127 | |
| 5128 | |
| 5129 | |
| 5130 | |
| 5131 | |
| 5132 | |
| 5133 | |
| 5134 | |
| 5135 | |
| 5136 | static bool |
| 5137 | anyDependentTemplateArguments(ArrayRef<TemplateArgumentLoc> Args, |
| 5138 | ArrayRef<TemplateArgument> Converted); |
| 5139 | static bool |
| 5140 | anyDependentTemplateArguments(const TemplateArgumentListInfo &, |
| 5141 | ArrayRef<TemplateArgument> Converted); |
| 5142 | static bool anyInstantiationDependentTemplateArguments( |
| 5143 | ArrayRef<TemplateArgumentLoc> Args); |
| 5144 | |
| 5145 | |
| 5146 | |
| 5147 | bool isCurrentInstantiation() const { |
| 5148 | return isa<InjectedClassNameType>(getCanonicalTypeInternal()); |
| 5149 | } |
| 5150 | |
| 5151 | |
| 5152 | |
| 5153 | |
| 5154 | |
| 5155 | |
| 5156 | |
| 5157 | |
| 5158 | |
| 5159 | |
| 5160 | |
| 5161 | |
| 5162 | |
| 5163 | |
| 5164 | |
| 5165 | |
| 5166 | bool isTypeAlias() const { return TemplateSpecializationTypeBits.TypeAlias; } |
| 5167 | |
| 5168 | |
| 5169 | |
| 5170 | QualType getAliasedType() const { |
| 5171 | assert(isTypeAlias() && "not a type alias template specialization"); |
| 5172 | return *reinterpret_cast<const QualType*>(end()); |
| 5173 | } |
| 5174 | |
| 5175 | using iterator = const TemplateArgument *; |
| 5176 | |
| 5177 | iterator begin() const { return getArgs(); } |
| 5178 | iterator end() const; |
| 5179 | |
| 5180 | |
| 5181 | TemplateName getTemplateName() const { return Template; } |
| 5182 | |
| 5183 | |
| 5184 | const TemplateArgument *getArgs() const { |
| 5185 | return reinterpret_cast<const TemplateArgument *>(this + 1); |
| 5186 | } |
| 5187 | |
| 5188 | |
| 5189 | unsigned getNumArgs() const { |
| 5190 | return TemplateSpecializationTypeBits.NumArgs; |
| 5191 | } |
| 5192 | |
| 5193 | |
| 5194 | |
| 5195 | const TemplateArgument &getArg(unsigned Idx) const; |
| 5196 | |
| 5197 | ArrayRef<TemplateArgument> template_arguments() const { |
| 5198 | return {getArgs(), getNumArgs()}; |
| 5199 | } |
| 5200 | |
| 5201 | bool isSugared() const { |
| 5202 | return !isDependentType() || isCurrentInstantiation() || isTypeAlias(); |
| 5203 | } |
| 5204 | |
| 5205 | QualType desugar() const { |
| 5206 | return isTypeAlias() ? getAliasedType() : getCanonicalTypeInternal(); |
| 5207 | } |
| 5208 | |
| 5209 | void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Ctx) { |
| 5210 | Profile(ID, Template, template_arguments(), Ctx); |
| 5211 | if (isTypeAlias()) |
| 5212 | getAliasedType().Profile(ID); |
| 5213 | } |
| 5214 | |
| 5215 | static void Profile(llvm::FoldingSetNodeID &ID, TemplateName T, |
| 5216 | ArrayRef<TemplateArgument> Args, |
| 5217 | const ASTContext &Context); |
| 5218 | |
| 5219 | static bool classof(const Type *T) { |
| 5220 | return T->getTypeClass() == TemplateSpecialization; |
| 5221 | } |
| 5222 | }; |
| 5223 | |
| 5224 | |
| 5225 | |
| 5226 | void printTemplateArgumentList(raw_ostream &OS, |
| 5227 | ArrayRef<TemplateArgument> Args, |
| 5228 | const PrintingPolicy &Policy, |
| 5229 | const TemplateParameterList *TPL = nullptr); |
| 5230 | |
| 5231 | void printTemplateArgumentList(raw_ostream &OS, |
| 5232 | ArrayRef<TemplateArgumentLoc> Args, |
| 5233 | const PrintingPolicy &Policy, |
| 5234 | const TemplateParameterList *TPL = nullptr); |
| 5235 | |
| 5236 | void printTemplateArgumentList(raw_ostream &OS, |
| 5237 | const TemplateArgumentListInfo &Args, |
| 5238 | const PrintingPolicy &Policy, |
| 5239 | const TemplateParameterList *TPL = nullptr); |
| 5240 | |
| 5241 | |
| 5242 | |
| 5243 | |
| 5244 | |
| 5245 | |
| 5246 | |
| 5247 | |
| 5248 | |
| 5249 | |
| 5250 | |
| 5251 | |
| 5252 | |
| 5253 | |
| 5254 | |
| 5255 | |
| 5256 | |
| 5257 | |
| 5258 | class InjectedClassNameType : public Type { |
| 5259 | friend class ASTContext; |
| 5260 | friend class ASTNodeImporter; |
| 5261 | friend class ASTReader; |
| 5262 | |
| 5263 | |
| 5264 | template <class T> friend class serialization::AbstractTypeReader; |
| 5265 | |
| 5266 | CXXRecordDecl *Decl; |
| 5267 | |
| 5268 | |
| 5269 | |
| 5270 | |
| 5271 | |
| 5272 | |
| 5273 | |
| 5274 | |
| 5275 | |
| 5276 | |
| 5277 | QualType InjectedType; |
| 5278 | |
| 5279 | InjectedClassNameType(CXXRecordDecl *D, QualType TST) |
| 5280 | : Type(InjectedClassName, QualType(), |
| 5281 | TypeDependence::DependentInstantiation), |
| 5282 | Decl(D), InjectedType(TST) { |
| 5283 | assert(isa<TemplateSpecializationType>(TST)); |
| 5284 | assert(!TST.hasQualifiers()); |
| 5285 | assert(TST->isDependentType()); |
| 5286 | } |
| 5287 | |
| 5288 | public: |
| 5289 | QualType getInjectedSpecializationType() const { return InjectedType; } |
| 5290 | |
| 5291 | const TemplateSpecializationType *getInjectedTST() const { |
| 5292 | return cast<TemplateSpecializationType>(InjectedType.getTypePtr()); |
| 5293 | } |
| 5294 | |
| 5295 | TemplateName getTemplateName() const { |
| 5296 | return getInjectedTST()->getTemplateName(); |
| 5297 | } |
| 5298 | |
| 5299 | CXXRecordDecl *getDecl() const; |
| 5300 | |
| 5301 | bool isSugared() const { return false; } |
| 5302 | QualType desugar() const { return QualType(this, 0); } |
| 5303 | |
| 5304 | static bool classof(const Type *T) { |
| 5305 | return T->getTypeClass() == InjectedClassName; |
| 5306 | } |
| 5307 | }; |
| 5308 | |
| 5309 | |
| 5310 | enum TagTypeKind { |
| 5311 | |
| 5312 | TTK_Struct, |
| 5313 | |
| 5314 | |
| 5315 | TTK_Interface, |
| 5316 | |
| 5317 | |
| 5318 | TTK_Union, |
| 5319 | |
| 5320 | |
| 5321 | TTK_Class, |
| 5322 | |
| 5323 | |
| 5324 | TTK_Enum |
| 5325 | }; |
| 5326 | |
| 5327 | |
| 5328 | |
| 5329 | enum ElaboratedTypeKeyword { |
| 5330 | |
| 5331 | ETK_Struct, |
| 5332 | |
| 5333 | |
| 5334 | ETK_Interface, |
| 5335 | |
| 5336 | |
| 5337 | ETK_Union, |
| 5338 | |
| 5339 | |
| 5340 | ETK_Class, |
| 5341 | |
| 5342 | |
| 5343 | ETK_Enum, |
| 5344 | |
| 5345 | |
| 5346 | |
| 5347 | ETK_Typename, |
| 5348 | |
| 5349 | |
| 5350 | ETK_None |
| 5351 | }; |
| 5352 | |
| 5353 | |
| 5354 | |
| 5355 | |
| 5356 | |
| 5357 | class TypeWithKeyword : public Type { |
| 5358 | protected: |
| 5359 | TypeWithKeyword(ElaboratedTypeKeyword Keyword, TypeClass tc, |
| 5360 | QualType Canonical, TypeDependence Dependence) |
| 5361 | : Type(tc, Canonical, Dependence) { |
| 5362 | TypeWithKeywordBits.Keyword = Keyword; |
| 5363 | } |
| 5364 | |
| 5365 | public: |
| 5366 | ElaboratedTypeKeyword getKeyword() const { |
| 5367 | return static_cast<ElaboratedTypeKeyword>(TypeWithKeywordBits.Keyword); |
| 5368 | } |
| 5369 | |
| 5370 | |
| 5371 | static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec); |
| 5372 | |
| 5373 | |
| 5374 | |
| 5375 | static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec); |
| 5376 | |
| 5377 | |
| 5378 | static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag); |
| 5379 | |
| 5380 | |
| 5381 | |
| 5382 | |
| 5383 | static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword); |
| 5384 | |
| 5385 | static bool KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword); |
| 5386 | |
| 5387 | static StringRef getKeywordName(ElaboratedTypeKeyword Keyword); |
| 5388 | |
| 5389 | static StringRef getTagTypeKindName(TagTypeKind Kind) { |
| 5390 | return getKeywordName(getKeywordForTagTypeKind(Kind)); |
| 5391 | } |
| 5392 | |
| 5393 | class CannotCastToThisType {}; |
| 5394 | static CannotCastToThisType classof(const Type *); |
| 5395 | }; |
| 5396 | |
| 5397 | |
| 5398 | |
| 5399 | |
| 5400 | |
| 5401 | |
| 5402 | |
| 5403 | |
| 5404 | |
| 5405 | class ElaboratedType final |
| 5406 | : public TypeWithKeyword, |
| 5407 | public llvm::FoldingSetNode, |
| 5408 | private llvm::TrailingObjects<ElaboratedType, TagDecl *> { |
| 5409 | friend class ASTContext; |
| 5410 | friend TrailingObjects; |
| 5411 | |
| 5412 | |
| 5413 | NestedNameSpecifier *NNS; |
| 5414 | |
| 5415 | |
| 5416 | QualType NamedType; |
| 5417 | |
| 5418 | |
| 5419 | |
| 5420 | |
| 5421 | |
| 5422 | ElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, |
| 5423 | QualType NamedType, QualType CanonType, TagDecl *OwnedTagDecl) |
| 5424 | : TypeWithKeyword(Keyword, Elaborated, CanonType, |
| 5425 | |
| 5426 | |
| 5427 | |
| 5428 | |
| 5429 | NamedType->getDependence() | |
| 5430 | (NNS ? toSyntacticDependence( |
| 5431 | toTypeDependence(NNS->getDependence())) |
| 5432 | : TypeDependence::None)), |
| 5433 | NNS(NNS), NamedType(NamedType) { |
| 5434 | ElaboratedTypeBits.HasOwnedTagDecl = false; |
| 5435 | if (OwnedTagDecl) { |
| 5436 | ElaboratedTypeBits.HasOwnedTagDecl = true; |
| 5437 | *getTrailingObjects<TagDecl *>() = OwnedTagDecl; |
| 5438 | } |
| 5439 | assert(!(Keyword == ETK_None && NNS == nullptr) && |
| 5440 | "ElaboratedType cannot have elaborated type keyword " |
| 5441 | "and name qualifier both null."); |
| 5442 | } |
| 5443 | |
| 5444 | public: |
| 5445 | |
| 5446 | NestedNameSpecifier *getQualifier() const { return NNS; } |
| 5447 | |
| 5448 | |
| 5449 | QualType getNamedType() const { return NamedType; } |
| 5450 | |
| 5451 | |
| 5452 | QualType desugar() const { return getNamedType(); } |
| 5453 | |
| 5454 | |
| 5455 | bool isSugared() const { return true; } |
| 5456 | |
| 5457 | |
| 5458 | |
| 5459 | TagDecl *getOwnedTagDecl() const { |
| 5460 | return ElaboratedTypeBits.HasOwnedTagDecl ? *getTrailingObjects<TagDecl *>() |
| 5461 | : nullptr; |
| 5462 | } |
| 5463 | |
| 5464 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 5465 | Profile(ID, getKeyword(), NNS, NamedType, getOwnedTagDecl()); |
| 5466 | } |
| 5467 | |
| 5468 | static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, |
| 5469 | NestedNameSpecifier *NNS, QualType NamedType, |
| 5470 | TagDecl *OwnedTagDecl) { |
| 5471 | ID.AddInteger(Keyword); |
| 5472 | ID.AddPointer(NNS); |
| 5473 | NamedType.Profile(ID); |
| 5474 | ID.AddPointer(OwnedTagDecl); |
| 5475 | } |
| 5476 | |
| 5477 | static bool classof(const Type *T) { return T->getTypeClass() == Elaborated; } |
| 5478 | }; |
| 5479 | |
| 5480 | |
| 5481 | |
| 5482 | |
| 5483 | |
| 5484 | |
| 5485 | |
| 5486 | |
| 5487 | |
| 5488 | |
| 5489 | |
| 5490 | |
| 5491 | |
| 5492 | class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode { |
| 5493 | friend class ASTContext; |
| 5494 | |
| 5495 | |
| 5496 | NestedNameSpecifier *NNS; |
| 5497 | |
| 5498 | |
| 5499 | const IdentifierInfo *Name; |
| 5500 | |
| 5501 | DependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, |
| 5502 | const IdentifierInfo *Name, QualType CanonType) |
| 5503 | : TypeWithKeyword(Keyword, DependentName, CanonType, |
| 5504 | TypeDependence::DependentInstantiation | |
| 5505 | toTypeDependence(NNS->getDependence())), |
| 5506 | NNS(NNS), Name(Name) {} |
| 5507 | |
| 5508 | public: |
| 5509 | |
| 5510 | NestedNameSpecifier *getQualifier() const { return NNS; } |
| 5511 | |
| 5512 | |
| 5513 | |
| 5514 | |
| 5515 | |
| 5516 | |
| 5517 | const IdentifierInfo *getIdentifier() const { |
| 5518 | return Name; |
| 5519 | } |
| 5520 | |
| 5521 | bool isSugared() const { return false; } |
| 5522 | QualType desugar() const { return QualType(this, 0); } |
| 5523 | |
| 5524 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 5525 | Profile(ID, getKeyword(), NNS, Name); |
| 5526 | } |
| 5527 | |
| 5528 | static void Profile(llvm::FoldingSetNodeID &ID, ElaboratedTypeKeyword Keyword, |
| 5529 | NestedNameSpecifier *NNS, const IdentifierInfo *Name) { |
| 5530 | ID.AddInteger(Keyword); |
| 5531 | ID.AddPointer(NNS); |
| 5532 | ID.AddPointer(Name); |
| 5533 | } |
| 5534 | |
| 5535 | static bool classof(const Type *T) { |
| 5536 | return T->getTypeClass() == DependentName; |
| 5537 | } |
| 5538 | }; |
| 5539 | |
| 5540 | |
| 5541 | |
| 5542 | |
| 5543 | class alignas(8) DependentTemplateSpecializationType |
| 5544 | : public TypeWithKeyword, |
| 5545 | public llvm::FoldingSetNode { |
| 5546 | friend class ASTContext; |
| 5547 | |
| 5548 | |
| 5549 | NestedNameSpecifier *NNS; |
| 5550 | |
| 5551 | |
| 5552 | const IdentifierInfo *Name; |
| 5553 | |
| 5554 | DependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, |
| 5555 | NestedNameSpecifier *NNS, |
| 5556 | const IdentifierInfo *Name, |
| 5557 | ArrayRef<TemplateArgument> Args, |
| 5558 | QualType Canon); |
| 5559 | |
| 5560 | const TemplateArgument *getArgBuffer() const { |
| 5561 | return reinterpret_cast<const TemplateArgument*>(this+1); |
| 5562 | } |
| 5563 | |
| 5564 | TemplateArgument *getArgBuffer() { |
| 5565 | return reinterpret_cast<TemplateArgument*>(this+1); |
| 5566 | } |
| 5567 | |
| 5568 | public: |
| 5569 | NestedNameSpecifier *getQualifier() const { return NNS; } |
| 5570 | const IdentifierInfo *getIdentifier() const { return Name; } |
| 5571 | |
| 5572 | |
| 5573 | const TemplateArgument *getArgs() const { |
| 5574 | return getArgBuffer(); |
| 5575 | } |
| 5576 | |
| 5577 | |
| 5578 | unsigned getNumArgs() const { |
| 5579 | return DependentTemplateSpecializationTypeBits.NumArgs; |
| 5580 | } |
| 5581 | |
| 5582 | const TemplateArgument &getArg(unsigned Idx) const; |
| 5583 | |
| 5584 | ArrayRef<TemplateArgument> template_arguments() const { |
| 5585 | return {getArgs(), getNumArgs()}; |
| 5586 | } |
| 5587 | |
| 5588 | using iterator = const TemplateArgument *; |
| 5589 | |
| 5590 | iterator begin() const { return getArgs(); } |
| 5591 | iterator end() const; |
| 5592 | |
| 5593 | bool isSugared() const { return false; } |
| 5594 | QualType desugar() const { return QualType(this, 0); } |
| 5595 | |
| 5596 | void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context) { |
| 5597 | Profile(ID, Context, getKeyword(), NNS, Name, {getArgs(), getNumArgs()}); |
| 5598 | } |
| 5599 | |
| 5600 | static void Profile(llvm::FoldingSetNodeID &ID, |
| 5601 | const ASTContext &Context, |
| 5602 | ElaboratedTypeKeyword Keyword, |
| 5603 | NestedNameSpecifier *Qualifier, |
| 5604 | const IdentifierInfo *Name, |
| 5605 | ArrayRef<TemplateArgument> Args); |
| 5606 | |
| 5607 | static bool classof(const Type *T) { |
| 5608 | return T->getTypeClass() == DependentTemplateSpecialization; |
| 5609 | } |
| 5610 | }; |
| 5611 | |
| 5612 | |
| 5613 | |
| 5614 | |
| 5615 | |
| 5616 | |
| 5617 | |
| 5618 | |
| 5619 | |
| 5620 | |
| 5621 | |
| 5622 | |
| 5623 | |
| 5624 | |
| 5625 | |
| 5626 | |
| 5627 | |
| 5628 | |
| 5629 | |
| 5630 | |
| 5631 | |
| 5632 | |
| 5633 | |
| 5634 | class PackExpansionType : public Type, public llvm::FoldingSetNode { |
| 5635 | friend class ASTContext; |
| 5636 | |
| 5637 | |
| 5638 | QualType Pattern; |
| 5639 | |
| 5640 | PackExpansionType(QualType Pattern, QualType Canon, |
| 5641 | Optional<unsigned> NumExpansions) |
| 5642 | : Type(PackExpansion, Canon, |
| 5643 | (Pattern->getDependence() | TypeDependence::Dependent | |
| 5644 | TypeDependence::Instantiation) & |
| 5645 | ~TypeDependence::UnexpandedPack), |
| 5646 | Pattern(Pattern) { |
| 5647 | PackExpansionTypeBits.NumExpansions = |
| 5648 | NumExpansions ? *NumExpansions + 1 : 0; |
| 5649 | } |
| 5650 | |
| 5651 | public: |
| 5652 | |
| 5653 | |
| 5654 | |
| 5655 | QualType getPattern() const { return Pattern; } |
| 5656 | |
| 5657 | |
| 5658 | |
| 5659 | Optional<unsigned> getNumExpansions() const { |
| 5660 | if (PackExpansionTypeBits.NumExpansions) |
| 5661 | return PackExpansionTypeBits.NumExpansions - 1; |
| 5662 | return None; |
| 5663 | } |
| 5664 | |
| 5665 | bool isSugared() const { return false; } |
| 5666 | QualType desugar() const { return QualType(this, 0); } |
| 5667 | |
| 5668 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 5669 | Profile(ID, getPattern(), getNumExpansions()); |
| 5670 | } |
| 5671 | |
| 5672 | static void Profile(llvm::FoldingSetNodeID &ID, QualType Pattern, |
| 5673 | Optional<unsigned> NumExpansions) { |
| 5674 | ID.AddPointer(Pattern.getAsOpaquePtr()); |
| 5675 | ID.AddBoolean(NumExpansions.hasValue()); |
| 5676 | if (NumExpansions) |
| 5677 | ID.AddInteger(*NumExpansions); |
| 5678 | } |
| 5679 | |
| 5680 | static bool classof(const Type *T) { |
| 5681 | return T->getTypeClass() == PackExpansion; |
| 5682 | } |
| 5683 | }; |
| 5684 | |
| 5685 | |
| 5686 | |
| 5687 | template <class T> |
| 5688 | class ObjCProtocolQualifiers { |
| 5689 | protected: |
| 5690 | ObjCProtocolQualifiers() = default; |
| 5691 | |
| 5692 | ObjCProtocolDecl * const *getProtocolStorage() const { |
| 5693 | return const_cast<ObjCProtocolQualifiers*>(this)->getProtocolStorage(); |
| 5694 | } |
| 5695 | |
| 5696 | ObjCProtocolDecl **getProtocolStorage() { |
| 5697 | return static_cast<T*>(this)->getProtocolStorageImpl(); |
| 5698 | } |
| 5699 | |
| 5700 | void setNumProtocols(unsigned N) { |
| 5701 | static_cast<T*>(this)->setNumProtocolsImpl(N); |
| 5702 | } |
| 5703 | |
| 5704 | void initialize(ArrayRef<ObjCProtocolDecl *> protocols) { |
| 5705 | setNumProtocols(protocols.size()); |
| 5706 | assert(getNumProtocols() == protocols.size() && |
| 5707 | "bitfield overflow in protocol count"); |
| 5708 | if (!protocols.empty()) |
| 5709 | memcpy(getProtocolStorage(), protocols.data(), |
| 5710 | protocols.size() * sizeof(ObjCProtocolDecl*)); |
| 5711 | } |
| 5712 | |
| 5713 | public: |
| 5714 | using qual_iterator = ObjCProtocolDecl * const *; |
| 5715 | using qual_range = llvm::iterator_range<qual_iterator>; |
| 5716 | |
| 5717 | qual_range quals() const { return qual_range(qual_begin(), qual_end()); } |
| 5718 | qual_iterator qual_begin() const { return getProtocolStorage(); } |
| 5719 | qual_iterator qual_end() const { return qual_begin() + getNumProtocols(); } |
| 5720 | |
| 5721 | bool qual_empty() const { return getNumProtocols() == 0; } |
| 5722 | |
| 5723 | |
| 5724 | |
| 5725 | unsigned getNumProtocols() const { |
| 5726 | return static_cast<const T*>(this)->getNumProtocolsImpl(); |
| 5727 | } |
| 5728 | |
| 5729 | |
| 5730 | ObjCProtocolDecl *getProtocol(unsigned I) const { |
| 5731 | assert(I < getNumProtocols() && "Out-of-range protocol access"); |
| 5732 | return qual_begin()[I]; |
| 5733 | } |
| 5734 | |
| 5735 | |
| 5736 | ArrayRef<ObjCProtocolDecl *> getProtocols() const { |
| 5737 | return ArrayRef<ObjCProtocolDecl *>(qual_begin(), getNumProtocols()); |
| 5738 | } |
| 5739 | }; |
| 5740 | |
| 5741 | |
| 5742 | |
| 5743 | class ObjCTypeParamType : public Type, |
| 5744 | public ObjCProtocolQualifiers<ObjCTypeParamType>, |
| 5745 | public llvm::FoldingSetNode { |
| 5746 | friend class ASTContext; |
| 5747 | friend class ObjCProtocolQualifiers<ObjCTypeParamType>; |
| 5748 | |
| 5749 | |
| 5750 | unsigned NumProtocols : 6; |
| 5751 | |
| 5752 | ObjCTypeParamDecl *OTPDecl; |
| 5753 | |
| 5754 | |
| 5755 | |
| 5756 | |
| 5757 | ObjCProtocolDecl **getProtocolStorageImpl(); |
| 5758 | |
| 5759 | |
| 5760 | |
| 5761 | unsigned getNumProtocolsImpl() const { |
| 5762 | return NumProtocols; |
| 5763 | } |
| 5764 | |
| 5765 | void setNumProtocolsImpl(unsigned N) { |
| 5766 | NumProtocols = N; |
| 5767 | } |
| 5768 | |
| 5769 | ObjCTypeParamType(const ObjCTypeParamDecl *D, |
| 5770 | QualType can, |
| 5771 | ArrayRef<ObjCProtocolDecl *> protocols); |
| 5772 | |
| 5773 | public: |
| 5774 | bool isSugared() const { return true; } |
| 5775 | QualType desugar() const { return getCanonicalTypeInternal(); } |
| 5776 | |
| 5777 | static bool classof(const Type *T) { |
| 5778 | return T->getTypeClass() == ObjCTypeParam; |
| 5779 | } |
| 5780 | |
| 5781 | void Profile(llvm::FoldingSetNodeID &ID); |
| 5782 | static void Profile(llvm::FoldingSetNodeID &ID, |
| 5783 | const ObjCTypeParamDecl *OTPDecl, |
| 5784 | QualType CanonicalType, |
| 5785 | ArrayRef<ObjCProtocolDecl *> protocols); |
| 5786 | |
| 5787 | ObjCTypeParamDecl *getDecl() const { return OTPDecl; } |
| 5788 | }; |
| 5789 | |
| 5790 | |
| 5791 | |
| 5792 | |
| 5793 | |
| 5794 | |
| 5795 | |
| 5796 | |
| 5797 | |
| 5798 | |
| 5799 | |
| 5800 | |
| 5801 | |
| 5802 | |
| 5803 | |
| 5804 | |
| 5805 | |
| 5806 | |
| 5807 | |
| 5808 | |
| 5809 | |
| 5810 | |
| 5811 | |
| 5812 | |
| 5813 | |
| 5814 | |
| 5815 | |
| 5816 | |
| 5817 | |
| 5818 | class ObjCObjectType : public Type, |
| 5819 | public ObjCProtocolQualifiers<ObjCObjectType> { |
| 5820 | friend class ObjCProtocolQualifiers<ObjCObjectType>; |
| 5821 | |
| 5822 | |
| 5823 | |
| 5824 | |
| 5825 | |
| 5826 | |
| 5827 | |
| 5828 | |
| 5829 | |
| 5830 | |
| 5831 | |
| 5832 | |
| 5833 | |
| 5834 | |
| 5835 | QualType BaseType; |
| 5836 | |
| 5837 | |
| 5838 | mutable llvm::PointerIntPair<const ObjCObjectType *, 1, bool> |
| 5839 | CachedSuperClassType; |
| 5840 | |
| 5841 | QualType *getTypeArgStorage(); |
| 5842 | const QualType *getTypeArgStorage() const { |
| 5843 | return const_cast<ObjCObjectType *>(this)->getTypeArgStorage(); |
| 5844 | } |
| 5845 | |
| 5846 | ObjCProtocolDecl **getProtocolStorageImpl(); |
| 5847 | |
| 5848 | |
| 5849 | unsigned getNumProtocolsImpl() const { |
| 5850 | return ObjCObjectTypeBits.NumProtocols; |
| 5851 | } |
| 5852 | void setNumProtocolsImpl(unsigned N) { |
| 5853 | ObjCObjectTypeBits.NumProtocols = N; |
| 5854 | } |
| 5855 | |
| 5856 | protected: |
| 5857 | enum Nonce_ObjCInterface { Nonce_ObjCInterface }; |
| 5858 | |
| 5859 | ObjCObjectType(QualType Canonical, QualType Base, |
| 5860 | ArrayRef<QualType> typeArgs, |
| 5861 | ArrayRef<ObjCProtocolDecl *> protocols, |
| 5862 | bool isKindOf); |
| 5863 | |
| 5864 | ObjCObjectType(enum Nonce_ObjCInterface) |
| 5865 | : Type(ObjCInterface, QualType(), TypeDependence::None), |
| 5866 | BaseType(QualType(this_(), 0)) { |
| 5867 | ObjCObjectTypeBits.NumProtocols = 0; |
| 5868 | ObjCObjectTypeBits.NumTypeArgs = 0; |
| 5869 | ObjCObjectTypeBits.IsKindOf = 0; |
| 5870 | } |
| 5871 | |
| 5872 | void computeSuperClassTypeSlow() const; |
| 5873 | |
| 5874 | public: |
| 5875 | |
| 5876 | |
| 5877 | |
| 5878 | |
| 5879 | |
| 5880 | |
| 5881 | QualType getBaseType() const { return BaseType; } |
| 5882 | |
| 5883 | bool isObjCId() const { |
| 5884 | return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCId); |
| 5885 | } |
| 5886 | |
| 5887 | bool isObjCClass() const { |
| 5888 | return getBaseType()->isSpecificBuiltinType(BuiltinType::ObjCClass); |
| 5889 | } |
| 5890 | |
| 5891 | bool isObjCUnqualifiedId() const { return qual_empty() && isObjCId(); } |
| 5892 | bool isObjCUnqualifiedClass() const { return qual_empty() && isObjCClass(); } |
| 5893 | bool isObjCUnqualifiedIdOrClass() const { |
| 5894 | if (!qual_empty()) return false; |
| 5895 | if (const BuiltinType *T = getBaseType()->getAs<BuiltinType>()) |
| 5896 | return T->getKind() == BuiltinType::ObjCId || |
| 5897 | T->getKind() == BuiltinType::ObjCClass; |
| 5898 | return false; |
| 5899 | } |
| 5900 | bool isObjCQualifiedId() const { return !qual_empty() && isObjCId(); } |
| 5901 | bool isObjCQualifiedClass() const { return !qual_empty() && isObjCClass(); } |
| 5902 | |
| 5903 | |
| 5904 | |
| 5905 | ObjCInterfaceDecl *getInterface() const; |
| 5906 | |
| 5907 | |
| 5908 | |
| 5909 | bool isSpecialized() const; |
| 5910 | |
| 5911 | |
| 5912 | bool isSpecializedAsWritten() const { |
| 5913 | return ObjCObjectTypeBits.NumTypeArgs > 0; |
| 5914 | } |
| 5915 | |
| 5916 | |
| 5917 | |
| 5918 | bool isUnspecialized() const { return !isSpecialized(); } |
| 5919 | |
| 5920 | |
| 5921 | |
| 5922 | bool isUnspecializedAsWritten() const { return !isSpecializedAsWritten(); } |
| 5923 | |
| 5924 | |
| 5925 | ArrayRef<QualType> getTypeArgs() const; |
| 5926 | |
| 5927 | |
| 5928 | |
| 5929 | ArrayRef<QualType> getTypeArgsAsWritten() const { |
| 5930 | return llvm::makeArrayRef(getTypeArgStorage(), |
| 5931 | ObjCObjectTypeBits.NumTypeArgs); |
| 5932 | } |
| 5933 | |
| 5934 | |
| 5935 | bool isKindOfTypeAsWritten() const { return ObjCObjectTypeBits.IsKindOf; } |
| 5936 | |
| 5937 | |
| 5938 | bool isKindOfType() const; |
| 5939 | |
| 5940 | |
| 5941 | |
| 5942 | |
| 5943 | |
| 5944 | |
| 5945 | |
| 5946 | QualType getSuperClassType() const { |
| 5947 | if (!CachedSuperClassType.getInt()) |
| 5948 | computeSuperClassTypeSlow(); |
| 5949 | |
| 5950 | assert(CachedSuperClassType.getInt() && "Superclass not set?"); |
| 5951 | return QualType(CachedSuperClassType.getPointer(), 0); |
| 5952 | } |
| 5953 | |
| 5954 | |
| 5955 | |
| 5956 | QualType stripObjCKindOfTypeAndQuals(const ASTContext &ctx) const; |
| 5957 | |
| 5958 | bool isSugared() const { return false; } |
| 5959 | QualType desugar() const { return QualType(this, 0); } |
| 5960 | |
| 5961 | static bool classof(const Type *T) { |
| 5962 | return T->getTypeClass() == ObjCObject || |
| 5963 | T->getTypeClass() == ObjCInterface; |
| 5964 | } |
| 5965 | }; |
| 5966 | |
| 5967 | |
| 5968 | |
| 5969 | |
| 5970 | |
| 5971 | class ObjCObjectTypeImpl : public ObjCObjectType, public llvm::FoldingSetNode { |
| 5972 | friend class ASTContext; |
| 5973 | |
| 5974 | |
| 5975 | |
| 5976 | |
| 5977 | ObjCObjectTypeImpl(QualType Canonical, QualType Base, |
| 5978 | ArrayRef<QualType> typeArgs, |
| 5979 | ArrayRef<ObjCProtocolDecl *> protocols, |
| 5980 | bool isKindOf) |
| 5981 | : ObjCObjectType(Canonical, Base, typeArgs, protocols, isKindOf) {} |
| 5982 | |
| 5983 | public: |
| 5984 | void Profile(llvm::FoldingSetNodeID &ID); |
| 5985 | static void Profile(llvm::FoldingSetNodeID &ID, |
| 5986 | QualType Base, |
| 5987 | ArrayRef<QualType> typeArgs, |
| 5988 | ArrayRef<ObjCProtocolDecl *> protocols, |
| 5989 | bool isKindOf); |
| 5990 | }; |
| 5991 | |
| 5992 | inline QualType *ObjCObjectType::getTypeArgStorage() { |
| 5993 | return reinterpret_cast<QualType *>(static_cast<ObjCObjectTypeImpl*>(this)+1); |
| 5994 | } |
| 5995 | |
| 5996 | inline ObjCProtocolDecl **ObjCObjectType::getProtocolStorageImpl() { |
| 5997 | return reinterpret_cast<ObjCProtocolDecl**>( |
| 5998 | getTypeArgStorage() + ObjCObjectTypeBits.NumTypeArgs); |
| 5999 | } |
| 6000 | |
| 6001 | inline ObjCProtocolDecl **ObjCTypeParamType::getProtocolStorageImpl() { |
| 6002 | return reinterpret_cast<ObjCProtocolDecl**>( |
| 6003 | static_cast<ObjCTypeParamType*>(this)+1); |
| 6004 | } |
| 6005 | |
| 6006 | |
| 6007 | |
| 6008 | |
| 6009 | |
| 6010 | |
| 6011 | |
| 6012 | |
| 6013 | |
| 6014 | |
| 6015 | |
| 6016 | |
| 6017 | |
| 6018 | class ObjCInterfaceType : public ObjCObjectType { |
| 6019 | friend class ASTContext; |
| 6020 | friend class ASTReader; |
| 6021 | friend class ObjCInterfaceDecl; |
| 6022 | template <class T> friend class serialization::AbstractTypeReader; |
| 6023 | |
| 6024 | mutable ObjCInterfaceDecl *Decl; |
| 6025 | |
| 6026 | ObjCInterfaceType(const ObjCInterfaceDecl *D) |
| 6027 | : ObjCObjectType(Nonce_ObjCInterface), |
| 6028 | Decl(const_cast<ObjCInterfaceDecl*>(D)) {} |
| 6029 | |
| 6030 | public: |
| 6031 | |
| 6032 | ObjCInterfaceDecl *getDecl() const { return Decl; } |
| 6033 | |
| 6034 | bool isSugared() const { return false; } |
| 6035 | QualType desugar() const { return QualType(this, 0); } |
| 6036 | |
| 6037 | static bool classof(const Type *T) { |
| 6038 | return T->getTypeClass() == ObjCInterface; |
| 6039 | } |
| 6040 | |
| 6041 | |
| 6042 | |
| 6043 | |
| 6044 | |
| 6045 | enum { |
| 6046 | qual_iterator, |
| 6047 | qual_begin, |
| 6048 | qual_end, |
| 6049 | getNumProtocols, |
| 6050 | getProtocol |
| 6051 | }; |
| 6052 | }; |
| 6053 | |
| 6054 | inline ObjCInterfaceDecl *ObjCObjectType::getInterface() const { |
| 6055 | QualType baseType = getBaseType(); |
| 6056 | while (const auto *ObjT = baseType->getAs<ObjCObjectType>()) { |
| 6057 | if (const auto *T = dyn_cast<ObjCInterfaceType>(ObjT)) |
| 6058 | return T->getDecl(); |
| 6059 | |
| 6060 | baseType = ObjT->getBaseType(); |
| 6061 | } |
| 6062 | |
| 6063 | return nullptr; |
| 6064 | } |
| 6065 | |
| 6066 | |
| 6067 | |
| 6068 | |
| 6069 | |
| 6070 | |
| 6071 | |
| 6072 | |
| 6073 | |
| 6074 | |
| 6075 | class ObjCObjectPointerType : public Type, public llvm::FoldingSetNode { |
| 6076 | friend class ASTContext; |
| 6077 | |
| 6078 | QualType PointeeType; |
| 6079 | |
| 6080 | ObjCObjectPointerType(QualType Canonical, QualType Pointee) |
| 6081 | : Type(ObjCObjectPointer, Canonical, Pointee->getDependence()), |
| 6082 | PointeeType(Pointee) {} |
| 6083 | |
| 6084 | public: |
| 6085 | |
| 6086 | |
| 6087 | QualType getPointeeType() const { return PointeeType; } |
| 6088 | |
| 6089 | |
| 6090 | |
| 6091 | |
| 6092 | |
| 6093 | |
| 6094 | |
| 6095 | |
| 6096 | |
| 6097 | |
| 6098 | |
| 6099 | |
| 6100 | |
| 6101 | |
| 6102 | |
| 6103 | |
| 6104 | |
| 6105 | |
| 6106 | |
| 6107 | |
| 6108 | |
| 6109 | |
| 6110 | |
| 6111 | |
| 6112 | const ObjCObjectType *getObjectType() const { |
| 6113 | return PointeeType->castAs<ObjCObjectType>(); |
| 6114 | } |
| 6115 | |
| 6116 | |
| 6117 | |
| 6118 | |
| 6119 | |
| 6120 | |
| 6121 | const ObjCInterfaceType *getInterfaceType() const; |
| 6122 | |
| 6123 | |
| 6124 | |
| 6125 | |
| 6126 | |
| 6127 | ObjCInterfaceDecl *getInterfaceDecl() const { |
| 6128 | return getObjectType()->getInterface(); |
| 6129 | } |
| 6130 | |
| 6131 | |
| 6132 | |
| 6133 | bool isObjCIdType() const { |
| 6134 | return getObjectType()->isObjCUnqualifiedId(); |
| 6135 | } |
| 6136 | |
| 6137 | |
| 6138 | |
| 6139 | bool isObjCClassType() const { |
| 6140 | return getObjectType()->isObjCUnqualifiedClass(); |
| 6141 | } |
| 6142 | |
| 6143 | |
| 6144 | bool isObjCIdOrClassType() const { |
| 6145 | return getObjectType()->isObjCUnqualifiedIdOrClass(); |
| 6146 | } |
| 6147 | |
| 6148 | |
| 6149 | |
| 6150 | bool isObjCQualifiedIdType() const { |
| 6151 | return getObjectType()->isObjCQualifiedId(); |
| 6152 | } |
| 6153 | |
| 6154 | |
| 6155 | |
| 6156 | bool isObjCQualifiedClassType() const { |
| 6157 | return getObjectType()->isObjCQualifiedClass(); |
| 6158 | } |
| 6159 | |
| 6160 | |
| 6161 | bool isKindOfType() const { return getObjectType()->isKindOfType(); } |
| 6162 | |
| 6163 | |
| 6164 | bool isSpecialized() const { return getObjectType()->isSpecialized(); } |
| 6165 | |
| 6166 | |
| 6167 | bool isSpecializedAsWritten() const { |
| 6168 | return getObjectType()->isSpecializedAsWritten(); |
| 6169 | } |
| 6170 | |
| 6171 | |
| 6172 | bool isUnspecialized() const { return getObjectType()->isUnspecialized(); } |
| 6173 | |
| 6174 | |
| 6175 | |
| 6176 | bool isUnspecializedAsWritten() const { return !isSpecializedAsWritten(); } |
| 6177 | |
| 6178 | |
| 6179 | ArrayRef<QualType> getTypeArgs() const { |
| 6180 | return getObjectType()->getTypeArgs(); |
| 6181 | } |
| 6182 | |
| 6183 | |
| 6184 | ArrayRef<QualType> getTypeArgsAsWritten() const { |
| 6185 | return getObjectType()->getTypeArgsAsWritten(); |
| 6186 | } |
| 6187 | |
| 6188 | |
| 6189 | |
| 6190 | |
| 6191 | using qual_iterator = ObjCObjectType::qual_iterator; |
| 6192 | using qual_range = llvm::iterator_range<qual_iterator>; |
| 6193 | |
| 6194 | qual_range quals() const { return qual_range(qual_begin(), qual_end()); } |
| 6195 | |
| 6196 | qual_iterator qual_begin() const { |
| 6197 | return getObjectType()->qual_begin(); |
| 6198 | } |
| 6199 | |
| 6200 | qual_iterator qual_end() const { |
| 6201 | return getObjectType()->qual_end(); |
| 6202 | } |
| 6203 | |
| 6204 | bool qual_empty() const { return getObjectType()->qual_empty(); } |
| 6205 | |
| 6206 | |
| 6207 | unsigned getNumProtocols() const { |
| 6208 | return getObjectType()->getNumProtocols(); |
| 6209 | } |
| 6210 | |
| 6211 | |
| 6212 | ObjCProtocolDecl *getProtocol(unsigned I) const { |
| 6213 | return getObjectType()->getProtocol(I); |
| 6214 | } |
| 6215 | |
| 6216 | bool isSugared() const { return false; } |
| 6217 | QualType desugar() const { return QualType(this, 0); } |
| 6218 | |
| 6219 | |
| 6220 | |
| 6221 | |
| 6222 | |
| 6223 | |
| 6224 | |
| 6225 | QualType getSuperClassType() const; |
| 6226 | |
| 6227 | |
| 6228 | |
| 6229 | const ObjCObjectPointerType *stripObjCKindOfTypeAndQuals( |
| 6230 | const ASTContext &ctx) const; |
| 6231 | |
| 6232 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 6233 | Profile(ID, getPointeeType()); |
| 6234 | } |
| 6235 | |
| 6236 | static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { |
| 6237 | ID.AddPointer(T.getAsOpaquePtr()); |
| 6238 | } |
| 6239 | |
| 6240 | static bool classof(const Type *T) { |
| 6241 | return T->getTypeClass() == ObjCObjectPointer; |
| 6242 | } |
| 6243 | }; |
| 6244 | |
| 6245 | class AtomicType : public Type, public llvm::FoldingSetNode { |
| 6246 | friend class ASTContext; |
| 6247 | |
| 6248 | QualType ValueType; |
| 6249 | |
| 6250 | AtomicType(QualType ValTy, QualType Canonical) |
| 6251 | : Type(Atomic, Canonical, ValTy->getDependence()), ValueType(ValTy) {} |
| 6252 | |
| 6253 | public: |
| 6254 | |
| 6255 | |
| 6256 | QualType getValueType() const { return ValueType; } |
| 6257 | |
| 6258 | bool isSugared() const { return false; } |
| 6259 | QualType desugar() const { return QualType(this, 0); } |
| 6260 | |
| 6261 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 6262 | Profile(ID, getValueType()); |
| 6263 | } |
| 6264 | |
| 6265 | static void Profile(llvm::FoldingSetNodeID &ID, QualType T) { |
| 6266 | ID.AddPointer(T.getAsOpaquePtr()); |
| 6267 | } |
| 6268 | |
| 6269 | static bool classof(const Type *T) { |
| 6270 | return T->getTypeClass() == Atomic; |
| 6271 | } |
| 6272 | }; |
| 6273 | |
| 6274 | |
| 6275 | class PipeType : public Type, public llvm::FoldingSetNode { |
| 6276 | friend class ASTContext; |
| 6277 | |
| 6278 | QualType ElementType; |
| 6279 | bool isRead; |
| 6280 | |
| 6281 | PipeType(QualType elemType, QualType CanonicalPtr, bool isRead) |
| 6282 | : Type(Pipe, CanonicalPtr, elemType->getDependence()), |
| 6283 | ElementType(elemType), isRead(isRead) {} |
| 6284 | |
| 6285 | public: |
| 6286 | QualType getElementType() const { return ElementType; } |
| 6287 | |
| 6288 | bool isSugared() const { return false; } |
| 6289 | |
| 6290 | QualType desugar() const { return QualType(this, 0); } |
| 6291 | |
| 6292 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 6293 | Profile(ID, getElementType(), isReadOnly()); |
| 6294 | } |
| 6295 | |
| 6296 | static void Profile(llvm::FoldingSetNodeID &ID, QualType T, bool isRead) { |
| 6297 | ID.AddPointer(T.getAsOpaquePtr()); |
| 6298 | ID.AddBoolean(isRead); |
| 6299 | } |
| 6300 | |
| 6301 | static bool classof(const Type *T) { |
| 6302 | return T->getTypeClass() == Pipe; |
| 6303 | } |
| 6304 | |
| 6305 | bool isReadOnly() const { return isRead; } |
| 6306 | }; |
| 6307 | |
| 6308 | |
| 6309 | class ExtIntType final : public Type, public llvm::FoldingSetNode { |
| 6310 | friend class ASTContext; |
| 6311 | unsigned IsUnsigned : 1; |
| 6312 | unsigned NumBits : 24; |
| 6313 | |
| 6314 | protected: |
| 6315 | ExtIntType(bool isUnsigned, unsigned NumBits); |
| 6316 | |
| 6317 | public: |
| 6318 | bool isUnsigned() const { return IsUnsigned; } |
| 6319 | bool isSigned() const { return !IsUnsigned; } |
| 6320 | unsigned getNumBits() const { return NumBits; } |
| 6321 | |
| 6322 | bool isSugared() const { return false; } |
| 6323 | QualType desugar() const { return QualType(this, 0); } |
| 6324 | |
| 6325 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 6326 | Profile(ID, isUnsigned(), getNumBits()); |
| 6327 | } |
| 6328 | |
| 6329 | static void Profile(llvm::FoldingSetNodeID &ID, bool IsUnsigned, |
| 6330 | unsigned NumBits) { |
| 6331 | ID.AddBoolean(IsUnsigned); |
| 6332 | ID.AddInteger(NumBits); |
| 6333 | } |
| 6334 | |
| 6335 | static bool classof(const Type *T) { return T->getTypeClass() == ExtInt; } |
| 6336 | }; |
| 6337 | |
| 6338 | class DependentExtIntType final : public Type, public llvm::FoldingSetNode { |
| 6339 | friend class ASTContext; |
| 6340 | const ASTContext &Context; |
| 6341 | llvm::PointerIntPair<Expr*, 1, bool> ExprAndUnsigned; |
| 6342 | |
| 6343 | protected: |
| 6344 | DependentExtIntType(const ASTContext &Context, bool IsUnsigned, |
| 6345 | Expr *NumBits); |
| 6346 | |
| 6347 | public: |
| 6348 | bool isUnsigned() const; |
| 6349 | bool isSigned() const { return !isUnsigned(); } |
| 6350 | Expr *getNumBitsExpr() const; |
| 6351 | |
| 6352 | bool isSugared() const { return false; } |
| 6353 | QualType desugar() const { return QualType(this, 0); } |
| 6354 | |
| 6355 | void Profile(llvm::FoldingSetNodeID &ID) { |
| 6356 | Profile(ID, Context, isUnsigned(), getNumBitsExpr()); |
| 6357 | } |
| 6358 | static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context, |
| 6359 | bool IsUnsigned, Expr *NumBitsExpr); |
| 6360 | |
| 6361 | static bool classof(const Type *T) { |
| 6362 | return T->getTypeClass() == DependentExtInt; |
| 6363 | } |
| 6364 | }; |
| 6365 | |
| 6366 | |
| 6367 | class QualifierCollector : public Qualifiers { |
| 6368 | public: |
| 6369 | QualifierCollector(Qualifiers Qs = Qualifiers()) : Qualifiers(Qs) {} |
| 6370 | |
| 6371 | |
| 6372 | |
| 6373 | |
| 6374 | const Type *strip(QualType type) { |
| 6375 | addFastQualifiers(type.getLocalFastQualifiers()); |
| 6376 | if (!type.hasLocalNonFastQualifiers()) |
| 6377 | return type.getTypePtrUnsafe(); |
| 6378 | |
| 6379 | const ExtQuals *extQuals = type.getExtQualsUnsafe(); |
| 6380 | addConsistentQualifiers(extQuals->getQualifiers()); |
| 6381 | return extQuals->getBaseType(); |
| 6382 | } |
| 6383 | |
| 6384 | |
| 6385 | QualType apply(const ASTContext &Context, QualType QT) const; |
| 6386 | |
| 6387 | |
| 6388 | QualType apply(const ASTContext &Context, const Type* T) const; |
| 6389 | }; |
| 6390 | |
| 6391 | |
| 6392 | |
| 6393 | |
| 6394 | |
| 6395 | |
| 6396 | |
| 6397 | |
| 6398 | class alignas(8) TypeSourceInfo { |
| 6399 | |
| 6400 | |
| 6401 | friend class ASTContext; |
| 6402 | |
| 6403 | QualType Ty; |
| 6404 | |
| 6405 | TypeSourceInfo(QualType ty) : Ty(ty) {} |
| 6406 | |
| 6407 | public: |
| 6408 | |
| 6409 | QualType getType() const { return Ty; } |
| 6410 | |
| 6411 | |
| 6412 | TypeLoc getTypeLoc() const; |
| 6413 | |
| 6414 | |
| 6415 | void overrideType(QualType T) { Ty = T; } |
| 6416 | }; |
| 6417 | |
| 6418 | |
| 6419 | |
| 6420 | inline SplitQualType SplitQualType::getSingleStepDesugaredType() const { |
| 6421 | SplitQualType desugar = |
| 6422 | Ty->getLocallyUnqualifiedSingleStepDesugaredType().split(); |
| 6423 | desugar.Quals.addConsistentQualifiers(Quals); |
| 6424 | return desugar; |
| 6425 | } |
| 6426 | |
| 6427 | inline const Type *QualType::getTypePtr() const { |
| 6428 | return getCommonPtr()->BaseType; |
| 6429 | } |
| 6430 | |
| 6431 | inline const Type *QualType::getTypePtrOrNull() const { |
| 6432 | return (isNull() ? nullptr : getCommonPtr()->BaseType); |
| 6433 | } |
| 6434 | |
| 6435 | inline SplitQualType QualType::split() const { |
| 6436 | if (!hasLocalNonFastQualifiers()) |
| 6437 | return SplitQualType(getTypePtrUnsafe(), |
| 6438 | Qualifiers::fromFastMask(getLocalFastQualifiers())); |
| 6439 | |
| 6440 | const ExtQuals *eq = getExtQualsUnsafe(); |
| 6441 | Qualifiers qs = eq->getQualifiers(); |
| 6442 | qs.addFastQualifiers(getLocalFastQualifiers()); |
| 6443 | return SplitQualType(eq->getBaseType(), qs); |
| 6444 | } |
| 6445 | |
| 6446 | inline Qualifiers QualType::getLocalQualifiers() const { |
| 6447 | Qualifiers Quals; |
| 6448 | if (hasLocalNonFastQualifiers()) |
| 6449 | Quals = getExtQualsUnsafe()->getQualifiers(); |
| 6450 | Quals.addFastQualifiers(getLocalFastQualifiers()); |
| 6451 | return Quals; |
| 6452 | } |
| 6453 | |
| 6454 | inline Qualifiers QualType::getQualifiers() const { |
| 6455 | Qualifiers quals = getCommonPtr()->CanonicalType.getLocalQualifiers(); |
| 6456 | quals.addFastQualifiers(getLocalFastQualifiers()); |
| 6457 | return quals; |
| 6458 | } |
| 6459 | |
| 6460 | inline unsigned QualType::getCVRQualifiers() const { |
| 6461 | unsigned cvr = getCommonPtr()->CanonicalType.getLocalCVRQualifiers(); |
| 6462 | cvr |= getLocalCVRQualifiers(); |
| 6463 | return cvr; |
| 6464 | } |
| 6465 | |
| 6466 | inline QualType QualType::getCanonicalType() const { |
| 6467 | QualType canon = getCommonPtr()->CanonicalType; |
| 6468 | return canon.withFastQualifiers(getLocalFastQualifiers()); |
| 6469 | } |
| 6470 | |
| 6471 | inline bool QualType::isCanonical() const { |
| 6472 | return getTypePtr()->isCanonicalUnqualified(); |
| 6473 | } |
| 6474 | |
| 6475 | inline bool QualType::isCanonicalAsParam() const { |
| 6476 | if (!isCanonical()) return false; |
| 6477 | if (hasLocalQualifiers()) return false; |
| 6478 | |
| 6479 | const Type *T = getTypePtr(); |
| 6480 | if (T->isVariablyModifiedType() && T->hasSizedVLAType()) |
| 6481 | return false; |
| 6482 | |
| 6483 | return !isa<FunctionType>(T) && !isa<ArrayType>(T); |
| 6484 | } |
| 6485 | |
| 6486 | inline bool QualType::isConstQualified() const { |
| 6487 | return isLocalConstQualified() || |
| 6488 | getCommonPtr()->CanonicalType.isLocalConstQualified(); |
| 6489 | } |
| 6490 | |
| 6491 | inline bool QualType::isRestrictQualified() const { |
| 6492 | return isLocalRestrictQualified() || |
| 6493 | getCommonPtr()->CanonicalType.isLocalRestrictQualified(); |
| 6494 | } |
| 6495 | |
| 6496 | |
| 6497 | inline bool QualType::isVolatileQualified() const { |
| 6498 | return isLocalVolatileQualified() || |
| 6499 | getCommonPtr()->CanonicalType.isLocalVolatileQualified(); |
| 6500 | } |
| 6501 | |
| 6502 | inline bool QualType::hasQualifiers() const { |
| 6503 | return hasLocalQualifiers() || |
| 6504 | getCommonPtr()->CanonicalType.hasLocalQualifiers(); |
| 6505 | } |
| 6506 | |
| 6507 | inline QualType QualType::getUnqualifiedType() const { |
| 6508 | if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) |
| 6509 | return QualType(getTypePtr(), 0); |
| 6510 | |
| 6511 | return QualType(getSplitUnqualifiedTypeImpl(*this).Ty, 0); |
| 6512 | } |
| 6513 | |
| 6514 | inline SplitQualType QualType::getSplitUnqualifiedType() const { |
| 6515 | if (!getTypePtr()->getCanonicalTypeInternal().hasLocalQualifiers()) |
| 6516 | return split(); |
| 6517 | |
| 6518 | return getSplitUnqualifiedTypeImpl(*this); |
| 6519 | } |
| 6520 | |
| 6521 | inline void QualType::removeLocalConst() { |
| 6522 | removeLocalFastQualifiers(Qualifiers::Const); |
| 6523 | } |
| 6524 | |
| 6525 | inline void QualType::removeLocalRestrict() { |
| 6526 | removeLocalFastQualifiers(Qualifiers::Restrict); |
| 6527 | } |
| 6528 | |
| 6529 | inline void QualType::removeLocalVolatile() { |
| 6530 | removeLocalFastQualifiers(Qualifiers::Volatile); |
| 6531 | } |
| 6532 | |
| 6533 | inline void QualType::removeLocalCVRQualifiers(unsigned Mask) { |
| 6534 | assert(!(Mask & ~Qualifiers::CVRMask) && "mask has non-CVR bits"); |
| 6535 | static_assert((int)Qualifiers::CVRMask == (int)Qualifiers::FastMask, |
| 6536 | "Fast bits differ from CVR bits!"); |
| 6537 | |
| 6538 | |
| 6539 | removeLocalFastQualifiers(Mask); |
| 6540 | } |
| 6541 | |
| 6542 | |
| 6543 | inline bool QualType::hasAddressSpace() const { |
| 6544 | return getQualifiers().hasAddressSpace(); |
| 6545 | } |
| 6546 | |
| 6547 | |
| 6548 | inline LangAS QualType::getAddressSpace() const { |
| 6549 | return getQualifiers().getAddressSpace(); |
| 6550 | } |
| 6551 | |
| 6552 | |
| 6553 | inline Qualifiers::GC QualType::getObjCGCAttr() const { |
| 6554 | return getQualifiers().getObjCGCAttr(); |
| 6555 | } |
| 6556 | |
| 6557 | inline bool QualType::hasNonTrivialToPrimitiveDefaultInitializeCUnion() const { |
| 6558 | if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl()) |
| 6559 | return hasNonTrivialToPrimitiveDefaultInitializeCUnion(RD); |
| 6560 | return false; |
| 6561 | } |
| 6562 | |
| 6563 | inline bool QualType::hasNonTrivialToPrimitiveDestructCUnion() const { |
| 6564 | if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl()) |
| 6565 | return hasNonTrivialToPrimitiveDestructCUnion(RD); |
| 6566 | return false; |
| 6567 | } |
| 6568 | |
| 6569 | inline bool QualType::hasNonTrivialToPrimitiveCopyCUnion() const { |
| 6570 | if (auto *RD = getTypePtr()->getBaseElementTypeUnsafe()->getAsRecordDecl()) |
| 6571 | return hasNonTrivialToPrimitiveCopyCUnion(RD); |
| 6572 | return false; |
| 6573 | } |
| 6574 | |
| 6575 | inline FunctionType::ExtInfo getFunctionExtInfo(const Type &t) { |
| 6576 | if (const auto *PT = t.getAs<PointerType>()) { |
| 6577 | if (const auto *FT = PT->getPointeeType()->getAs<FunctionType>()) |
| 6578 | return FT->getExtInfo(); |
| 6579 | } else if (const auto *FT = t.getAs<FunctionType>()) |
| 6580 | return FT->getExtInfo(); |
| 6581 | |
| 6582 | return FunctionType::ExtInfo(); |
| 6583 | } |
| 6584 | |
| 6585 | inline FunctionType::ExtInfo getFunctionExtInfo(QualType t) { |
| 6586 | return getFunctionExtInfo(*t); |
| 6587 | } |
| 6588 | |
| 6589 | |
| 6590 | |
| 6591 | |
| 6592 | |
| 6593 | |
| 6594 | inline bool QualType::isMoreQualifiedThan(QualType other) const { |
| 6595 | Qualifiers MyQuals = getQualifiers(); |
| 6596 | Qualifiers OtherQuals = other.getQualifiers(); |
| 6597 | return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes(OtherQuals)); |
| 6598 | } |
| 6599 | |
| 6600 | |
| 6601 | |
| 6602 | |
| 6603 | |
| 6604 | inline bool QualType::isAtLeastAsQualifiedAs(QualType other) const { |
| 6605 | Qualifiers OtherQuals = other.getQualifiers(); |
| 6606 | |
| 6607 | |
| 6608 | if (getUnqualifiedType()->isVoidType()) |
| 6609 | OtherQuals.removeUnaligned(); |
| 6610 | |
| 6611 | return getQualifiers().compatiblyIncludes(OtherQuals); |
| 6612 | } |
| 6613 | |
| 6614 | |
| 6615 | |
| 6616 | |
| 6617 | |
| 6618 | |
| 6619 | |
| 6620 | |
| 6621 | |
| 6622 | |
| 6623 | inline QualType QualType::getNonReferenceType() const { |
| 6624 | if (const auto *RefType = (*this)->getAs<ReferenceType>()) |
| 6625 | return RefType->getPointeeType(); |
| 6626 | else |
| 6627 | return *this; |
| 6628 | } |
| 6629 | |
| 6630 | inline bool QualType::isCForbiddenLValueType() const { |
| 6631 | return ((getTypePtr()->isVoidType() && !hasQualifiers()) || |
| 6632 | getTypePtr()->isFunctionType()); |
| 6633 | } |
| 6634 | |
| 6635 | |
| 6636 | |
| 6637 | |
| 6638 | inline bool Type::isFundamentalType() const { |
| 6639 | return isVoidType() || |
| 6640 | isNullPtrType() || |
| 6641 | |
| 6642 | |
| 6643 | (isArithmeticType() && !isEnumeralType()); |
| 6644 | } |
| 6645 | |
| 6646 | |
| 6647 | |
| 6648 | |
| 6649 | inline bool Type::isCompoundType() const { |
| 6650 | |
| 6651 | |
| 6652 | |
| 6653 | return isArrayType() || |
| 6654 | |
| 6655 | isFunctionType() || |
| 6656 | |
| 6657 | isPointerType() || |
| 6658 | |
| 6659 | isReferenceType() || |
| 6660 | |
| 6661 | isRecordType() || |
| 6662 | |
| 6663 | |
| 6664 | isUnionType() || |
| 6665 | |
| 6666 | isEnumeralType() || |
| 6667 | |
| 6668 | isMemberPointerType(); |
| 6669 | } |
| 6670 | |
| 6671 | inline bool Type::isFunctionType() const { |
| 6672 | return isa<FunctionType>(CanonicalType); |
| 6673 | } |
| 6674 | |
| 6675 | inline bool Type::isPointerType() const { |
| 6676 | return isa<PointerType>(CanonicalType); |
| 6677 | } |
| 6678 | |
| 6679 | inline bool Type::isAnyPointerType() const { |
| 6680 | return isPointerType() || isObjCObjectPointerType(); |
| 6681 | } |
| 6682 | |
| 6683 | inline bool Type::isBlockPointerType() const { |
| 6684 | return isa<BlockPointerType>(CanonicalType); |
| 6685 | } |
| 6686 | |
| 6687 | inline bool Type::isReferenceType() const { |
| 6688 | return isa<ReferenceType>(CanonicalType); |
| 6689 | } |
| 6690 | |
| 6691 | inline bool Type::isLValueReferenceType() const { |
| 6692 | return isa<LValueReferenceType>(CanonicalType); |
| 6693 | } |
| 6694 | |
| 6695 | inline bool Type::isRValueReferenceType() const { |
| 6696 | return isa<RValueReferenceType>(CanonicalType); |
| 6697 | } |
| 6698 | |
| 6699 | inline bool Type::isObjectPointerType() const { |
| 6700 | |
| 6701 | |
| 6702 | |
| 6703 | if (const auto *T = getAs<PointerType>()) |
| 6704 | return !T->getPointeeType()->isFunctionType(); |
| 6705 | else |
| 6706 | return false; |
| 6707 | } |
| 6708 | |
| 6709 | inline bool Type::isFunctionPointerType() const { |
| 6710 | if (const auto *T = getAs<PointerType>()) |
| 6711 | return T->getPointeeType()->isFunctionType(); |
| 6712 | else |
| 6713 | return false; |
| 6714 | } |
| 6715 | |
| 6716 | inline bool Type::isFunctionReferenceType() const { |
| 6717 | if (const auto *T = getAs<ReferenceType>()) |
| 6718 | return T->getPointeeType()->isFunctionType(); |
| 6719 | else |
| 6720 | return false; |
| 6721 | } |
| 6722 | |
| 6723 | inline bool Type::isMemberPointerType() const { |
| 6724 | return isa<MemberPointerType>(CanonicalType); |
| 6725 | } |
| 6726 | |
| 6727 | inline bool Type::isMemberFunctionPointerType() const { |
| 6728 | if (const auto *T = getAs<MemberPointerType>()) |
| 6729 | return T->isMemberFunctionPointer(); |
| 6730 | else |
| 6731 | return false; |
| 6732 | } |
| 6733 | |
| 6734 | inline bool Type::isMemberDataPointerType() const { |
| 6735 | if (const auto *T = getAs<MemberPointerType>()) |
| 6736 | return T->isMemberDataPointer(); |
| 6737 | else |
| 6738 | return false; |
| 6739 | } |
| 6740 | |
| 6741 | inline bool Type::isArrayType() const { |
| 6742 | return isa<ArrayType>(CanonicalType); |
| 6743 | } |
| 6744 | |
| 6745 | inline bool Type::isConstantArrayType() const { |
| 6746 | return isa<ConstantArrayType>(CanonicalType); |
| 6747 | } |
| 6748 | |
| 6749 | inline bool Type::isIncompleteArrayType() const { |
| 6750 | return isa<IncompleteArrayType>(CanonicalType); |
| 6751 | } |
| 6752 | |
| 6753 | inline bool Type::isVariableArrayType() const { |
| 6754 | return isa<VariableArrayType>(CanonicalType); |
| 6755 | } |
| 6756 | |
| 6757 | inline bool Type::isDependentSizedArrayType() const { |
| 6758 | return isa<DependentSizedArrayType>(CanonicalType); |
| 6759 | } |
| 6760 | |
| 6761 | inline bool Type::isBuiltinType() const { |
| 6762 | return isa<BuiltinType>(CanonicalType); |
| 6763 | } |
| 6764 | |
| 6765 | inline bool Type::isRecordType() const { |
| 6766 | return isa<RecordType>(CanonicalType); |
| 6767 | } |
| 6768 | |
| 6769 | inline bool Type::isEnumeralType() const { |
| 6770 | return isa<EnumType>(CanonicalType); |
| 6771 | } |
| 6772 | |
| 6773 | inline bool Type::isAnyComplexType() const { |
| 6774 | return isa<ComplexType>(CanonicalType); |
| 6775 | } |
| 6776 | |
| 6777 | inline bool Type::isVectorType() const { |
| 6778 | return isa<VectorType>(CanonicalType); |
| 6779 | } |
| 6780 | |
| 6781 | inline bool Type::isExtVectorType() const { |
| 6782 | return isa<ExtVectorType>(CanonicalType); |
| 6783 | } |
| 6784 | |
| 6785 | inline bool Type::isMatrixType() const { |
| 6786 | return isa<MatrixType>(CanonicalType); |
| 6787 | } |
| 6788 | |
| 6789 | inline bool Type::isConstantMatrixType() const { |
| 6790 | return isa<ConstantMatrixType>(CanonicalType); |
| 6791 | } |
| 6792 | |
| 6793 | inline bool Type::isDependentAddressSpaceType() const { |
| 6794 | return isa<DependentAddressSpaceType>(CanonicalType); |
| 6795 | } |
| 6796 | |
| 6797 | inline bool Type::isObjCObjectPointerType() const { |
| 6798 | return isa<ObjCObjectPointerType>(CanonicalType); |
| 6799 | } |
| 6800 | |
| 6801 | inline bool Type::isObjCObjectType() const { |
| 6802 | return isa<ObjCObjectType>(CanonicalType); |
| 6803 | } |
| 6804 | |
| 6805 | inline bool Type::isObjCObjectOrInterfaceType() const { |
| 6806 | return isa<ObjCInterfaceType>(CanonicalType) || |
| 6807 | isa<ObjCObjectType>(CanonicalType); |
| 6808 | } |
| 6809 | |
| 6810 | inline bool Type::isAtomicType() const { |
| 6811 | return isa<AtomicType>(CanonicalType); |
| 6812 | } |
| 6813 | |
| 6814 | inline bool Type::isUndeducedAutoType() const { |
| 6815 | return isa<AutoType>(CanonicalType); |
| 6816 | } |
| 6817 | |
| 6818 | inline bool Type::isObjCQualifiedIdType() const { |
| 6819 | if (const auto *OPT = getAs<ObjCObjectPointerType>()) |
| 6820 | return OPT->isObjCQualifiedIdType(); |
| 6821 | return false; |
| 6822 | } |
| 6823 | |
| 6824 | inline bool Type::isObjCQualifiedClassType() const { |
| 6825 | if (const auto *OPT = getAs<ObjCObjectPointerType>()) |
| 6826 | return OPT->isObjCQualifiedClassType(); |
| 6827 | return false; |
| 6828 | } |
| 6829 | |
| 6830 | inline bool Type::isObjCIdType() const { |
| 6831 | if (const auto *OPT = getAs<ObjCObjectPointerType>()) |
| 6832 | return OPT->isObjCIdType(); |
| 6833 | return false; |
| 6834 | } |
| 6835 | |
| 6836 | inline bool Type::isObjCClassType() const { |
| 6837 | if (const auto *OPT = getAs<ObjCObjectPointerType>()) |
| 6838 | return OPT->isObjCClassType(); |
| 6839 | return false; |
| 6840 | } |
| 6841 | |
| 6842 | inline bool Type::isObjCSelType() const { |
| 6843 | if (const auto *OPT = getAs<PointerType>()) |
| 6844 | return OPT->getPointeeType()->isSpecificBuiltinType(BuiltinType::ObjCSel); |
| 6845 | return false; |
| 6846 | } |
| 6847 | |
| 6848 | inline bool Type::isObjCBuiltinType() const { |
| 6849 | return isObjCIdType() || isObjCClassType() || isObjCSelType(); |
| 6850 | } |
| 6851 | |
| 6852 | inline bool Type::isDecltypeType() const { |
| 6853 | return isa<DecltypeType>(this); |
| 6854 | } |
| 6855 | |
| 6856 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ |
| 6857 | inline bool Type::is##Id##Type() const { \ |
| 6858 | return isSpecificBuiltinType(BuiltinType::Id); \ |
| 6859 | } |
| 6860 | #include "clang/Basic/OpenCLImageTypes.def" |
| 6861 | |
| 6862 | inline bool Type::isSamplerT() const { |
| 6863 | return isSpecificBuiltinType(BuiltinType::OCLSampler); |
| 6864 | } |
| 6865 | |
| 6866 | inline bool Type::isEventT() const { |
| 6867 | return isSpecificBuiltinType(BuiltinType::OCLEvent); |
| 6868 | } |
| 6869 | |
| 6870 | inline bool Type::isClkEventT() const { |
| 6871 | return isSpecificBuiltinType(BuiltinType::OCLClkEvent); |
| 6872 | } |
| 6873 | |
| 6874 | inline bool Type::isQueueT() const { |
| 6875 | return isSpecificBuiltinType(BuiltinType::OCLQueue); |
| 6876 | } |
| 6877 | |
| 6878 | inline bool Type::isReserveIDT() const { |
| 6879 | return isSpecificBuiltinType(BuiltinType::OCLReserveID); |
| 6880 | } |
| 6881 | |
| 6882 | inline bool Type::isImageType() const { |
| 6883 | #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) is##Id##Type() || |
| 6884 | return |
| 6885 | #include "clang/Basic/OpenCLImageTypes.def" |
| 6886 | false; |
| 6887 | } |
| 6888 | |
| 6889 | inline bool Type::isPipeType() const { |
| 6890 | return isa<PipeType>(CanonicalType); |
| 6891 | } |
| 6892 | |
| 6893 | inline bool Type::isExtIntType() const { |
| 6894 | return isa<ExtIntType>(CanonicalType); |
| 6895 | } |
| 6896 | |
| 6897 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ |
| 6898 | inline bool Type::is##Id##Type() const { \ |
| 6899 | return isSpecificBuiltinType(BuiltinType::Id); \ |
| 6900 | } |
| 6901 | #include "clang/Basic/OpenCLExtensionTypes.def" |
| 6902 | |
| 6903 | inline bool Type::isOCLIntelSubgroupAVCType() const { |
| 6904 | #define INTEL_SUBGROUP_AVC_TYPE(ExtType, Id) \ |
| 6905 | isOCLIntelSubgroupAVC##Id##Type() || |
| 6906 | return |
| 6907 | #include "clang/Basic/OpenCLExtensionTypes.def" |
| 6908 | false; |
| 6909 | } |
| 6910 | |
| 6911 | inline bool Type::isOCLExtOpaqueType() const { |
| 6912 | #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) is##Id##Type() || |
| 6913 | return |
| 6914 | #include "clang/Basic/OpenCLExtensionTypes.def" |
| 6915 | false; |
| 6916 | } |
| 6917 | |
| 6918 | inline bool Type::isOpenCLSpecificType() const { |
| 6919 | return isSamplerT() || isEventT() || isImageType() || isClkEventT() || |
| 6920 | isQueueT() || isReserveIDT() || isPipeType() || isOCLExtOpaqueType(); |
| 6921 | } |
| 6922 | |
| 6923 | inline bool Type::isTemplateTypeParmType() const { |
| 6924 | return isa<TemplateTypeParmType>(CanonicalType); |
| 6925 | } |
| 6926 | |
| 6927 | inline bool Type::isSpecificBuiltinType(unsigned K) const { |
| 6928 | if (const BuiltinType *BT = getAs<BuiltinType>()) { |
| 6929 | return BT->getKind() == static_cast<BuiltinType::Kind>(K); |
| 6930 | } |
| 6931 | return false; |
| 6932 | } |
| 6933 | |
| 6934 | inline bool Type::isPlaceholderType() const { |
| 6935 | if (const auto *BT = dyn_cast<BuiltinType>(this)) |
| 6936 | return BT->isPlaceholderType(); |
| 6937 | return false; |
| 6938 | } |
| 6939 | |
| 6940 | inline const BuiltinType *Type::getAsPlaceholderType() const { |
| 6941 | if (const auto *BT = dyn_cast<BuiltinType>(this)) |
| 6942 | if (BT->isPlaceholderType()) |
| 6943 | return BT; |
| 6944 | return nullptr; |
| 6945 | } |
| 6946 | |
| 6947 | inline bool Type::isSpecificPlaceholderType(unsigned K) const { |
| 6948 | assert(BuiltinType::isPlaceholderTypeKind((BuiltinType::Kind) K)); |
| 6949 | return isSpecificBuiltinType(K); |
| 6950 | } |
| 6951 | |
| 6952 | inline bool Type::isNonOverloadPlaceholderType() const { |
| 6953 | if (const auto *BT = dyn_cast<BuiltinType>(this)) |
| 6954 | return BT->isNonOverloadPlaceholderType(); |
| 6955 | return false; |
| 6956 | } |
| 6957 | |
| 6958 | inline bool Type::isVoidType() const { |
| 6959 | return isSpecificBuiltinType(BuiltinType::Void); |
| 6960 | } |
| 6961 | |
| 6962 | inline bool Type::isHalfType() const { |
| 6963 | |
| 6964 | return isSpecificBuiltinType(BuiltinType::Half); |
| 6965 | } |
| 6966 | |
| 6967 | inline bool Type::isFloat16Type() const { |
| 6968 | return isSpecificBuiltinType(BuiltinType::Float16); |
| 6969 | } |
| 6970 | |
| 6971 | inline bool Type::isBFloat16Type() const { |
| 6972 | return isSpecificBuiltinType(BuiltinType::BFloat16); |
| 6973 | } |
| 6974 | |
| 6975 | inline bool Type::isFloat128Type() const { |
| 6976 | return isSpecificBuiltinType(BuiltinType::Float128); |
| 6977 | } |
| 6978 | |
| 6979 | inline bool Type::isNullPtrType() const { |
| 6980 | return isSpecificBuiltinType(BuiltinType::NullPtr); |
| 6981 | } |
| 6982 | |
| 6983 | bool IsEnumDeclComplete(EnumDecl *); |
| 6984 | bool IsEnumDeclScoped(EnumDecl *); |
| 6985 | |
| 6986 | inline bool Type::isIntegerType() const { |
| 6987 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 6988 | return BT->getKind() >= BuiltinType::Bool && |
| 6989 | BT->getKind() <= BuiltinType::Int128; |
| 6990 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) { |
| 6991 | |
| 6992 | |
| 6993 | return IsEnumDeclComplete(ET->getDecl()) && |
| 6994 | !IsEnumDeclScoped(ET->getDecl()); |
| 6995 | } |
| 6996 | return isExtIntType(); |
| 6997 | } |
| 6998 | |
| 6999 | inline bool Type::isFixedPointType() const { |
| 7000 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 7001 | return BT->getKind() >= BuiltinType::ShortAccum && |
| 7002 | BT->getKind() <= BuiltinType::SatULongFract; |
| 7003 | } |
| 7004 | return false; |
| 7005 | } |
| 7006 | |
| 7007 | inline bool Type::isFixedPointOrIntegerType() const { |
| 7008 | return isFixedPointType() || isIntegerType(); |
| 7009 | } |
| 7010 | |
| 7011 | inline bool Type::isSaturatedFixedPointType() const { |
| 7012 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 7013 | return BT->getKind() >= BuiltinType::SatShortAccum && |
| 7014 | BT->getKind() <= BuiltinType::SatULongFract; |
| 7015 | } |
| 7016 | return false; |
| 7017 | } |
| 7018 | |
| 7019 | inline bool Type::isUnsaturatedFixedPointType() const { |
| 7020 | return isFixedPointType() && !isSaturatedFixedPointType(); |
| 7021 | } |
| 7022 | |
| 7023 | inline bool Type::isSignedFixedPointType() const { |
| 7024 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) { |
| 7025 | return ((BT->getKind() >= BuiltinType::ShortAccum && |
| 7026 | BT->getKind() <= BuiltinType::LongAccum) || |
| 7027 | (BT->getKind() >= BuiltinType::ShortFract && |
| 7028 | BT->getKind() <= BuiltinType::LongFract) || |
| 7029 | (BT->getKind() >= BuiltinType::SatShortAccum && |
| 7030 | BT->getKind() <= BuiltinType::SatLongAccum) || |
| 7031 | (BT->getKind() >= BuiltinType::SatShortFract && |
| 7032 | BT->getKind() <= BuiltinType::SatLongFract)); |
| 7033 | } |
| 7034 | return false; |
| 7035 | } |
| 7036 | |
| 7037 | inline bool Type::isUnsignedFixedPointType() const { |
| 7038 | return isFixedPointType() && !isSignedFixedPointType(); |
| 7039 | } |
| 7040 | |
| 7041 | inline bool Type::isScalarType() const { |
| 7042 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 7043 | return BT->getKind() > BuiltinType::Void && |
| 7044 | BT->getKind() <= BuiltinType::NullPtr; |
| 7045 | if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) |
| 7046 | |
| 7047 | |
| 7048 | return IsEnumDeclComplete(ET->getDecl()); |
| 7049 | return isa<PointerType>(CanonicalType) || |
| 7050 | isa<BlockPointerType>(CanonicalType) || |
| 7051 | isa<MemberPointerType>(CanonicalType) || |
| 7052 | isa<ComplexType>(CanonicalType) || |
| 7053 | isa<ObjCObjectPointerType>(CanonicalType) || |
| 7054 | isExtIntType(); |
| 7055 | } |
| 7056 | |
| 7057 | inline bool Type::isIntegralOrEnumerationType() const { |
| 7058 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 7059 | return BT->getKind() >= BuiltinType::Bool && |
| 7060 | BT->getKind() <= BuiltinType::Int128; |
| 7061 | |
| 7062 | |
| 7063 | |
| 7064 | if (const auto *ET = dyn_cast<EnumType>(CanonicalType)) |
| 7065 | return IsEnumDeclComplete(ET->getDecl()); |
| 7066 | |
| 7067 | return isExtIntType(); |
| 7068 | } |
| 7069 | |
| 7070 | inline bool Type::isBooleanType() const { |
| 7071 | if (const auto *BT = dyn_cast<BuiltinType>(CanonicalType)) |
| 7072 | return BT->getKind() == BuiltinType::Bool; |
| 7073 | return false; |
| 7074 | } |
| 7075 | |
| 7076 | inline bool Type::isUndeducedType() const { |
| 7077 | auto *DT = getContainedDeducedType(); |
| 7078 | return DT && !DT->isDeduced(); |
| 7079 | } |
| 7080 | |
| 7081 | |
| 7082 | |
| 7083 | inline bool Type::isOverloadableType() const { |
| 7084 | return isDependentType() || isRecordType() || isEnumeralType(); |
| 7085 | } |
| 7086 | |
| 7087 | |
| 7088 | inline bool Type::isTypedefNameType() const { |
| 7089 | if (getAs<TypedefType>()) |
| 7090 | return true; |
| 7091 | if (auto *TST = getAs<TemplateSpecializationType>()) |
| 7092 | return TST->isTypeAlias(); |
| 7093 | return false; |
| 7094 | } |
| 7095 | |
| 7096 | |
| 7097 | inline bool Type::canDecayToPointerType() const { |
| 7098 | return isFunctionType() || isArrayType(); |
| 7099 | } |
| 7100 | |
| 7101 | inline bool Type::hasPointerRepresentation() const { |
| 7102 | return (isPointerType() || isReferenceType() || isBlockPointerType() || |
| 7103 | isObjCObjectPointerType() || isNullPtrType()); |
| 7104 | } |
| 7105 | |
| 7106 | inline bool Type::hasObjCPointerRepresentation() const { |
| 7107 | return isObjCObjectPointerType(); |
| 7108 | } |
| 7109 | |
| 7110 | inline const Type *Type::getBaseElementTypeUnsafe() const { |
| 7111 | const Type *type = this; |
| 7112 | while (const ArrayType *arrayType = type->getAsArrayTypeUnsafe()) |
| 7113 | type = arrayType->getElementType().getTypePtr(); |
| 7114 | return type; |
| 7115 | } |
| 7116 | |
| 7117 | inline const Type *Type::getPointeeOrArrayElementType() const { |
| 7118 | const Type *type = this; |
| 7119 | if (type->isAnyPointerType()) |
| 7120 | return type->getPointeeType().getTypePtr(); |
| 7121 | else if (type->isArrayType()) |
| 7122 | return type->getBaseElementTypeUnsafe(); |
| 7123 | return type; |
| 7124 | } |
| 7125 | |
| 7126 | |
| 7127 | inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD, |
| 7128 | LangAS AS) { |
| 7129 | PD.AddTaggedVal(static_cast<std::underlying_type_t<LangAS>>(AS), |
| 7130 | DiagnosticsEngine::ArgumentKind::ak_addrspace); |
| 7131 | return PD; |
| 7132 | } |
| 7133 | |
| 7134 | |
| 7135 | |
| 7136 | inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD, |
| 7137 | Qualifiers Q) { |
| 7138 | PD.AddTaggedVal(Q.getAsOpaqueValue(), |
| 7139 | DiagnosticsEngine::ArgumentKind::ak_qual); |
| 7140 | return PD; |
| 7141 | } |
| 7142 | |
| 7143 | |
| 7144 | |
| 7145 | inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD, |
| 7146 | QualType T) { |
| 7147 | PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), |
| 7148 | DiagnosticsEngine::ak_qualtype); |
| 7149 | return PD; |
| 7150 | } |
| 7151 | |
| 7152 | |
| 7153 | |
| 7154 | template <typename T> |
| 7155 | using TypeIsArrayType = |
| 7156 | std::integral_constant<bool, std::is_same<T, ArrayType>::value || |
| 7157 | std::is_base_of<ArrayType, T>::value>; |
| 7158 | |
| 7159 | |
| 7160 | template <typename T> const T *Type::getAs() const { |
| 7161 | static_assert(!TypeIsArrayType<T>::value, |
| 7162 | "ArrayType cannot be used with getAs!"); |
| 7163 | |
| 7164 | |
| 7165 | if (const auto *Ty = dyn_cast<T>(this)) |
| 7166 | return Ty; |
| 7167 | |
| 7168 | |
| 7169 | if (!isa<T>(CanonicalType)) |
| 7170 | return nullptr; |
| 7171 | |
| 7172 | |
| 7173 | |
| 7174 | return cast<T>(getUnqualifiedDesugaredType()); |
| 7175 | } |
| 7176 | |
| 7177 | template <typename T> const T *Type::getAsAdjusted() const { |
| 7178 | static_assert(!TypeIsArrayType<T>::value, "ArrayType cannot be used with getAsAdjusted!"); |
| 7179 | |
| 7180 | |
| 7181 | if (const auto *Ty = dyn_cast<T>(this)) |
| 7182 | return Ty; |
| 7183 | |
| 7184 | |
| 7185 | if (!isa<T>(CanonicalType)) |
| 7186 | return nullptr; |
| 7187 | |
| 7188 | |
| 7189 | |
| 7190 | const Type *Ty = this; |
| 7191 | while (Ty) { |
| 7192 | if (const auto *A = dyn_cast<AttributedType>(Ty)) |
| 7193 | Ty = A->getModifiedType().getTypePtr(); |
| 7194 | else if (const auto *E = dyn_cast<ElaboratedType>(Ty)) |
| 7195 | Ty = E->desugar().getTypePtr(); |
| 7196 | else if (const auto *P = dyn_cast<ParenType>(Ty)) |
| 7197 | Ty = P->desugar().getTypePtr(); |
| 7198 | else if (const auto *A = dyn_cast<AdjustedType>(Ty)) |
| 7199 | Ty = A->desugar().getTypePtr(); |
| 7200 | else if (const auto *M = dyn_cast<MacroQualifiedType>(Ty)) |
| 7201 | Ty = M->desugar().getTypePtr(); |
| 7202 | else |
| 7203 | break; |
| 7204 | } |
| 7205 | |
| 7206 | |
| 7207 | |
| 7208 | return dyn_cast<T>(Ty); |
| 7209 | } |
| 7210 | |
| 7211 | inline const ArrayType *Type::getAsArrayTypeUnsafe() const { |
| 7212 | |
| 7213 | if (const auto *arr = dyn_cast<ArrayType>(this)) |
| 7214 | return arr; |
| 7215 | |
| 7216 | |
| 7217 | if (!isa<ArrayType>(CanonicalType)) |
| 7218 | return nullptr; |
| 7219 | |
| 7220 | |
| 7221 | |
| 7222 | return cast<ArrayType>(getUnqualifiedDesugaredType()); |
| 7223 | } |
| 7224 | |
| 7225 | template <typename T> const T *Type::castAs() const { |
| 7226 | static_assert(!TypeIsArrayType<T>::value, |
| 7227 | "ArrayType cannot be used with castAs!"); |
| 7228 | |
| 7229 | if (const auto *ty = dyn_cast<T>(this)) return ty; |
| 7230 | assert(isa<T>(CanonicalType)); |
| 7231 | return cast<T>(getUnqualifiedDesugaredType()); |
| 7232 | } |
| 7233 | |
| 7234 | inline const ArrayType *Type::castAsArrayTypeUnsafe() const { |
| 7235 | assert(isa<ArrayType>(CanonicalType)); |
| 7236 | if (const auto *arr = dyn_cast<ArrayType>(this)) return arr; |
| 7237 | return cast<ArrayType>(getUnqualifiedDesugaredType()); |
| 7238 | } |
| 7239 | |
| 7240 | DecayedType::DecayedType(QualType OriginalType, QualType DecayedPtr, |
| 7241 | QualType CanonicalPtr) |
| 7242 | : AdjustedType(Decayed, OriginalType, DecayedPtr, CanonicalPtr) { |
| 7243 | #ifndef NDEBUG |
| 7244 | QualType Adjusted = getAdjustedType(); |
| 7245 | (void)AttributedType::stripOuterNullability(Adjusted); |
| 7246 | assert(isa<PointerType>(Adjusted)); |
| 7247 | #endif |
| 7248 | } |
| 7249 | |
| 7250 | QualType DecayedType::getPointeeType() const { |
| 7251 | QualType Decayed = getDecayedType(); |
| 7252 | (void)AttributedType::stripOuterNullability(Decayed); |
| 7253 | return cast<PointerType>(Decayed)->getPointeeType(); |
| 7254 | } |
| 7255 | |
| 7256 | |
| 7257 | |
| 7258 | |
| 7259 | |
| 7260 | void FixedPointValueToString(SmallVectorImpl<char> &Str, llvm::APSInt Val, |
| 7261 | unsigned Scale); |
| 7262 | |
| 7263 | } |
| 7264 | |
| 7265 | #endif // LLVM_CLANG_AST_TYPE_H |