aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/MultiplexExternalSemaSource.cpp
diff options
context:
space:
mode:
authorcor3ntin <corentinjabot@gmail.com>2023-11-30 08:45:05 +0100
committerGitHub <noreply@github.com>2023-11-30 08:45:05 +0100
commit030047c432cac133738be68fa0974f70e69dd58d (patch)
tree9e0e500d92fd0a6f05ab250c840fe2dedb0b5574 /clang/lib/Sema/MultiplexExternalSemaSource.cpp
parent8a66510fa73c1507c2a58338e180ddb075993a5a (diff)
downloadllvm-030047c432cac133738be68fa0974f70e69dd58d.zip
llvm-030047c432cac133738be68fa0974f70e69dd58d.tar.gz
llvm-030047c432cac133738be68fa0974f70e69dd58d.tar.bz2
[Clang] Eagerly instantiate used constexpr function upon definition. (#73463)
Despite CWG2497 not being resolved, it is reasonable to expect the following code to compile (and which is supported by other compilers) ```cpp template<typename T> constexpr T f(); constexpr int g() { return f<int>(); } // #1 template<typename T> constexpr T f() { return 123; } int k[g()]; // #2 ``` To that end, we eagerly instantiate all referenced specializations of constexpr functions when they are defined. We maintain a map of (pattern, [instantiations]) independent of `PendingInstantiations` to avoid having to iterate that list after each function definition. We should apply the same logic to constexpr variables, but I wanted to keep the PR small. Fixes #73232
Diffstat (limited to 'clang/lib/Sema/MultiplexExternalSemaSource.cpp')
-rw-r--r--clang/lib/Sema/MultiplexExternalSemaSource.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/Sema/MultiplexExternalSemaSource.cpp b/clang/lib/Sema/MultiplexExternalSemaSource.cpp
index 058e22c..d0d6a3a 100644
--- a/clang/lib/Sema/MultiplexExternalSemaSource.cpp
+++ b/clang/lib/Sema/MultiplexExternalSemaSource.cpp
@@ -310,6 +310,12 @@ void MultiplexExternalSemaSource::ReadPendingInstantiations(
Sources[i]->ReadPendingInstantiations(Pending);
}
+void MultiplexExternalSemaSource::ReadPendingInstantiationsOfConstexprEntity(
+ const NamedDecl *D, llvm::SmallSetVector<NamedDecl *, 4> &Decls) {
+ for (size_t i = 0; i < Sources.size(); ++i)
+ Sources[i]->ReadPendingInstantiationsOfConstexprEntity(D, Decls);
+};
+
void MultiplexExternalSemaSource::ReadLateParsedTemplates(
llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
&LPTMap) {