https://github.com/zyn0217 created https://github.com/llvm/llvm-project/pull/190312
When both outer and inner pack substitution indexes are present, we should cache both. Otherwise we will have wrong cached result. This is a regression fix so no release note. >From 87fd68045f59500d76f32ec647ed939e021b60c1 Mon Sep 17 00:00:00 2001 From: Younan Zhang <[email protected]> Date: Fri, 3 Apr 2026 14:04:39 +0800 Subject: [PATCH] [Clang] Fix concept cache for normalized fold expressions When both outer and inner pack substitution indexes are present, we should cache both. Otherwise we will have wrong cached result. This is a regression fix so no release note. --- clang/lib/Sema/SemaConcept.cpp | 29 ++++++++++++------------- clang/test/SemaCXX/cxx2c-fold-exprs.cpp | 14 ++++++++++++ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index 9c4f52dd7150c..5af5fa5c2ce84 100644 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -488,6 +488,12 @@ class ConstraintSatisfactionChecker { ConceptDecl *ParentConcept = nullptr; private: + template <class Constraint> + UnsignedOrNone getOuterPackIndex(const Constraint &C) const { + return C.getPackSubstitutionIndex() ? C.getPackSubstitutionIndex() + : PackSubstitutionIndex; + } + ExprResult EvaluateAtomicConstraint(const Expr *AtomicExpr, const MultiLevelTemplateArgumentList &MLTAL); @@ -798,14 +804,11 @@ ExprResult ConstraintSatisfactionChecker::Evaluate( unsigned Size = Satisfaction.Details.size(); llvm::FoldingSetNodeID ID; - UnsignedOrNone OuterPackSubstIndex = - Constraint.getPackSubstitutionIndex() - ? Constraint.getPackSubstitutionIndex() - : PackSubstitutionIndex; - ID.AddPointer(Constraint.getConstraintExpr()); - ID.AddInteger(OuterPackSubstIndex.toInternalRepresentation()); - HashParameterMapping(S, MLTAL, ID, OuterPackSubstIndex) + ID.AddInteger( + Constraint.getPackSubstitutionIndex().toInternalRepresentation()); + ID.AddInteger(PackSubstitutionIndex.toInternalRepresentation()); + HashParameterMapping(S, MLTAL, ID, getOuterPackIndex(Constraint)) .VisitConstraint(Constraint); if (auto Iter = S.UnsubstitutedConstraintSatisfactionCache.find(ID); @@ -1034,12 +1037,6 @@ ExprResult ConstraintSatisfactionChecker::Evaluate( const MultiLevelTemplateArgumentList &MLTAL) { const ConceptReference *ConceptId = Constraint.getConceptId(); - - UnsignedOrNone OuterPackSubstIndex = - Constraint.getPackSubstitutionIndex() - ? Constraint.getPackSubstitutionIndex() - : PackSubstitutionIndex; - Sema::InstantiatingTemplate InstTemplate( S, ConceptId->getBeginLoc(), Sema::InstantiatingTemplate::ConstraintsCheck{}, @@ -1075,8 +1072,10 @@ ExprResult ConstraintSatisfactionChecker::Evaluate( llvm::FoldingSetNodeID ID; ID.AddPointer(Constraint.getConceptId()); - ID.AddInteger(OuterPackSubstIndex.toInternalRepresentation()); - HashParameterMapping(S, MLTAL, ID, OuterPackSubstIndex) + ID.AddInteger( + Constraint.getPackSubstitutionIndex().toInternalRepresentation()); + ID.AddInteger(PackSubstitutionIndex.toInternalRepresentation()); + HashParameterMapping(S, MLTAL, ID, getOuterPackIndex(Constraint)) .VisitConstraint(Constraint); if (auto Iter = S.UnsubstitutedConstraintSatisfactionCache.find(ID); diff --git a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp index 89ddcbaf11583..5b993fead4877 100644 --- a/clang/test/SemaCXX/cxx2c-fold-exprs.cpp +++ b/clang/test/SemaCXX/cxx2c-fold-exprs.cpp @@ -508,3 +508,17 @@ static_assert(!__callable<__mdispatch<int>>); } } + +namespace GH190169 { + +template <typename Type, typename... Choices> +concept OneOf = (... || __is_same(Type, Choices)); + +template <typename F, typename... Ts> +using check = decltype((F{}(Ts{}), ...)); + +using X = check<decltype([](auto val) { + [](OneOf<int, char> auto) {}(val); +}), char>; + +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
