Skip to content

Commit 3b737ae

Browse files
committed
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 877bd0a commit 3b737ae

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);
@@ -1581,6 +1595,8 @@ substituteParameterMappings(Sema &S, NormalizedConstraintWithParamMapping &N,
15811595
SourceLocation Loc = ArgsAsWritten->NumTemplateArgs > I
15821596
? ArgsAsWritten->arguments()[I].getLocation()
15831597
: SourceLocation();
1598+
// FIXME: Investigate when we couldn't preserve the SourceLoc. What shall we do??
1599+
// assert(Loc.isValid());
15841600
if (OccurringIndices[I]) {
15851601
NamedDecl *Param = TemplateParams->begin()[I];
15861602
new (&(TempArgs)[J])
@@ -1637,6 +1653,7 @@ substituteParameterMappings(Sema &S, NormalizedConstraintWithParamMapping &N,
16371653
// If this is an empty pack, we have no corresponding SubstArgs.
16381654
if (I < SubstArgs.size())
16391655
Loc = SubstArgs.arguments()[I].getLocation();
1656+
// assert(Loc.isValid());
16401657
TempArgs[I] = S.getTrivialTemplateArgumentLoc(CTAI.SugaredConverted[I],
16411658
QualType(), Loc);
16421659
}
@@ -1671,9 +1688,29 @@ substituteParameterMappings(Sema &S, ConceptIdConstraint &N,
16711688
assert(CSE);
16721689
TemplateArgumentListInfo Out;
16731690
assert(!N.getBeginLoc().isInvalid());
1674-
if (S.SubstTemplateArgumentsInParameterMapping(
1675-
CSE->getTemplateArgsAsWritten()->arguments(), N.getBeginLoc(),
1676-
MLTAL, Out))
1691+
// TransformTemplateArguments is unable to preserve the source location of a
1692+
// pack. The SourceLocation is necessary for the instantiation location.
1693+
// FIXME: The BaseLoc will be used as the location of the pack expansion,
1694+
// which is wrong.
1695+
ArgsAsWritten = CSE->getTemplateArgsAsWritten();
1696+
SourceLocation InstLocBegin =
1697+
ArgsAsWritten->arguments().empty()
1698+
? ArgsAsWritten->getLAngleLoc()
1699+
: ArgsAsWritten->arguments().front().getSourceRange().getBegin();
1700+
SourceLocation InstLocEnd =
1701+
ArgsAsWritten->arguments().empty()
1702+
? ArgsAsWritten->getRAngleLoc()
1703+
: ArgsAsWritten->arguments().front().getSourceRange().getEnd();
1704+
Sema::InstantiatingTemplate Inst(
1705+
S, InstLocBegin,
1706+
Sema::InstantiatingTemplate::ParameterMappingSubstitution{},
1707+
const_cast<NamedDecl *>(N.getConstraintDecl()),
1708+
{InstLocBegin, InstLocEnd});
1709+
if (Inst.isInvalid())
1710+
return true;
1711+
1712+
if (S.SubstTemplateArgumentsInParameterMapping(ArgsAsWritten->arguments(),
1713+
N.getBeginLoc(), MLTAL, Out))
16771714
return true;
16781715
Sema::CheckTemplateArgumentInfo CTAI;
16791716
if (S.CheckTemplateArgumentList(CSE->getNamedConcept(),

clang/lib/Sema/TreeTransform.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3714,10 +3714,6 @@ class TreeTransform {
37143714
ParentContext);
37153715
}
37163716

3717-
/// Build a new Objective-C boxed expression.
3718-
///
3719-
/// By default, performs semantic analysis to build the new expression.
3720-
/// Subclasses may override this routine to provide different behavior.
37213717
ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS,
37223718
SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
37233719
NamedDecl *FoundDecl, ConceptDecl *NamedConcept,

0 commit comments

Comments
 (0)