Author: Vaibhav Garg Date: 2020-09-04T11:39:04Z New Revision: 2c9dbcda4f71497d4a58020bb093af438fb6e967
URL: https://github.com/llvm/llvm-project/commit/2c9dbcda4f71497d4a58020bb093af438fb6e967 DIFF: https://github.com/llvm/llvm-project/commit/2c9dbcda4f71497d4a58020bb093af438fb6e967.diff LOG: [modules] Correctly parse LateParsedTemplates in case of dependent modules. While parsing LateParsedTemplates, Clang assumes that the Global DeclID matches with the Local DeclID of a Decl. This is not the case when we have multiple dependent modules , each having their own LateParsedTemplate section. In such a case, a Local/Global DeclID confusion occurs which leads to improper casting of FunctionDecl's. This commit creates a Vector to map the LateParsedTemplate section of each Module with their module file and therefore resolving the Global/Local DeclID confusion. Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D86514 Added: Modified: clang/include/clang/Serialization/ASTReader.h clang/lib/Serialization/ASTReader.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Serialization/ASTReader.h b/clang/include/clang/Serialization/ASTReader.h index b6892e295ac7..29c4f15e57b0 100644 --- a/clang/include/clang/Serialization/ASTReader.h +++ b/clang/include/clang/Serialization/ASTReader.h @@ -900,8 +900,9 @@ class ASTReader /// Delete expressions to analyze at the end of translation unit. SmallVector<uint64_t, 8> DelayedDeleteExprs; - // A list of late parsed template function data. - SmallVector<uint64_t, 1> LateParsedTemplates; + // A list of late parsed template function data with their module files. + SmallVector<std::pair<ModuleFile *, SmallVector<uint64_t, 1>>, 4> + LateParsedTemplates; /// The IDs of all decls to be checked for deferred diags. /// diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 55d68a7c6919..6f5fa67117c0 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -3722,7 +3722,9 @@ ASTReader::ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities) { } case LATE_PARSED_TEMPLATE: - LateParsedTemplates.append(Record.begin(), Record.end()); + LateParsedTemplates.emplace_back( + std::piecewise_construct, std::forward_as_tuple(&F), + std::forward_as_tuple(Record.begin(), Record.end())); break; case OPTIMIZE_PRAGMA_OPTIONS: @@ -8389,25 +8391,28 @@ void ASTReader::ReadPendingInstantiations( void ASTReader::ReadLateParsedTemplates( llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>> &LPTMap) { - for (unsigned Idx = 0, N = LateParsedTemplates.size(); Idx < N; - /* In loop */) { - FunctionDecl *FD = cast<FunctionDecl>(GetDecl(LateParsedTemplates[Idx++])); + for (auto &LPT : LateParsedTemplates) { + ModuleFile *FMod = LPT.first; + RecordDataImpl &LateParsed = LPT.second; + for (unsigned Idx = 0, N = LateParsed.size(); Idx < N; + /* In loop */) { + FunctionDecl *FD = + cast<FunctionDecl>(GetLocalDecl(*FMod, LateParsed[Idx++])); - auto LT = std::make_unique<LateParsedTemplate>(); - LT->D = GetDecl(LateParsedTemplates[Idx++]); + auto LT = std::make_unique<LateParsedTemplate>(); + LT->D = GetLocalDecl(*FMod, LateParsed[Idx++]); - ModuleFile *F = getOwningModuleFile(LT->D); - assert(F && "No module"); + ModuleFile *F = getOwningModuleFile(LT->D); + assert(F && "No module"); - unsigned TokN = LateParsedTemplates[Idx++]; - LT->Toks.reserve(TokN); - for (unsigned T = 0; T < TokN; ++T) - LT->Toks.push_back(ReadToken(*F, LateParsedTemplates, Idx)); + unsigned TokN = LateParsed[Idx++]; + LT->Toks.reserve(TokN); + for (unsigned T = 0; T < TokN; ++T) + LT->Toks.push_back(ReadToken(*F, LateParsed, Idx)); - LPTMap.insert(std::make_pair(FD, std::move(LT))); + LPTMap.insert(std::make_pair(FD, std::move(LT))); + } } - - LateParsedTemplates.clear(); } void ASTReader::LoadSelector(Selector Sel) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits