Michael Park 0689d23ab3
[C++20][Modules] Prevent premature calls to PassInterestingDeclsToConsumer() within FinishedDeserializing(). (#129982)
`ASTReader::FinishedDeserializing` uses `NumCurrentElementsDeserializing` to keep track of nested `Deserializing` RAII actions. The `FinishedDeserializing` only performs actions if it is the top-level `Deserializing` layer. This works fine in general, but there is a problematic edge case.

If a call to `redecls()` in `FinishedDeserializing` performs deserialization, we re-enter `FinishedDeserializing` while in the middle of the previous `FinishedDeserializing` call.

The known problematic part of this is that this inner `FinishedDeserializing` can go all the way to `PassInterestingDeclsToConsumer`, which operates on `PotentiallyInterestingDecls` data structure which contain decls that should be handled by the previous `FinishedDeserializing` stage.

The other shared data structures are also somewhat concerning at a high-level in that the inner `FinishedDeserializing` would be handling pending actions that are not "within its scope", but this part is not known to be problematic.

We already have a guard within `PassInterestingDeclsToConsumer` because we can end up with recursive deserialization within `PassInterestingDeclsToConsumer`. The implemented solution is to apply this guard to the portion of `FinishedDeserializing` that performs further deserialization as well. This ensures that recursive deserialization does not trigger `PassInterestingDeclsToConsumer` which may operate on entries that are not ready to be passed.
2025-03-15 23:03:20 -07:00

108 lines
1.3 KiB
C++

// If this test fails, it should be investigated under Debug builds.
// Before the PR, this test was violating an assertion.
// RUN: rm -rf %t
// RUN: mkdir -p %t
// RUN: split-file %s %t
// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules \
// RUN: -fmodule-map-file=%t/module.modulemap \
// RUN: -fmodules-cache-path=%t %t/a.cpp
//--- module.modulemap
module ebo {
header "ebo.h"
}
module fwd {
header "fwd.h"
}
module s {
header "s.h"
export *
}
module mod {
header "a.h"
header "b.h"
}
//--- ebo.h
#pragma once
namespace N { inline namespace __1 {
template <typename T>
struct EBO : T {
EBO() = default;
};
}}
//--- fwd.h
#pragma once
namespace N { inline namespace __1 {
template <typename T>
struct Empty;
template <typename T>
struct BS;
using S = BS<Empty<char>>;
}}
//--- s.h
#pragma once
#include "fwd.h"
#include "ebo.h"
namespace N { inline namespace __1 {
template <typename T>
struct Empty {};
template <typename T>
struct BS {
EBO<T> _;
void f();
};
extern template void BS<Empty<char>>::f();
}}
//--- b.h
#pragma once
#include "s.h"
struct B {
void f() {
N::S{}.f();
}
};
//--- a.h
#pragma once
#include "s.h"
struct A {
void f(int) {}
void f(const N::S &) {}
void g();
};
//--- a.cpp
#include "a.h"
void A::g() { f(0); }
// expected-no-diagnostics