Skip to content

Commit 19e2174

Browse files
committed
Revert "[Clang] Eagerly instantiate used constexpr function upon definition. (#73463)"
This reverts commit 030047c. Breaks Qt and is inconsistent with GCC. See the following issue for details: Fixes #74069
1 parent 293c21d commit 19e2174

14 files changed

+2
-165
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -802,11 +802,6 @@ Bug Fixes to C++ Support
802802
- Fix crash when parsing nested requirement. Fixes:
803803
(`#73112 <https://github.com/llvm/llvm-project/issues/73112>`_)
804804

805-
- Clang now immediately instantiates function template specializations
806-
at the end of the definition of the corresponding function template
807-
when the definition appears after the first point of instantiation.
808-
(`#73232 <https://github.com/llvm/llvm-project/issues/73232>`_)
809-
810805
Bug Fixes to AST Handling
811806
^^^^^^^^^^^^^^^^^^^^^^^^^
812807
- Fixed an import failure of recursive friend class template.

clang/include/clang/Sema/ExternalSemaSource.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,6 @@ class ExternalSemaSource : public ExternalASTSource {
181181
SmallVectorImpl<std::pair<ValueDecl *,
182182
SourceLocation> > &Pending) {}
183183

184-
virtual void ReadPendingInstantiationsOfConstexprEntity(
185-
const NamedDecl *D, llvm::SmallSetVector<NamedDecl *, 4> &Decls){};
186-
187184
/// Read the set of late parsed template functions for this source.
188185
///
189186
/// The external source should insert its own late parsed template functions

