-
Notifications
You must be signed in to change notification settings - Fork 14k
[C++20][Modules] Load function body from the module that gives canonical decl #111992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dmpolukhin
merged 9 commits into
llvm:main
from
dmpolukhin:assert-not-instantiated-in-scope-cxx-modules4
Dec 16, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d71fb50
[C++20][Modules] Load function body from the module that gives cannon…
dmpolukhin a91a49b
Add test case
dmpolukhin 2818867
Use mechanism for deserializing related decl
dmpolukhin 9ecc0db
Use canonical decl as a template for instantiation
dmpolukhin 0dda28d
Add test for the latest reproducer
dmpolukhin efb41e6
Add forgotten use of non-canonical TemplatedDecl
dmpolukhin c3aeec3
Limit scope of the change to inline friend functions.
dmpolukhin 7aa4c05
Fix formatting issue
dmpolukhin 5df865a
Fix minor formatting issue + rebase
dmpolukhin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -798,6 +798,17 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) { | |
} | ||
} | ||
|
||
if (D->getFriendObjectKind()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As stated in #122493 (comment), this is intended. It would be helpful to include comments explaining why this logic is applied exclusively to friend objects. |
||
// 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 { | ||
|
110 changes: 110 additions & 0 deletions
110
clang/test/Headers/crash-instantiated-in-scope-cxx-modules4.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// RUN: rm -fR %t | ||
// RUN: split-file %s %t | ||
// RUN: cd %t | ||
// RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map -fmodule-name=foo1 -emit-module modules.map -o foo1.pcm | ||
// RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map -fmodule-name=foo2 -emit-module modules.map -o foo2.pcm | ||
// RUN: %clang_cc1 -verify -std=c++20 -x c++ -fmodule-map-file=modules.map -fmodule-file=foo1.pcm -fmodule-file=foo2.pcm server.cc | ||
|
||
//--- functional | ||
#pragma once | ||
|
||
namespace std { | ||
template <class> class function {}; | ||
} // namespace std | ||
|
||
//--- foo.h | ||
#pragma once | ||
|
||
class MethodHandler { | ||
public: | ||
virtual ~MethodHandler() {} | ||
struct HandlerParameter { | ||
HandlerParameter(); | ||
}; | ||
virtual void RunHandler(const HandlerParameter ¶m); | ||
}; | ||
|
||
template <class RequestType, class ResponseType> | ||
class CallbackUnaryHandler : public MethodHandler { | ||
public: | ||
explicit CallbackUnaryHandler(); | ||
|
||
void RunHandler(const HandlerParameter ¶m) final { | ||
void *call = nullptr; | ||
(void)[call](bool){}; | ||
} | ||
}; | ||
|
||
//--- foo1.h | ||
// expected-no-diagnostics | ||
#pragma once | ||
|
||
#include "functional" | ||
|
||
#include "foo.h" | ||
|
||
class A; | ||
|
||
class ClientAsyncResponseReaderHelper { | ||
public: | ||
using t = std::function<void(A)>; | ||
static void SetupRequest(t finish); | ||
}; | ||
|
||
//--- foo2.h | ||
// expected-no-diagnostics | ||
#pragma once | ||
|
||
#include "foo.h" | ||
|
||
template <class BaseClass> | ||
class a : public BaseClass { | ||
public: | ||
a() { [[maybe_unused]] CallbackUnaryHandler<int, int> a; } | ||
}; | ||
|
||
//--- modules.map | ||
module "foo" { | ||
export * | ||
module "foo.h" { | ||
export * | ||
textual header "foo.h" | ||
} | ||
} | ||
|
||
module "foo1" { | ||
export * | ||
module "foo1.h" { | ||
export * | ||
header "foo1.h" | ||
} | ||
|
||
use "foo" | ||
} | ||
|
||
module "foo2" { | ||
export * | ||
module "foo2.h" { | ||
export * | ||
header "foo2.h" | ||
} | ||
|
||
use "foo" | ||
} | ||
|
||
//--- server.cc | ||
// expected-no-diagnostics | ||
#include "functional" | ||
|
||
#include "foo1.h" | ||
#include "foo2.h" | ||
|
||
std::function<void()> on_emit; | ||
|
||
template <class RequestType, class ResponseType> | ||
class CallbackUnaryHandler; | ||
|
||
class s {}; | ||
class hs final : public a<s> { | ||
explicit hs() {} | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the main decl? I can image some definitions, but it would be nice to have some clarifications included in the comment.