Skip to content

[C++20][Modules][Serialization] Delay marking pending incomplete decl chains until the end of finishPendingActions. #121245

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
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions clang/lib/Serialization/ASTReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10186,12 +10186,12 @@ void ASTReader::visitTopLevelModuleMaps(
}

void ASTReader::finishPendingActions() {
while (
!PendingIdentifierInfos.empty() || !PendingDeducedFunctionTypes.empty() ||
!PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() ||
!PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
!PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
!PendingObjCExtensionIvarRedeclarations.empty()) {
while (!PendingIdentifierInfos.empty() ||
!PendingDeducedFunctionTypes.empty() ||
!PendingDeducedVarTypes.empty() || !PendingDeclChains.empty() ||
!PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
!PendingUpdateRecords.empty() ||
!PendingObjCExtensionIvarRedeclarations.empty()) {
// If any identifiers with corresponding top-level declarations have
// been loaded, load those declarations now.
using TopLevelDeclsMap =
Expand Down Expand Up @@ -10239,13 +10239,6 @@ void ASTReader::finishPendingActions() {
}
PendingDeducedVarTypes.clear();

// For each decl chain that we wanted to complete while deserializing, mark
// it as "still needs to be completed".
for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
}
PendingIncompleteDeclChains.clear();

// Load pending declaration chains.
for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
loadPendingDeclChain(PendingDeclChains[I].first,
Expand Down Expand Up @@ -10483,6 +10476,12 @@ void ASTReader::finishPendingActions() {
for (auto *ND : PendingMergedDefinitionsToDeduplicate)
getContext().deduplicateMergedDefinitonsFor(ND);
PendingMergedDefinitionsToDeduplicate.clear();

// For each decl chain that we wanted to complete while deserializing, mark
// it as "still needs to be completed".
for (Decl *D : PendingIncompleteDeclChains)
markIncompleteDeclChain(D);
PendingIncompleteDeclChains.clear();
}

void ASTReader::diagnoseOdrViolations() {
Expand Down
93 changes: 93 additions & 0 deletions clang/test/Modules/pr121245.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// If this test fails, it should be investigated under Debug builds.
// Before the PR, this test was encountering an `llvm_unreachable()`.

// RUN: rm -rf %t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment that the test results in llvm_unreachable in debug builds so debug build should be used to investigate problems with the test.

// RUN: mkdir -p %t
// RUN: split-file %s %t
// RUN: cd %t

// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-01.h \
// RUN: -fcxx-exceptions -o %t/hu-01.pcm

// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-02.h \
// RUN: -Wno-experimental-header-units -fcxx-exceptions \
// RUN: -fmodule-file=%t/hu-01.pcm -o %t/hu-02.pcm

// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-03.h \
// RUN: -Wno-experimental-header-units -fcxx-exceptions \
// RUN: -fmodule-file=%t/hu-01.pcm -o %t/hu-03.pcm

// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-04.h \
// RUN: -Wno-experimental-header-units -fcxx-exceptions \
// RUN: -fmodule-file=%t/hu-01.pcm -o %t/hu-04.pcm

// RUN: %clang_cc1 -std=c++20 -emit-header-unit -xc++-user-header %t/hu-05.h \
// RUN: -Wno-experimental-header-units -fcxx-exceptions \
// RUN: -fmodule-file=%t/hu-03.pcm -fmodule-file=%t/hu-04.pcm \
// RUN: -fmodule-file=%t/hu-01.pcm -o %t/hu-05.pcm

// RUN: %clang_cc1 -std=c++20 -emit-obj %t/main.cpp \
// RUN: -Wno-experimental-header-units -fcxx-exceptions \
// RUN: -fmodule-file=%t/hu-02.pcm -fmodule-file=%t/hu-05.pcm \
// RUN: -fmodule-file=%t/hu-04.pcm -fmodule-file=%t/hu-03.pcm \
// RUN: -fmodule-file=%t/hu-01.pcm

//--- hu-01.h
template <typename T>
struct A {
A() {}
~A() {}
};

template <typename T>
struct EBO : T {
EBO() = default;
};

template <typename T>
struct HT : EBO<A<T>> {};

//--- hu-02.h
import "hu-01.h";

inline void f() {
HT<int>();
}

//--- hu-03.h
import "hu-01.h";

struct C {
C();

HT<long> _;
};

//--- hu-04.h
import "hu-01.h";

void g(HT<long> = {});

//--- hu-05.h
import "hu-03.h";
import "hu-04.h";
import "hu-01.h";

struct B {
virtual ~B() = default;

virtual void f() {
HT<long>();
}
};

//--- main.cpp
import "hu-02.h";
import "hu-05.h";
import "hu-03.h";

int main() {
f();
C();
B();
}