Skip to content

Commit fb4eac5

Browse files
committed
Address Richard's feedback.
1 parent abdcef3 commit fb4eac5

File tree

10 files changed

+25
-22
lines changed

10 files changed

+25
-22
lines changed

clang/include/clang/Sema/ExternalSemaSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ class ExternalSemaSource : public ExternalASTSource {
181181
SmallVectorImpl<std::pair<ValueDecl *,
182182
SourceLocation> > &Pending) {}
183183

184-
virtual void ReadPendingOfInstantiationsForConstexprEntity(
184+
virtual void ReadPendingInstantiationsOfConstexprEntity(
185185
const NamedDecl *D, llvm::SmallSetVector<NamedDecl *, 4> &Decls){};
186186

187187
/// Read the set of late parsed template functions for this source.

clang/include/clang/Sema/MultiplexExternalSemaSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class MultiplexExternalSemaSource : public ExternalSemaSource {
319319
void ReadPendingInstantiations(
320320
SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending) override;
321321

322-
virtual void ReadPendingOfInstantiationsForConstexprEntity(
322+
virtual void ReadPendingInstantiationsOfConstexprEntity(
323323
const NamedDecl *D, llvm::SmallSetVector<NamedDecl *, 4> &Decls) override;
324324

325325
/// Read the set of late parsed template functions for this source.

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10413,8 +10413,7 @@ class Sema final {
1041310413
bool DefinitionRequired = false,
1041410414
bool AtEndOfTU = false);
1041510415

10416-
void InstantiateFunctionTemplateSpecializations(
10417-
SourceLocation PointOfInstantiation, FunctionDecl *Template);
10416+
void PerformPendingInstantiationsOfConstexprFunctions(FunctionDecl *Template);
1041810417

1041910418
VarTemplateSpecializationDecl *BuildVarTemplateInstantiation(
1042010419
VarTemplateDecl *VarTemplate, VarDecl *FromVar,

clang/include/clang/Serialization/ASTReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2104,7 +2104,7 @@ class ASTReader
21042104
SmallVectorImpl<std::pair<ValueDecl *,
21052105
SourceLocation>> &Pending) override;
21062106

2107-
virtual void ReadPendingOfInstantiationsForConstexprEntity(
2107+
virtual void ReadPendingInstantiationsOfConstexprEntity(
21082108
const NamedDecl *D, llvm::SmallSetVector<NamedDecl *, 4> &Decls) override;
21092109

21102110
void ReadLateParsedTemplates(

clang/lib/Sema/MultiplexExternalSemaSource.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@ void MultiplexExternalSemaSource::ReadPendingInstantiations(
310310
Sources[i]->ReadPendingInstantiations(Pending);
311311
}
312312

313-
void MultiplexExternalSemaSource::ReadPendingOfInstantiationsForConstexprEntity(
313+
void MultiplexExternalSemaSource::ReadPendingInstantiationsOfConstexprEntity(
314314
const NamedDecl *D, llvm::SmallSetVector<NamedDecl *, 4> &Decls) {
315315
for (size_t i = 0; i < Sources.size(); ++i)
316-
Sources[i]->ReadPendingOfInstantiationsForConstexprEntity(D, Decls);
316+
Sources[i]->ReadPendingInstantiationsOfConstexprEntity(D, Decls);
317317
};
318318

319319
void MultiplexExternalSemaSource::ReadLateParsedTemplates(

clang/lib/Sema/SemaDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16276,7 +16276,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
1627616276
checkTypeSupport(FD->getType(), FD->getLocation(), FD);
1627716277

1627816278
if (FD && FD->isConstexpr() && FD->isTemplated())
16279-
InstantiateFunctionTemplateSpecializations(FD->getEndLoc(), FD);
16279+
PerformPendingInstantiationsOfConstexprFunctions(FD);
1628016280

1628116281
return dcl;
1628216282
}

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6496,28 +6496,29 @@ void Sema::PerformPendingInstantiations(bool LocalOnly) {
64966496
}
64976497

64986498
// Instantiate all referenced specializations of the given function template
6499-
// definition. This make sure that function template that are defined after the
6500-
// point of instantiation of their used can be evaluated after they are defined.
6501-
// see CWG2497.
6502-
void Sema::InstantiateFunctionTemplateSpecializations(
6503-
SourceLocation PointOfInstantiation, FunctionDecl *Tpl) {
6499+
// definition. This make sure that constexpr function templates that are defined
6500+
// after the point of instantiation of their use can be evaluated after they
6501+
// are defined. see CWG2497.
6502+
void Sema::PerformPendingInstantiationsOfConstexprFunctions(FunctionDecl *Tpl) {
65046503

65056504
auto InstantiateAll = [&](const auto &Range) {
6506-
for (NamedDecl *Fun : Range) {
6507-
InstantiateFunctionDefinition(PointOfInstantiation,
6508-
cast<FunctionDecl>(Fun));
6505+
for (NamedDecl *D : Range) {
6506+
FunctionDecl *Fun = cast<FunctionDecl>(D);
6507+
InstantiateFunctionDefinition(Fun->getPointOfInstantiation(), Fun);
65096508
}
65106509
};
65116510

65126511
auto It =
65136512
PendingInstantiationsOfConstexprEntities.find(Tpl->getCanonicalDecl());
65146513
if (It != PendingInstantiationsOfConstexprEntities.end()) {
6515-
InstantiateAll(It->second);
6514+
auto Decls = std::move(It->second);
6515+
PendingInstantiationsOfConstexprEntities.erase(It);
6516+
InstantiateAll(Decls);
65166517
}
65176518

65186519
llvm::SmallSetVector<NamedDecl *, 4> Decls;
65196520
if (ExternalSource) {
6520-
ExternalSource->ReadPendingOfInstantiationsForConstexprEntity(Tpl, Decls);
6521+
ExternalSource->ReadPendingInstantiationsOfConstexprEntity(Tpl, Decls);
65216522
InstantiateAll(Decls);
65226523
}
65236524
}

clang/lib/Serialization/ASTReader.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8731,9 +8731,11 @@ void ASTReader::ReadPendingInstantiations(
87318731
PendingInstantiations.clear();
87328732
}
87338733

8734-
void ASTReader::ReadPendingOfInstantiationsForConstexprEntity(
8734+
void ASTReader::ReadPendingInstantiationsOfConstexprEntity(
87358735
const NamedDecl *D, llvm::SmallSetVector<NamedDecl *, 4> &Decls) {
87368736
for (auto *Redecl : D->redecls()) {
8737+
if (!Redecl->isFromASTFile())
8738+
continue;
87378739
DeclID Id = Redecl->getGlobalID();
87388740
auto It = PendingInstantiationsOfConstexprEntities.find(Id);
87398741
if (It == PendingInstantiationsOfConstexprEntities.end())

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4837,7 +4837,7 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
48374837
assert(SemaRef.PendingLocalImplicitInstantiations.empty() &&
48384838
"There are local ones at end of translation unit!");
48394839

4840-
// Build a record containing all of pending instantiations of constexpr
4840+
// Build a record containing all pending instantiations of constexpr
48414841
// entities.
48424842
RecordData PendingInstantiationsOfConstexprEntities;
48434843
for (const auto &I : SemaRef.PendingInstantiationsOfConstexprEntities) {

clang/test/SemaCXX/cxx2b-consteval-propagate.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,13 @@ template <typename T>
105105
constexpr int f(T t);
106106

107107
auto a = &f<char>;
108-
auto b = &f<int>; // expected-error {{immediate function 'f<int>' used before it is defined}}
108+
auto b = &f<int>; // expected-error {{immediate function 'f<int>' used before it is defined}} \
109+
// expected-note {{in instantiation of function template specialization}}
109110

110111
template <typename T>
111112
constexpr int f(T t) { // expected-note {{'f<int>' defined here}}
112113
return id(t); // expected-note {{'f<int>' is an immediate function because its body contains a call to a consteval function 'id' and that call is not a constant expression}}
113-
} // expected-note {{in instantiation of function template specialization}}
114+
}
114115

115116

116117

0 commit comments

Comments
 (0)