clang/include/clang/Sema/MultiplexExternalSemaSource.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,6 @@ class MultiplexExternalSemaSource : public ExternalSemaSource {
319319
void ReadPendingInstantiations(
320320
SmallVectorImpl<std::pair<ValueDecl*, SourceLocation> >& Pending) override;
321321

322-
virtual void ReadPendingInstantiationsOfConstexprEntity(
323-
const NamedDecl *D, llvm::SmallSetVector<NamedDecl *, 4> &Decls) override;
324-
325322
/// Read the set of late parsed template functions for this source.
326323
///
327324
/// The external source should insert its own late parsed template functions

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
#include "clang/Sema/TypoCorrection.h"
6060
#include "clang/Sema/Weak.h"
6161
#include "llvm/ADT/ArrayRef.h"
62-
#include "llvm/ADT/DenseMap.h"
6362
#include "llvm/ADT/SetVector.h"
6463
#include "llvm/ADT/SmallBitVector.h"
6564
#include "llvm/ADT/SmallPtrSet.h"
@@ -10093,12 +10092,6 @@ class Sema final {
1009310092
/// but have not yet been performed.
1009410093
std::deque<PendingImplicitInstantiation> PendingInstantiations;
1009510094

10096-
/// Track constexpr functions referenced before they are (lexically) defined.
10097-
/// The key is the pattern, associated with a list of specialisations that
10098-
/// need to be instantiated when the pattern is defined.
10099-
llvm::DenseMap<NamedDecl *, SmallVector<NamedDecl *>>
10100-
PendingInstantiationsOfConstexprEntities;
10101-
1010210095
/// Queue of implicit template instantiations that cannot be performed
1010310096
/// eagerly.
1010410097
SmallVector<PendingImplicitInstantiation, 1> LateParsedInstantiations;
@@ -10417,9 +10410,6 @@ class Sema final {
1041710410
bool Recursive = false,
1041810411
bool DefinitionRequired = false,
1041910412
bool AtEndOfTU = false);
10420-
10421-
void PerformPendingInstantiationsOfConstexprFunctions(FunctionDecl *Template);
10422-
1042310413
VarTemplateSpecializationDecl *BuildVarTemplateInstantiation(
1042410414
VarTemplateDecl *VarTemplate, VarDecl *FromVar,
1042510415
const TemplateArgumentList &TemplateArgList,

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,10 +695,6 @@ enum ASTRecordTypes {
695695
/// Record code for an unterminated \#pragma clang assume_nonnull begin
696696
/// recorded in a preamble.
697697
PP_ASSUME_NONNULL_LOC = 67,
698-
699-
/// Record code for constexpr templated entities that have been used but not
700-
/// yet instantiated.
701-
PENDING_INSTANTIATIONS_OF_CONSTEXPR_ENTITIES = 68,
702698
};
703699

704700
/// Record types used within a source manager block.

clang/include/clang/Serialization/ASTReader.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -814,9 +814,6 @@ class ASTReader
814814
/// is the instantiation location.
815815
SmallVector<serialization::DeclID, 64> PendingInstantiations;
816816

817-
llvm::DenseMap<serialization::DeclID, std::set<serialization::DeclID>>
818-
PendingInstantiationsOfConstexprEntities;
819-
820817
//@}
821818

822819
/// \name DiagnosticsEngine-relevant special data
@@ -2104,9 +2101,6 @@ class ASTReader
21042101
SmallVectorImpl<std::pair<ValueDecl *,
21052102
SourceLocation>> &Pending) override;
21062103

2107-
virtual void ReadPendingInstantiationsOfConstexprEntity(
2108-
const NamedDecl *D, llvm::SmallSetVector<NamedDecl *, 4> &Decls) override;
2109-
21102104
void ReadLateParsedTemplates(
21112105
llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
21122106
&LPTMap) override;

clang/lib/Sema/MultiplexExternalSemaSource.cpp

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

313-
void MultiplexExternalSemaSource::ReadPendingInstantiationsOfConstexprEntity(
314-
const NamedDecl *D, llvm::SmallSetVector<NamedDecl *, 4> &Decls) {
315-
for (size_t i = 0; i < Sources.size(); ++i)
316-
Sources[i]->ReadPendingInstantiationsOfConstexprEntity(D, Decls);
317-
}
318-
319313
void MultiplexExternalSemaSource::ReadLateParsedTemplates(
320314
llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
321315
&LPTMap) {

clang/lib/Sema/SemaDecl.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16286,9 +16286,6 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
1628616286
if (FD && !FD->isDeleted())
1628716287
checkTypeSupport(FD->getType(), FD->getLocation(), FD);
1628816288

16289-
if (FD && FD->isConstexpr() && FD->isTemplated())
16290-
PerformPendingInstantiationsOfConstexprFunctions(FD);
16291-
1629216289
return dcl;
1629316290
}
1629416291

clang/lib/Sema/SemaExpr.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19053,17 +19053,12 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func,
1905319053
CodeSynthesisContexts.size())
1905419054
PendingLocalImplicitInstantiations.push_back(
1905519055
std::make_pair(Func, PointOfInstantiation));
19056-
else if (Func->isConstexpr()) {
19056+
else if (Func->isConstexpr())
1905719057
// Do not defer instantiations of constexpr functions, to avoid the
1905819058
// expression evaluator needing to call back into Sema if it sees a
1905919059
// call to such a function.
1906019060
InstantiateFunctionDefinition(PointOfInstantiation, Func);
19061-
if (!Func->isDefined()) {
19062-
PendingInstantiationsOfConstexprEntities
19063-
[Func->getTemplateInstantiationPattern()->getCanonicalDecl()]
19064-
.push_back(Func);
19065-
}
19066-
} else {
19061+
else {
1906719062
Func->setInstantiationIsPending(true);
1906819063
PendingInstantiations.push_back(
1906919064
std::make_pair(Func, PointOfInstantiation));

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6495,34 +6495,6 @@ void Sema::PerformPendingInstantiations(bool LocalOnly) {
64956495
PendingInstantiations.swap(delayedPCHInstantiations);
64966496
}
64976497

6498-
// Instantiate all referenced specializations of the given function template
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) {
6503-
6504-
auto InstantiateAll = [&](const auto &Range) {
6505-
for (NamedDecl *D : Range) {
6506-
FunctionDecl *Fun = cast<FunctionDecl>(D);
6507-
InstantiateFunctionDefinition(Fun->getPointOfInstantiation(), Fun);
6508-
}
6509-
};
6510-
6511-
auto It =
6512-
PendingInstantiationsOfConstexprEntities.find(Tpl->getCanonicalDecl());
6513-
if (It != PendingInstantiationsOfConstexprEntities.end()) {
6514-
auto Decls = std::move(It->second);
6515-
PendingInstantiationsOfConstexprEntities.erase(It);
6516-
InstantiateAll(Decls);
6517-
}
6518-
6519-
llvm::SmallSetVector<NamedDecl *, 4> Decls;
6520-
if (ExternalSource) {
6521-
ExternalSource->ReadPendingInstantiationsOfConstexprEntity(Tpl, Decls);
6522-
InstantiateAll(Decls);
6523-
}
6524-
}
6525-
65266498
void Sema::PerformDependentDiagnostics(const DeclContext *Pattern,
65276499
const MultiLevelTemplateArgumentList &TemplateArgs) {
65286500
for (auto *DD : Pattern->ddiags()) {

clang/lib/Serialization/ASTReader.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3709,19 +3709,6 @@ llvm::Error ASTReader::ReadASTBlock(ModuleFile &F,
37093709
}
37103710
break;
37113711

3712-
case PENDING_INSTANTIATIONS_OF_CONSTEXPR_ENTITIES:
3713-
if (Record.size() % 2 != 0)
3714-
return llvm::createStringError(
3715-
std::errc::illegal_byte_sequence,
3716-
"Invalid PENDING_INSTANTIATIONS_OF_CONSTEXPR_ENTITIES block");
3717-
3718-
for (unsigned I = 0, N = Record.size(); I != N; /* in loop */) {
3719-
DeclID Key = getGlobalDeclID(F, Record[I++]);
3720-
DeclID Value = getGlobalDeclID(F, Record[I++]);
3721-
PendingInstantiationsOfConstexprEntities[Key].insert(Value);
3722-
}
3723-
break;
3724-
37253712
case SEMA_DECL_REFS:
37263713
if (Record.size() != 3)
37273714
return llvm::createStringError(std::errc::illegal_byte_sequence,
@@ -8731,20 +8718,6 @@ void ASTReader::ReadPendingInstantiations(
87318718
PendingInstantiations.clear();
87328719
}
87338720

8734-
void ASTReader::ReadPendingInstantiationsOfConstexprEntity(
8735-
const NamedDecl *D, llvm::SmallSetVector<NamedDecl *, 4> &Decls) {
8736-
for (auto *Redecl : D->redecls()) {
8737-
if (!Redecl->isFromASTFile())
8738-
continue;
8739-
DeclID Id = Redecl->getGlobalID();
8740-
auto It = PendingInstantiationsOfConstexprEntities.find(Id);
8741-
if (It == PendingInstantiationsOfConstexprEntities.end())
8742-
continue;
8743-
for (DeclID InstantiationId : It->second)
8744-
Decls.insert(cast<NamedDecl>(GetDecl(InstantiationId)));
8745-
}
8746-
}
8747-
87488721
void ASTReader::ReadLateParsedTemplates(
87498722
llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
87508723
&LPTMap) {

clang/lib/Serialization/ASTWriter.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,6 @@ void ASTWriter::WriteBlockInfoBlock() {
849849
RECORD(SEMA_DECL_REFS);
850850
RECORD(WEAK_UNDECLARED_IDENTIFIERS);
851851
RECORD(PENDING_IMPLICIT_INSTANTIATIONS);
852-
RECORD(PENDING_INSTANTIATIONS_OF_CONSTEXPR_ENTITIES);
853852
RECORD(UPDATE_VISIBLE);
854853
RECORD(DECL_UPDATE_OFFSETS);
855854
RECORD(DECL_UPDATES);
@@ -4837,16 +4836,6 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
48374836
assert(SemaRef.PendingLocalImplicitInstantiations.empty() &&
48384837
"There are local ones at end of translation unit!");
48394838

4840-
// Build a record containing all pending instantiations of constexpr
4841-
// entities.
4842-
RecordData PendingInstantiationsOfConstexprEntities;
4843-
for (const auto &I : SemaRef.PendingInstantiationsOfConstexprEntities) {
4844-
for (const auto &Elem : I.second) {
4845-
AddDeclRef(I.first, PendingInstantiationsOfConstexprEntities);
4846-
AddDeclRef(Elem, PendingInstantiationsOfConstexprEntities);
4847-
}
4848-
}
4849-
48504839
// Build a record containing some declaration references.
48514840
RecordData SemaDeclRefs;
48524841
if (SemaRef.StdNamespace || SemaRef.StdBadAlloc || SemaRef.StdAlignValT) {
@@ -5164,11 +5153,6 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot,
51645153
if (!PendingInstantiations.empty())
51655154
Stream.EmitRecord(PENDING_IMPLICIT_INSTANTIATIONS, PendingInstantiations);
51665155

5167-
// Write the record containing pending instantiations of constexpr entities.
5168-
if (!PendingInstantiationsOfConstexprEntities.empty())
5169-
Stream.EmitRecord(PENDING_INSTANTIATIONS_OF_CONSTEXPR_ENTITIES,
5170-
PendingInstantiationsOfConstexprEntities);
5171-
51725156
// Write the record containing declaration references of Sema.
51735157
if (!SemaDeclRefs.empty())
51745158
Stream.EmitRecord(SEMA_DECL_REFS, SemaDeclRefs);

clang/test/PCH/instantiate-used-constexpr-function.cpp

Lines changed: 0 additions & 17 deletions
This file was deleted.

clang/test/SemaTemplate/instantiate-used-constexpr-function.cpp

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)