Skip to content

Commit 91dd4ec

Browse files
authored
Revert "[clang] Track function template instantiation from definition (#110387)" (#111764)
This reverts commit 4336f00.
1 parent ac3321f commit 91dd4ec

File tree

12 files changed

+26
-169
lines changed

12 files changed

+26
-169
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ Bug Fixes to C++ Support
468468
- Fixed an assertion failure in debug mode, and potential crashes in release mode, when
469469
diagnosing a failed cast caused indirectly by a failed implicit conversion to the type of the constructor parameter.
470470
- Fixed an assertion failure by adjusting integral to boolean vector conversions (#GH108326)
471-
- Clang is now better at keeping track of friend function template instance contexts. (#GH55509)
472471
- Fixed an issue deducing non-type template arguments of reference type. (#GH73460)
473472
- Fixed an issue in constraint evaluation, where type constraints on the lambda expression
474473
containing outer unexpanded parameters were not correctly expanded. (#GH101754)

clang/include/clang/AST/Decl.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,13 +2299,6 @@ class FunctionDecl : public DeclaratorDecl,
22992299
FunctionDeclBits.IsLateTemplateParsed = ILT;
23002300
}
23012301

2302-
bool isInstantiatedFromMemberTemplate() const {
2303-
return FunctionDeclBits.IsInstantiatedFromMemberTemplate;
2304-
}
2305-
void setInstantiatedFromMemberTemplate(bool Val = true) {
2306-
FunctionDeclBits.IsInstantiatedFromMemberTemplate = Val;
2307-
}
2308-
23092302
/// Whether this function is "trivial" in some specialized C++ senses.
23102303
/// Can only be true for default constructors, copy constructors,
23112304
/// copy assignment operators, and destructors. Not meaningful until

clang/include/clang/AST/DeclBase.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,8 +1763,6 @@ class DeclContext {
17631763
uint64_t HasImplicitReturnZero : 1;
17641764
LLVM_PREFERRED_TYPE(bool)
17651765
uint64_t IsLateTemplateParsed : 1;
1766-
LLVM_PREFERRED_TYPE(bool)
1767-
uint64_t IsInstantiatedFromMemberTemplate : 1;
17681766

17691767
/// Kind of contexpr specifier as defined by ConstexprSpecKind.
17701768
LLVM_PREFERRED_TYPE(ConstexprSpecKind)
@@ -1815,7 +1813,7 @@ class DeclContext {
18151813
};
18161814

18171815
/// Number of inherited and non-inherited bits in FunctionDeclBitfields.
1818-
enum { NumFunctionDeclBits = NumDeclContextBits + 32 };
1816+
enum { NumFunctionDeclBits = NumDeclContextBits + 31 };
18191817

18201818
/// Stores the bits used by CXXConstructorDecl. If modified
18211819
/// NumCXXConstructorDeclBits and the accessor
@@ -1826,12 +1824,12 @@ class DeclContext {
18261824
LLVM_PREFERRED_TYPE(FunctionDeclBitfields)
18271825
uint64_t : NumFunctionDeclBits;
18281826

1829-
/// 19 bits to fit in the remaining available space.
1827+
/// 20 bits to fit in the remaining available space.
18301828
/// Note that this makes CXXConstructorDeclBitfields take
18311829
/// exactly 64 bits and thus the width of NumCtorInitializers
18321830
/// will need to be shrunk if some bit is added to NumDeclContextBitfields,
18331831
/// NumFunctionDeclBitfields or CXXConstructorDeclBitfields.
1834-
uint64_t NumCtorInitializers : 16;
1832+
uint64_t NumCtorInitializers : 17;
18351833
LLVM_PREFERRED_TYPE(bool)
18361834
uint64_t IsInheritingConstructor : 1;
18371835

@@ -1845,7 +1843,7 @@ class DeclContext {
18451843
};
18461844

18471845
/// Number of inherited and non-inherited bits in CXXConstructorDeclBitfields.
1848-
enum { NumCXXConstructorDeclBits = NumFunctionDeclBits + 19 };
1846+
enum { NumCXXConstructorDeclBits = NumFunctionDeclBits + 20 };
18491847

18501848
/// Stores the bits used by ObjCMethodDecl.
18511849
/// If modified NumObjCMethodDeclBits and the accessor

clang/include/clang/AST/DeclTemplate.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,15 +1008,6 @@ class FunctionTemplateDecl : public RedeclarableTemplateDecl {
10081008
return getTemplatedDecl()->isThisDeclarationADefinition();
10091009
}
10101010

1011-
bool isCompatibleWithDefinition() const {
1012-
return getTemplatedDecl()->isInstantiatedFromMemberTemplate() ||
1013-
isThisDeclarationADefinition();
1014-
}
1015-
void setInstantiatedFromMemberTemplate(FunctionTemplateDecl *D) {
1016-
getTemplatedDecl()->setInstantiatedFromMemberTemplate();
1017-
RedeclarableTemplateDecl::setInstantiatedFromMemberTemplate(D);
1018-
}
1019-
10201011
/// Return the specialization with the provided arguments if it exists,
10211012
/// otherwise return the insertion point.
10221013
FunctionDecl *findSpecialization(ArrayRef<TemplateArgument> Args,

clang/include/clang/Sema/Sema.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13017,12 +13017,6 @@ class Sema final : public SemaBase {
1301713017
std::optional<ArrayRef<TemplateArgument>> Innermost = std::nullopt,
1301813018
bool RelativeToPrimary = false, bool ForConstraintInstantiation = false);
1301913019

13020-
void getTemplateInstantiationArgs(
13021-
MultiLevelTemplateArgumentList &Result, const NamedDecl *D,
13022-
const DeclContext *DC = nullptr, bool Final = false,
13023-
std::optional<ArrayRef<TemplateArgument>> Innermost = std::nullopt,
13024-
bool RelativeToPrimary = false, bool ForConstraintInstantiation = false);
13025-
1302613020
/// RAII object to handle the state changes required to synthesize
1302713021
/// a function body.
1302813022
class SynthesizedFunctionScope {

clang/lib/AST/Decl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3067,7 +3067,6 @@ FunctionDecl::FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC,
30673067
FunctionDeclBits.IsIneligibleOrNotSelected = false;
30683068
FunctionDeclBits.HasImplicitReturnZero = false;
30693069
FunctionDeclBits.IsLateTemplateParsed = false;
3070-
FunctionDeclBits.IsInstantiatedFromMemberTemplate = false;
30713070
FunctionDeclBits.ConstexprKind = static_cast<uint64_t>(ConstexprKind);
30723071
FunctionDeclBits.BodyContainsImmediateEscalatingExpression = false;
30733072
FunctionDeclBits.InstantiationIsPending = false;

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3928,7 +3928,22 @@ TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
39283928
if (FunctionTemplate->getFriendObjectKind())
39293929
Owner = FunctionTemplate->getLexicalDeclContext();
39303930
FunctionDecl *FD = FunctionTemplate->getTemplatedDecl();
3931-
3931+
// additional check for inline friend,
3932+
// ```
3933+
// template <class F1> int foo(F1 X);
3934+
// template <int A1> struct A {
3935+
// template <class F1> friend int foo(F1 X) { return A1; }
3936+
// };
3937+
// template struct A<1>;
3938+
// int a = foo(1.0);
3939+
// ```
3940+
const FunctionDecl *FDFriend;
3941+
if (FD->getFriendObjectKind() == Decl::FriendObjectKind::FOK_None &&
3942+
FD->isDefined(FDFriend, /*CheckForPendingFriendDefinition*/ true) &&
3943+
FDFriend->getFriendObjectKind() != Decl::FriendObjectKind::FOK_None) {
3944+
FD = const_cast<FunctionDecl *>(FDFriend);
3945+
Owner = FD->getLexicalDeclContext();
3946+
}
39323947
MultiLevelTemplateArgumentList SubstArgs(
39333948
FunctionTemplate, CanonicalDeducedArgumentList->asArray(),
39343949
/*Final=*/false);

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,13 @@ struct TemplateInstantiationArgumentCollecter
512512

513513
} // namespace
514514

515-
void Sema::getTemplateInstantiationArgs(
516-
MultiLevelTemplateArgumentList &Result, const NamedDecl *ND,
517-
const DeclContext *DC, bool Final,
515+
MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs(
516+
const NamedDecl *ND, const DeclContext *DC, bool Final,
518517
std::optional<ArrayRef<TemplateArgument>> Innermost, bool RelativeToPrimary,
519518
bool ForConstraintInstantiation) {
520519
assert((ND || DC) && "Can't find arguments for a decl if one isn't provided");
521520
// Accumulate the set of template argument lists in this structure.
521+
MultiLevelTemplateArgumentList Result;
522522
const Decl *CurDecl = ND;
523523

524524
if (!CurDecl)
@@ -529,17 +529,6 @@ void Sema::getTemplateInstantiationArgs(
529529
do {
530530
CurDecl = Collecter.Visit(const_cast<Decl *>(CurDecl));
531531
} while (CurDecl);
532-
}
533-
534-
MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs(
535-
const NamedDecl *ND, const DeclContext *DC, bool Final,
536-
std::optional<ArrayRef<TemplateArgument>> Innermost, bool RelativeToPrimary,
537-
bool ForConstraintInstantiation) {
538-
assert((ND || DC) && "Can't find arguments for a decl if one isn't provided");
539-
// Accumulate the set of template argument lists in this structure.
540-
MultiLevelTemplateArgumentList Result;
541-
getTemplateInstantiationArgs(Result, ND, DC, Final, Innermost,
542-
RelativeToPrimary, ForConstraintInstantiation);
543532
return Result;
544533
}
545534

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5224,26 +5224,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
52245224
RebuildTypeSourceInfoForDefaultSpecialMembers();
52255225
SetDeclDefaulted(Function, PatternDecl->getLocation());
52265226
} else {
5227-
DeclContext *DC = Function;
5228-
MultiLevelTemplateArgumentList TemplateArgs;
5229-
if (auto *Primary = Function->getPrimaryTemplate();
5230-
Primary &&
5231-
!isGenericLambdaCallOperatorOrStaticInvokerSpecialization(Function)) {
5232-
auto It = llvm::find_if(Primary->redecls(),
5233-
[](const RedeclarableTemplateDecl *RTD) {
5234-
return cast<FunctionTemplateDecl>(RTD)
5235-
->isCompatibleWithDefinition();
5236-
});
5237-
assert(It != Primary->redecls().end() &&
5238-
"Should't get here without a definition");
5239-
DC = (*It)->getLexicalDeclContext();
5240-
if (Function->getTemplateSpecializationKind() !=
5241-
TSK_ExplicitSpecialization)
5242-
TemplateArgs.addOuterTemplateArguments(
5243-
Function, Function->getTemplateSpecializationArgs()->asArray(),
5244-
/*Final=*/false);
5245-
}
5246-
getTemplateInstantiationArgs(TemplateArgs, /*D=*/nullptr, DC);
5227+
MultiLevelTemplateArgumentList TemplateArgs = getTemplateInstantiationArgs(
5228+
Function, Function->getLexicalDeclContext());
52475229

52485230
// Substitute into the qualifier; we can get a substitution failure here
52495231
// through evil use of alias templates.

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,6 @@ void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
10871087
FD->setHasImplicitReturnZero(FunctionDeclBits.getNextBit());
10881088
FD->setIsMultiVersion(FunctionDeclBits.getNextBit());
10891089
FD->setLateTemplateParsed(FunctionDeclBits.getNextBit());
1090-
FD->setInstantiatedFromMemberTemplate(FunctionDeclBits.getNextBit());
10911090
FD->setFriendConstraintRefersToEnclosingTemplate(
10921091
FunctionDeclBits.getNextBit());
10931092
FD->setUsesSEHTry(FunctionDeclBits.getNextBit());

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
626626
}
627627

628628
void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
629-
static_assert(DeclContext::NumFunctionDeclBits == 45,
629+
static_assert(DeclContext::NumFunctionDeclBits == 44,
630630
"You need to update the serializer after you change the "
631631
"FunctionDeclBits");
632632

@@ -732,7 +732,6 @@ void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
732732
FunctionDeclBits.addBit(D->hasImplicitReturnZero());
733733
FunctionDeclBits.addBit(D->isMultiVersion());
734734
FunctionDeclBits.addBit(D->isLateTemplateParsed());
735-
FunctionDeclBits.addBit(D->isInstantiatedFromMemberTemplate());
736735
FunctionDeclBits.addBit(D->FriendConstraintRefersToEnclosingTemplate());
737736
FunctionDeclBits.addBit(D->usesSEHTry());
738737
Record.push_back(FunctionDeclBits);

clang/test/SemaTemplate/GH55509.cpp

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

0 commit comments

Comments
 (0)