Skip to content

Commit 1edea42

Browse files
zyn0217cor3ntin
authored andcommitted
Stash recent changes
1 parent 7821469 commit 1edea42

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

clang/include/clang/Sema/SemaConcept.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct NormalizedConstraint {
7878
unsigned Kind : 5;
7979
LLVM_PREFERRED_TYPE(FoldOperatorKind)
8080
unsigned FoldOperator : 1;
81-
unsigned : 26;
81+
unsigned Placeholder : 26;
8282
OccurenceList Indexes;
8383
TemplateArgumentLoc *Args;
8484
const Expr *Pattern;
@@ -125,6 +125,7 @@ struct NormalizedConstraint {
125125
NormalizedConstraint *Constraint)
126126
: FoldExpanded{llvm::to_underlying(ConstraintKind::FoldExpanded),
127127
llvm::to_underlying(OpKind),
128+
/*Placeholder=*/0,
128129
/*Indexes=*/{},
129130
/*Args=*/nullptr,
130131
Pattern,

clang/lib/Sema/SemaConcept.cpp

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,11 @@ static std::optional<MultiLevelTemplateArgumentList>
351351
SubstitutionInTemplateArguments(
352352
Sema &S, const NormalizedConstraintWithParamMapping &Constraint,
353353
const NamedDecl *Template, MultiLevelTemplateArgumentList MLTAL,
354-
llvm::SmallVector<TemplateArgument> &SubstitutedOuterMost) {
354+
llvm::SmallVector<TemplateArgument> &SubstitutedOuterMost,
355+
// FIXME: Having both PackSubstitutionIndex and
356+
// NormalizedConstraintWithParamMapping::getPackSubstitutionIndex is
357+
// confusing
358+
UnsignedOrNone PackSubstitutionIndex) {
355359

356360
Sema::InstantiatingTemplate Inst(
357361
S, Constraint.getBeginLoc(),
@@ -369,7 +373,9 @@ SubstitutionInTemplateArguments(
369373
TemplateArgumentListInfo SubstArgs;
370374
if (Constraint.hasParameterMapping()) {
371375
Sema::ArgPackSubstIndexRAII SubstIndex(
372-
S, Constraint.getPackSubstitutionIndex());
376+
S, Constraint.getPackSubstitutionIndex()
377+
? Constraint.getPackSubstitutionIndex()
378+
: PackSubstitutionIndex);
373379
if (S.SubstTemplateArgumentsInParameterMapping(
374380
Constraint.getParameterMapping(), MLTAL, SubstArgs) ||
375381
Trap.hasErrorOccurred())
@@ -405,11 +411,12 @@ static bool calculateConstraintSatisfaction(
405411
llvm::SmallVector<TemplateArgument> SubstitutedOuterMost;
406412
std::optional<MultiLevelTemplateArgumentList> SubstitutedArgs =
407413
SubstitutionInTemplateArguments(S, Constraint, Template, MLTAL,
408-
SubstitutedOuterMost);
414+
SubstitutedOuterMost,
415+
PackSubstitutionIndex);
409416
if (!SubstitutedArgs)
410417
return false;
411418

412-
Sema::ArgPackSubstIndexRAII(S, PackSubstitutionIndex);
419+
Sema::ArgPackSubstIndexRAII SubstIndex(S, PackSubstitutionIndex);
413420
ExprResult SubstitutedAtomicExpr =
414421
EvaluateAtomicConstraint(S, Constraint.getConstraintExpr(), Template,
415422
TemplateNameLoc, *SubstitutedArgs, Satisfaction);
@@ -526,7 +533,8 @@ static bool calculateConstraintSatisfaction(
526533
S,
527534
static_cast<const NormalizedConstraintWithParamMapping &>(
528535
FE.getNormalizedPattern()),
529-
Template, MLTAL, SubstitutedOuterMost);
536+
// FIXME: Is PackSubstitutionIndex correct?
537+
Template, MLTAL, SubstitutedOuterMost, S.ArgPackSubstIndex);
530538
if (!SubstitutedArgs)
531539
return false;
532540

@@ -548,14 +556,20 @@ static bool calculateConstraintSatisfaction(
548556
bool Success = calculateConstraintSatisfaction(
549557
S, FE.getNormalizedPattern(), Template, TemplateNameLoc,
550558
*SubstitutedArgs, Satisfaction, UnsignedOrNone(I));
551-
if (!Success)
559+
// SFINAE errors shouldn't prevent disjunction from evaluating
560+
// FIXME: Does !Success == SFINAE errors occurred?
561+
if (!Success && Conjunction)
552562
return false;
553563
if (!Conjunction && Satisfaction.IsSatisfied) {
554564
Satisfaction.Details.erase(Satisfaction.Details.begin() + EffectiveDetailEndIndex,
555565
Satisfaction.Details.end());
556566
break;
557567
}
558568
}
569+
// Satisfaction.IsSatisfied might be overwritten.
570+
// How to handle errors here ?? Shall we substitute into the concept?
571+
if (Satisfaction.Details.size() != EffectiveDetailEndIndex)
572+
Satisfaction.IsSatisfied = false;
559573
return true;
560574
}
561575

@@ -569,11 +583,6 @@ static bool calculateConstraintSatisfaction(
569583
S, Constraint.getConceptId()->getNamedConcept()->getDeclContext(),
570584
/*NewThisContext=*/false);
571585

572-
llvm::SmallVector<TemplateArgument> SubstitutedOuterMost;
573-
std::optional<MultiLevelTemplateArgumentList> SubstitutedArgs =
574-
SubstitutionInTemplateArguments(S, Constraint, Template, MLTAL,
575-
SubstitutedOuterMost);
576-
577586
Sema::InstantiatingTemplate Tpl(
578587
S, Constraint.getConceptId()->getBeginLoc(),
579588
Sema::InstantiatingTemplate::ConstraintsCheck{},
@@ -588,6 +597,12 @@ static bool calculateConstraintSatisfaction(
588597

589598
if (Size != Satisfaction.Details.size()) {
590599

600+
llvm::SmallVector<TemplateArgument> SubstitutedOuterMost;
601+
std::optional<MultiLevelTemplateArgumentList> SubstitutedArgs =
602+
SubstitutionInTemplateArguments(S, Constraint, Template, MLTAL,
603+
SubstitutedOuterMost,
604+
PackSubstitutionIndex);
605+
591606
if (!SubstitutedArgs)
592607
return Ok;
593608

@@ -633,7 +648,7 @@ static bool calculateConstraintSatisfaction(
633648
SubstitutedConceptId.getAs<ConceptSpecializationExpr>()
634649
->getConceptReference()));
635650

636-
Satisfaction.Details.push_back(nullptr);
651+
// Satisfaction.Details.push_back(nullptr);
637652
}
638653
return Ok;
639654
}
@@ -1790,11 +1805,11 @@ NormalizedConstraint *NormalizedConstraint::fromConstraintExpr(
17901805
return nullptr;
17911806

17921807
if (FE->isRightFold())
1793-
RHS = FoldExpandedConstraint::Create(S.getASTContext(),
1794-
FE->getPattern(), Kind, RHS);
1795-
else
17961808
LHS = FoldExpandedConstraint::Create(S.getASTContext(),
17971809
FE->getPattern(), Kind, LHS);
1810+
else
1811+
RHS = FoldExpandedConstraint::Create(S.getASTContext(),
1812+
FE->getPattern(), Kind, RHS);
17981813

17991814
return CompoundConstraint::Create(
18001815
S.getASTContext(), LHS,

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5172,10 +5172,11 @@ bool Sema::CheckTemplateTypeArgument(
51725172
}
51735173
default: {
51745174
// We allow instantiating a template with template argument packs when
5175-
// building deduction guides.
5175+
// building deduction guides or mapping constraint template parameters.
51765176
if (Arg.getKind() == TemplateArgument::Pack &&
5177-
CodeSynthesisContexts.back().Kind ==
5178-
Sema::CodeSynthesisContext::BuildingDeductionGuides) {
5177+
(CodeSynthesisContexts.back().Kind ==
5178+
Sema::CodeSynthesisContext::BuildingDeductionGuides ||
5179+
inParameterMappingSubstitution())) {
51795180
SugaredConverted.push_back(Arg);
51805181
CanonicalConverted.push_back(Arg);
51815182
return false;

clang/test/SemaCXX/cxx2c-fold-exprs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ static_assert(And1<int, S>() == 1); // expected-error {{no matching function for
158158

159159
static_assert(And2<S>() == 2);
160160
static_assert(And2<S, S>() == 2);
161+
// FIXME: Should it compile??
161162
static_assert(And2<int>() == 2);
162163

163164
static_assert(And2<int, int>() == 2); // expected-error {{no matching function for call to 'And2'}}

0 commit comments

Comments
 (0)