Skip to content

Commit 0cf03fb

Browse files
zyn0217cor3ntin
authored andcommitted
Save the checkpoint
There are 6 tests failing now! Failed Tests (6): Clang :: AST/ByteCode/libcxx/deref-to-array.cpp Clang :: AST/ByteCode/libcxx/primitive-temporary.cpp Clang :: CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp Clang :: CXX/temp/temp.constr/temp.constr.normal/p1.cpp Clang :: Modules/GH60336.cpp Clang :: SemaTemplate/concepts-recursive-inst.cpp
1 parent 3cb8a9f commit 0cf03fb

File tree

4 files changed

+115
-62
lines changed

4 files changed

+115
-62
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "clang/Sema/Redeclaration.h"
6666
#include "clang/Sema/Scope.h"
6767
#include "clang/Sema/SemaBase.h"
68+
#include "clang/Sema/SemaConcept.h"
6869
#include "clang/Sema/TypoCorrection.h"
6970
#include "clang/Sema/Weak.h"
7071
#include "llvm/ADT/APInt.h"
@@ -14817,8 +14818,6 @@ class Sema final : public SemaBase {
1481714818
const NamedDecl *D1, ArrayRef<AssociatedConstraint> AC1,
1481814819
const NamedDecl *D2, ArrayRef<AssociatedConstraint> AC2);
1481914820

14820-
llvm::DenseMap<unsigned, MutableArrayRef<TemplateArgumentLoc>>
14821-
ParameterMappingCache;
1482214821
private:
1482314822
/// Caches pairs of template-like decls whose associated constraints were
1482414823
/// checked for subsumption and whether or not the first's constraints did in

