diff options
author | Dmitry Polukhin <34227995+dmpolukhin@users.noreply.github.com> | 2024-12-16 12:22:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-16 12:22:43 +0000 |
commit | 38b3d87bd384a469a6618ec6a971352cb4f813ba (patch) | |
tree | 722178de9dfaa4905e20dee69cd645192ce11880 /clang/lib/Serialization/ASTWriterDecl.cpp | |
parent | 671095b452365826b1ccb65483d6ae890a2a81f7 (diff) | |
download | llvm-38b3d87bd384a469a6618ec6a971352cb4f813ba.zip llvm-38b3d87bd384a469a6618ec6a971352cb4f813ba.tar.gz llvm-38b3d87bd384a469a6618ec6a971352cb4f813ba.tar.bz2 |
[C++20][Modules] Load function body from the module that gives canonical decl (#111992)
Summary:
Fix crash from reproducer provided in
https://github.com/llvm/llvm-project/pull/109167#issuecomment-2405289565
Also fix issues with merged inline friend functions merged during deserialization.
Test Plan: check-clang
Diffstat (limited to 'clang/lib/Serialization/ASTWriterDecl.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTWriterDecl.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index 68e2d6b..75c1d9a 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -798,6 +798,17 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) { } } + if (D->getFriendObjectKind()) { + // For a function defined inline within a class template, we have to force + // the canonical definition to be the one inside the canonical definition of + // the template. Remember this relation to deserialize them together. + if (auto *RD = dyn_cast<CXXRecordDecl>(D->getLexicalParent())) + if (RD->isDependentContext() && RD->isThisDeclarationADefinition()) { + Writer.RelatedDeclsMap[Writer.GetDeclRef(RD)].push_back( + Writer.GetDeclRef(D)); + } + } + Record.push_back(D->param_size()); for (auto *P : D->parameters()) Record.AddDeclRef(P); @@ -1563,7 +1574,7 @@ void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) { // For lambdas inside canonical FunctionDecl remember the mapping. if (auto FD = llvm::dyn_cast_or_null<FunctionDecl>(D->getDeclContext()); FD && FD->isCanonicalDecl()) { - Writer.FunctionToLambdasMap[Writer.GetDeclRef(FD)].push_back( + Writer.RelatedDeclsMap[Writer.GetDeclRef(FD)].push_back( Writer.GetDeclRef(D)); } } else { |