Skip to content

Commit 21cb63b

Browse files
zyn0217cor3ntin
authored andcommitted
Save the checkpoint
Failed Tests (3): Clang :: CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp Clang :: CXX/temp/temp.constr/temp.constr.normal/p1.cpp Clang :: SemaTemplate/concepts-recursive-inst.cpp
1 parent 0cf03fb commit 21cb63b

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

clang/lib/Sema/SemaConcept.cpp

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "clang/AST/Decl.h"
1818
#include "clang/AST/DeclCXX.h"
1919
#include "clang/AST/DeclTemplate.h"
20+
#include "clang/AST/DependenceFlags.h"
2021
#include "clang/AST/Expr.h"
2122
#include "clang/AST/ExprConcepts.h"
2223
#include "clang/AST/TemplateBase.h"
@@ -594,6 +595,19 @@ static bool calculateConstraintSatisfaction(
594595
ConstraintSatisfaction &Satisfaction,
595596
UnsignedOrNone PackSubstitutionIndex) {
596597

598+
// If the expression has been calculated, e.g. when we are in a nested
599+
// requirement, do not compute it repeatedly.
600+
if (auto *Expr = Constraint.getConceptSpecializationExpr();
601+
Expr && Expr->getDependence() == ExprDependence::None) {
602+
auto &Calculated = Expr->getSatisfaction();
603+
Satisfaction.ContainsErrors = Calculated.ContainsErrors;
604+
Satisfaction.IsSatisfied = Calculated.IsSatisfied;
605+
Satisfaction.Details.insert(Satisfaction.Details.end(),
606+
Calculated.records().begin(),
607+
Calculated.records().end());
608+
return !Satisfaction.ContainsErrors;
609+
}
610+
597611
Sema::ContextRAII CurContext(
598612
S, Constraint.getConceptId()->getNamedConcept()->getDeclContext(),
599613
/*NewThisContext=*/false);
@@ -1598,6 +1612,8 @@ substituteParameterMappings(Sema &S, NormalizedConstraintWithParamMapping &N,
15981612
SourceLocation Loc = ArgsAsWritten->NumTemplateArgs > I
15991613
? ArgsAsWritten->arguments()[I].getLocation()
16001614
: SourceLocation();
1615+
// FIXME: Investigate when we couldn't preserve the SourceLoc. What shall we do??
1616+
// assert(Loc.isValid());
16011617
if (OccurringIndices[I]) {
16021618
NamedDecl *Param = TemplateParams->begin()[I];
16031619
new (&(TempArgs)[J])
@@ -1654,6 +1670,7 @@ substituteParameterMappings(Sema &S, NormalizedConstraintWithParamMapping &N,
16541670
// If this is an empty pack, we have no corresponding SubstArgs.
16551671
if (I < SubstArgs.size())
16561672
Loc = SubstArgs.arguments()[I].getLocation();
1673+
// assert(Loc.isValid());
16571674
TempArgs[I] = S.getTrivialTemplateArgumentLoc(CTAI.SugaredConverted[I],
16581675
QualType(), Loc);
16591676
}
@@ -1688,9 +1705,29 @@ substituteParameterMappings(Sema &S, ConceptIdConstraint &N,
16881705
assert(CSE);
16891706
TemplateArgumentListInfo Out;
16901707
assert(!N.getBeginLoc().isInvalid());
1691-
if (S.SubstTemplateArgumentsInParameterMapping(
1692-
CSE->getTemplateArgsAsWritten()->arguments(), N.getBeginLoc(),
1693-
MLTAL, Out))
1708+
// TransformTemplateArguments is unable to preserve the source location of a
1709+
// pack. The SourceLocation is necessary for the instantiation location.
1710+
// FIXME: The BaseLoc will be used as the location of the pack expansion,
1711+
// which is wrong.
1712+
ArgsAsWritten = CSE->getTemplateArgsAsWritten();
1713+
SourceLocation InstLocBegin =
1714+
ArgsAsWritten->arguments().empty()
1715+
? ArgsAsWritten->getLAngleLoc()
1716+
: ArgsAsWritten->arguments().front().getSourceRange().getBegin();
1717+
SourceLocation InstLocEnd =
1718+
ArgsAsWritten->arguments().empty()
1719+
? ArgsAsWritten->getRAngleLoc()
1720+
: ArgsAsWritten->arguments().front().getSourceRange().getEnd();
1721+
Sema::InstantiatingTemplate Inst(
1722+
S, InstLocBegin,
1723+
Sema::InstantiatingTemplate::ParameterMappingSubstitution{},
1724+
const_cast<NamedDecl *>(N.getConstraintDecl()),
1725+
{InstLocBegin, InstLocEnd});
1726+
if (Inst.isInvalid())
1727+
return true;
1728+
1729+
if (S.SubstTemplateArgumentsInParameterMapping(ArgsAsWritten->arguments(),
1730+
N.getBeginLoc(), MLTAL, Out))
16941731
return true;
16951732
Sema::CheckTemplateArgumentInfo CTAI;
16961733
if (S.CheckTemplateArgumentList(CSE->getNamedConcept(),

clang/lib/Sema/TreeTransform.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3698,10 +3698,6 @@ class TreeTransform {
36983698
ParentContext);
36993699
}
37003700

3701-
/// Build a new Objective-C boxed expression.
3702-
///
3703-
/// By default, performs semantic analysis to build the new expression.
3704-
/// Subclasses may override this routine to provide different behavior.
37053701
ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS,
37063702
SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
37073703
NamedDecl *FoundDecl, ConceptDecl *NamedConcept,

0 commit comments

Comments
 (0)