clang/include/clang/Sema/SemaConcept.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ struct NormalizedConstraint {
8989

9090
struct ConceptIdBits : AtomicBits {
9191
NormalizedConstraint *Sub;
92+
93+
// Only used for parameter mapping.
94+
const ConceptSpecializationExpr *CSE;
9295
};
9396

9497
struct CompoundBits {
@@ -138,13 +141,15 @@ struct NormalizedConstraint {
138141
NormalizedConstraint(const ConceptReference *ConceptId,
139142
const NamedDecl *ConstraintDecl,
140143
NormalizedConstraint *SubConstraint,
144+
const ConceptSpecializationExpr *CSE,
141145
UnsignedOrNone PackIndex)
142146
: ConceptId{{llvm::to_underlying(ConstraintKind::ConceptId),
143147
/*Placeholder=*/0, PackIndex.toInternalRepresentation(),
144148
/*Indexes=*/{},
145149
/*Args=*/nullptr, /*ParamList=*/nullptr, ConceptId,
146150
ConstraintDecl},
147-
SubConstraint} {}
151+
SubConstraint,
152+
CSE} {}
148153

149154
NormalizedConstraint(NormalizedConstraint *LHS, CompoundConstraintKind CCK,
150155
NormalizedConstraint *RHS)
@@ -357,9 +362,14 @@ class ConceptIdConstraint : public NormalizedConstraintWithParamMapping {
357362
const ConceptReference *ConceptId,
358363
NormalizedConstraint *SubConstraint,
359364
const NamedDecl *ConstraintDecl,
365+
const ConceptSpecializationExpr *CSE,
360366
UnsignedOrNone PackIndex) {
361367
return new (Ctx) ConceptIdConstraint(ConceptId, ConstraintDecl,
362-
SubConstraint, PackIndex);
368+
SubConstraint, CSE, PackIndex);
369+
}
370+
371+
const ConceptSpecializationExpr *getConceptSpecializationExpr() const {
372+
return ConceptId.CSE;
363373
}
364374

365375
const ConceptReference *getConceptId() const {

clang/lib/Sema/SemaConcept.cpp

Lines changed: 100 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "llvm/ADT/PointerUnion.h"
3636
#include "llvm/ADT/SmallVector.h"
3737
#include "llvm/ADT/StringExtras.h"
38+
#include "llvm/Support/Timer.h"
39+
#include "llvm/Support/WithColor.h"
3840
#include <cstddef>
3941
#include <optional>
4042

@@ -390,16 +392,23 @@ SubstitutionInTemplateArguments(
390392
Constraint.mappingOccurenceList();
391393
SubstitutedOuterMost =
392394
llvm::to_vector_of<TemplateArgument>(MLTAL.getOutermost());
395+
unsigned Offset = 0;
393396
for (unsigned I = 0, MappedIndex = 0; I < Used.size(); I++) {
394397
TemplateArgument Arg;
395398
if (Used[I])
396399
Arg = S.Context.getCanonicalTemplateArgument(
397400
CTAI.SugaredConverted[MappedIndex++]);
398-
if (I < SubstitutedOuterMost.size())
401+
if (I < SubstitutedOuterMost.size()) {
399402
SubstitutedOuterMost[I] = Arg;
400-
else
403+
Offset = I + 1;
404+
} else {
401405
SubstitutedOuterMost.push_back(Arg);
406+
Offset = SubstitutedOuterMost.size();
402407
}
408+
}
409+
if (Offset < SubstitutedOuterMost.size())
410+
SubstitutedOuterMost.erase(SubstitutedOuterMost.begin() + Offset);
411+
403412
MLTAL.replaceOutermostTemplateArguments(
404413
const_cast<NamedDecl *>(Constraint.getConstraintDecl()),
405414
SubstitutedOuterMost);
@@ -765,7 +774,9 @@ static bool CheckConstraintSatisfaction(
765774
if (TopLevelConceptId)
766775
C = ConceptIdConstraint::Create(S.getASTContext(), TopLevelConceptId,
767776
const_cast<NormalizedConstraint *>(C),
768-
Template, S.ArgPackSubstIndex);
777+
Template, /*CSE=*/nullptr,
778+
S.ArgPackSubstIndex);
779+
}
769780

770781
ExprResult Res = calculateConstraintSatisfaction(
771782
S, *C, Template, TemplateIDRange.getBegin(), TemplateArgsLists,
@@ -1551,27 +1562,6 @@ void Sema::DiagnoseUnsatisfiedConstraint(
15511562
ConstraintExpr->getBeginLoc(), First);
15521563
}
15531564

1554-
const NormalizedConstraint *Sema::getNormalizedAssociatedConstraints(
1555-
ConstrainedDeclOrNestedRequirement ConstrainedDeclOrNestedReq,
1556-
ArrayRef<AssociatedConstraint> AssociatedConstraints) {
1557-
if (!ConstrainedDeclOrNestedReq)
1558-
return NormalizedConstraint::fromAssociatedConstraints(
1559-
*this, nullptr, AssociatedConstraints);
1560-
1561-
// FIXME: ConstrainedDeclOrNestedReq is never a NestedRequirement!
1562-
const NamedDecl *ND =
1563-
ConstrainedDeclOrNestedReq.dyn_cast<const NamedDecl *>();
1564-
auto CacheEntry = NormalizationCache.find(ConstrainedDeclOrNestedReq);
1565-
if (CacheEntry == NormalizationCache.end()) {
1566-
auto *Normalized = NormalizedConstraint::fromAssociatedConstraints(
1567-
*this, ND, AssociatedConstraints);
1568-
CacheEntry =
1569-
NormalizationCache.try_emplace(ConstrainedDeclOrNestedReq, Normalized)
1570-
.first;
1571-
}
1572-
return CacheEntry->second;
1573-
}
1574-
15751565
static bool
15761566
substituteParameterMappings(Sema &S, NormalizedConstraint &N,
15771567
const MultiLevelTemplateArgumentList &MLTAL,
@@ -1642,30 +1632,6 @@ substituteParameterMappings(Sema &S, NormalizedConstraintWithParamMapping &N,
16421632
if (Inst.isInvalid())
16431633
return true;
16441634

1645-
unsigned Hash;
1646-
llvm::FoldingSetNodeID ID;
1647-
auto &Context = S.getASTContext();
1648-
if (N.getKind() == NormalizedConstraint::ConstraintKind::ConceptId) {
1649-
ID.AddPointer(static_cast<ConceptIdConstraint &>(N)
1650-
.getConceptId()
1651-
->getNamedConcept()
1652-
->getCanonicalDecl());
1653-
for (auto &ArgLoc : static_cast<ConceptIdConstraint &>(N)
1654-
.getConceptId()
1655-
->getTemplateArgsAsWritten()
1656-
->arguments())
1657-
ArgLoc.getArgument().Profile(ID, Context);
1658-
1659-
Hash = ID.ComputeHash();
1660-
if (auto Iter = S.ParameterMappingCache.find(Hash);
1661-
Iter != S.ParameterMappingCache.end()) {
1662-
N.updateParameterMapping(N.mappingOccurenceList(), Iter->second,
1663-
N.getUsedTemplateParamList());
1664-
return false;
1665-
}
1666-
}
1667-
// FIXME: Cache for atomic constraints.
1668-
16691635
// TransformTemplateArguments is unable to preserve the source location of a
16701636
// pack. The SourceLocation is necessary for the instantiation location.
16711637
// FIXME: The BaseLoc will be used as the location of the pack expansion,
@@ -1699,23 +1665,46 @@ substituteParameterMappings(Sema &S, NormalizedConstraintWithParamMapping &N,
16991665
CTAI.SugaredConverted.size());
17001666
N.updateParameterMapping(N.mappingOccurenceList(), Mapping,
17011667
N.getUsedTemplateParamList());
1702-
if (N.getKind() == NormalizedConstraint::ConstraintKind::ConceptId)
1703-
S.ParameterMappingCache.insert({Hash, Mapping});
17041668
return false;
17051669
}
17061670

17071671
static bool
17081672
substituteParameterMappings(Sema &S, ConceptIdConstraint &N,
17091673
const MultiLevelTemplateArgumentList &MLTAL,
17101674
const ASTTemplateArgumentListInfo *ArgsAsWritten) {
1711-
1712-
if (N.getConstraintDecl()) {
1713-
substituteParameterMappings(
1675+
assert(N.getConstraintDecl());
1676+
#if 0
1677+
return substituteParameterMappings(
17141678
S, static_cast<NormalizedConstraintWithParamMapping &>(N), MLTAL,
17151679
ArgsAsWritten);
1680+
#else
1681+
auto TemplateArgs = MLTAL;
1682+
if (N.getConstraintDecl()) {
1683+
if (substituteParameterMappings(
1684+
S, static_cast<NormalizedConstraintWithParamMapping &>(N),
1685+
TemplateArgs, ArgsAsWritten))
1686+
return true;
1687+
auto *CSE = N.getConceptSpecializationExpr();
1688+
assert(CSE);
1689+
TemplateArgumentListInfo Out;
1690+
assert(!N.getBeginLoc().isInvalid());
1691+
if (S.SubstTemplateArgumentsInParameterMapping(
1692+
CSE->getTemplateArgsAsWritten()->arguments(), N.getBeginLoc(),
1693+
MLTAL, Out))
1694+
return true;
1695+
Sema::CheckTemplateArgumentInfo CTAI;
1696+
if (S.CheckTemplateArgumentList(CSE->getNamedConcept(),
1697+
CSE->getConceptNameInfo().getLoc(), Out,
1698+
/*DefaultArgs=*/{},
1699+
/*PartialTemplateArgs=*/false, CTAI,
1700+
/*UpdateArgsWithConversions=*/false))
1701+
return true;
1702+
TemplateArgs.replaceOutermostTemplateArguments(
1703+
TemplateArgs.getAssociatedDecl(0).first, CTAI.CanonicalConverted);
17161704
}
1717-
return substituteParameterMappings(S, N.getNormalizedConstraint(), MLTAL,
1718-
ArgsAsWritten);
1705+
return substituteParameterMappings(S, N.getNormalizedConstraint(),
1706+
TemplateArgs, ArgsAsWritten);
1707+
#endif
17191708
}
17201709

17211710
static bool
@@ -1758,10 +1747,40 @@ static bool substituteParameterMappings(Sema &S, NormalizedConstraint &N,
17581747
// Don't build Subst* nodes to model lambda expressions.
17591748
// The transform of Subst* is oblivious to the lambda type.
17601749
MLTAL.setKind(TemplateSubstitutionKind::Rewrite);
1750+
Sema::InstantiatingTemplate Inst(
1751+
S, N.getBeginLoc(),
1752+
Sema::InstantiatingTemplate::ParameterMappingSubstitution{},
1753+
CSE->getNamedConcept(), {N.getBeginLoc(), N.getEndLoc()});
1754+
if (Inst.isInvalid())
1755+
return true;
1756+
17611757
return substituteParameterMappings(S, N, MLTAL,
17621758
CSE->getTemplateArgsAsWritten());
17631759
}
17641760

1761+
static bool substituteParameterMappings(Sema &S, NormalizedConstraint &N) {
1762+
switch (N.getKind()) {
1763+
case NormalizedConstraint::ConstraintKind::Atomic:
1764+
return false;
1765+
case NormalizedConstraint::ConstraintKind::FoldExpanded: {
1766+
Sema::ArgPackSubstIndexRAII _(S, std::nullopt);
1767+
return substituteParameterMappings(
1768+
S, static_cast<FoldExpandedConstraint &>(N).getNormalizedPattern());
1769+
}
1770+
case NormalizedConstraint::ConstraintKind::ConceptId: {
1771+
auto &CC = static_cast<ConceptIdConstraint &>(N);
1772+
return substituteParameterMappings(S, CC.getNormalizedConstraint(),
1773+
CC.getConceptSpecializationExpr());
1774+
}
1775+
case NormalizedConstraint::ConstraintKind::Compound: {
1776+
auto &Compound = static_cast<CompoundConstraint &>(N);
1777+
if (substituteParameterMappings(S, Compound.getLHS()))
1778+
return true;
1779+
return substituteParameterMappings(S, Compound.getRHS());
1780+
}
1781+
}
1782+
}
1783+
17651784
NormalizedConstraint *NormalizedConstraint::fromAssociatedConstraints(
17661785
Sema &S, const NamedDecl *D, ArrayRef<AssociatedConstraint> ACs) {
17671786
assert(ACs.size() != 0);
@@ -1840,11 +1859,11 @@ NormalizedConstraint *NormalizedConstraint::fromConstraintExpr(
18401859
if (!SubNF)
18411860
return nullptr;
18421861
}
1843-
if (substituteParameterMappings(S, *SubNF, CSE))
1844-
return nullptr;
1862+
// if (substituteParameterMappings(S, *SubNF, CSE))
1863+
// return nullptr;
18451864

18461865
return ConceptIdConstraint::Create(
1847-
S.getASTContext(), CSE->getConceptReference(), SubNF, D, SubstIndex);
1866+
S.getASTContext(), CSE->getConceptReference(), SubNF, D, CSE, SubstIndex);
18481867

18491868
} else if (auto *FE = dyn_cast<const CXXFoldExpr>(E);
18501869
FE && S.getLangOpts().CPlusPlus26 &&
@@ -1886,6 +1905,29 @@ NormalizedConstraint *NormalizedConstraint::fromConstraintExpr(
18861905
return AtomicConstraint::Create(S.getASTContext(), E, D, SubstIndex);
18871906
}
18881907

1908+
const NormalizedConstraint *Sema::getNormalizedAssociatedConstraints(
1909+
ConstrainedDeclOrNestedRequirement ConstrainedDeclOrNestedReq,
1910+
ArrayRef<AssociatedConstraint> AssociatedConstraints) {
1911+
if (!ConstrainedDeclOrNestedReq)
1912+
return NormalizedConstraint::fromAssociatedConstraints(
1913+
*this, nullptr, AssociatedConstraints);
1914+
1915+
// FIXME: ConstrainedDeclOrNestedReq is never a NestedRequirement!
1916+
const NamedDecl *ND =
1917+
ConstrainedDeclOrNestedReq.dyn_cast<const NamedDecl *>();
1918+
auto CacheEntry = NormalizationCache.find(ConstrainedDeclOrNestedReq);
1919+
if (CacheEntry == NormalizationCache.end()) {
1920+
auto *Normalized = NormalizedConstraint::fromAssociatedConstraints(
1921+
*this, ND, AssociatedConstraints);
1922+
CacheEntry =
1923+
NormalizationCache.try_emplace(ConstrainedDeclOrNestedReq, Normalized)
1924+
.first;
1925+
if (!Normalized || substituteParameterMappings(*this, *Normalized))
1926+
return nullptr;
1927+
}
1928+
return CacheEntry->second;
1929+
}
1930+
18891931
bool FoldExpandedConstraint::AreCompatibleForSubsumption(
18901932
const FoldExpandedConstraint &A, const FoldExpandedConstraint &B) {
18911933

clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// RUN: %clang_cc1 -std=c++2a -x c++ -verify %s
2+
// FIXME: RUN: %clang_cc1 -std=c++2c -x c++ -verify %s
23

34
template<typename T> concept True = true;
45
template<typename T> concept Foo = True<T*>;
56
template<typename T> concept Bar = Foo<T&>;
67
template<typename T> requires Bar<T> struct S { };
8+
// FIXME: GCC rejects: https://gcc.godbolt.org/z/c9G7G6PTx if the specialization is present.
79
template<typename T> requires Bar<T> && true struct S<T> { };
810

911
template<typename T> concept True2 = sizeof(T) >= 0;

0 commit comments

Comments
 (0)