Skip to content

Commit 16980d5

Browse files
authored
Revert "[Clang] Fix dependent local class instantiation bugs" (llvm#135870)
Reverts llvm#134038 This crashes clang as reported here: llvm#134038 (comment)
1 parent 31f39c8 commit 16980d5

File tree

4 files changed

+4
-120
lines changed

4 files changed

+4
-120
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,6 @@ Bug Fixes to C++ Support
457457
by template argument deduction.
458458
- Clang is now better at instantiating the function definition after its use inside
459459
of a constexpr lambda. (#GH125747)
460-
- Fixed a local class member function instantiation bug inside dependent lambdas. (#GH59734), (#GH132208)
461460
- Clang no longer crashes when trying to unify the types of arrays with
462461
certain differences in qualifiers (this could happen during template argument
463462
deduction or when building a ternary operator). (#GH97005)

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4126,6 +4126,9 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation,
41264126
if (FunctionDecl *Pattern =
41274127
Function->getInstantiatedFromMemberFunction()) {
41284128

4129+
if (Function->isIneligibleOrNotSelected())
4130+
continue;
4131+
41294132
if (Function->getTrailingRequiresClause()) {
41304133
ConstraintSatisfaction Satisfaction;
41314134
if (CheckFunctionConstraints(Function, Satisfaction) ||

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5597,61 +5597,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
55975597
Function->setLocation(PatternDecl->getLocation());
55985598
Function->setInnerLocStart(PatternDecl->getInnerLocStart());
55995599
Function->setRangeEnd(PatternDecl->getEndLoc());
5600-
// Let the instantiation use the Pattern's DeclarationNameLoc, due to the
5601-
// following awkwardness:
5602-
//
5603-
// 1. There are out-of-tree users of getNameInfo().getSourceRange(), who
5604-
// expect the source range of the instantiated declaration to be set to
5605-
// point to the definition.
5606-
//
5607-
// 2. That getNameInfo().getSourceRange() might return the TypeLocInfo's
5608-
// location it tracked.
5609-
//
5610-
// 3. Function might come from an (implicit) declaration, while the pattern
5611-
// comes from a definition. In these cases, we need the PatternDecl's source
5612-
// location.
5613-
//
5614-
// To that end, we need to more or less tweak the DeclarationNameLoc. However,
5615-
// we can't blindly copy the DeclarationNameLoc from the PatternDecl to the
5616-
// function, since it contains associated TypeLocs that should have already
5617-
// been transformed. So, we rebuild the TypeLoc for that purpose. Technically,
5618-
// we should create a new function declaration and assign everything we need,
5619-
// but InstantiateFunctionDefinition updates the declaration in place.
5620-
auto NameLocPointsToPattern = [&] {
5621-
DeclarationNameInfo PatternName = PatternDecl->getNameInfo();
5622-
DeclarationNameLoc PatternNameLoc = PatternName.getInfo();
5623-
switch (PatternName.getName().getNameKind()) {
5624-
case DeclarationName::CXXConstructorName:
5625-
case DeclarationName::CXXDestructorName:
5626-
case DeclarationName::CXXConversionFunctionName:
5627-
break;
5628-
default:
5629-
// Cases where DeclarationNameLoc doesn't matter, as it merely contains a
5630-
// source range.
5631-
return PatternNameLoc;
5632-
}
5633-
5634-
TypeSourceInfo *TSI = Function->getNameInfo().getNamedTypeInfo();
5635-
// TSI might be null if the function is named by a constructor template id.
5636-
// E.g. S<T>() {} for class template S with a template parameter T.
5637-
if (!TSI) {
5638-
// We don't care about the DeclarationName of the instantiated function,
5639-
// but only the DeclarationNameLoc. So if the TypeLoc is absent, we do
5640-
// nothing.
5641-
return PatternNameLoc;
5642-
}
5643-
5644-
QualType InstT = TSI->getType();
5645-
// We want to use a TypeLoc that reflects the transformed type while
5646-
// preserving the source location from the pattern.
5647-
TypeLocBuilder TLB;
5648-
TLB.pushTrivial(
5649-
Context, InstT,
5650-
PatternNameLoc.getNamedTypeInfo()->getTypeLoc().getBeginLoc());
5651-
return DeclarationNameLoc::makeNamedTypeLoc(
5652-
TLB.getTypeSourceInfo(Context, InstT));
5653-
};
5654-
Function->setDeclarationNameLoc(NameLocPointsToPattern());
5600+
Function->setDeclarationNameLoc(PatternDecl->getNameInfo().getInfo());
56555601

56565602
EnterExpressionEvaluationContext EvalContext(
56575603
*this, Sema::ExpressionEvaluationContext::PotentiallyEvaluated);

clang/test/CodeGenCXX/local-class-instantiation.cpp

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

0 commit comments

Comments
 (0)