-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Clang] Fix concept paramater mapping and caching #161994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This expression is not handled by default in RAV, so our parameter mapping and cache mechanism don't work when it appears in a template argument list. There are a few other expressions, such as PackIndexingExpr and FunctionParmPackExpr, which are also no-ops by default. I don't have a test case for them now, so let's leave those until complain :/ There was also a bug in updating the parameter mapping, where the AssociatedDecl was not updated accordingly.
@llvm/pr-subscribers-clang Author: Younan Zhang (zyn0217) ChangesThis expression is not handled by default in RAV, so our parameter mapping and cache mechanism don't work when it appears in a template argument list. There are a few other expressions, such as PackIndexingExpr and FunctionParmPackExpr, which are also no-ops by default. I don't have a test case for them now, so let's leave those until complain :/ There was also a bug in updating the parameter mapping, where the AssociatedDecl was not updated accordingly. Relies on #161671 Full diff: https://github.com/llvm/llvm-project/pull/161994.diff 3 Files Affected:
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 8413090e7ebd1..0b70f61028e49 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -264,14 +264,6 @@ class HashParameterMapping : public RecursiveASTVisitor<HashParameterMapping> {
UnsignedOrNone OuterPackSubstIndex;
- TemplateArgument getPackSubstitutedTemplateArgument(TemplateArgument Arg) {
- assert(*SemaRef.ArgPackSubstIndex < Arg.pack_size());
- Arg = Arg.pack_begin()[*SemaRef.ArgPackSubstIndex];
- if (Arg.isPackExpansion())
- Arg = Arg.getPackExpansionPattern();
- return Arg;
- }
-
bool shouldVisitTemplateInstantiations() const { return true; }
public:
@@ -294,7 +286,7 @@ class HashParameterMapping : public RecursiveASTVisitor<HashParameterMapping> {
assert(Arg.getKind() == TemplateArgument::Pack &&
"Missing argument pack");
- Arg = getPackSubstitutedTemplateArgument(Arg);
+ Arg = SemaRef.getPackSubstitutedTemplateArgument(Arg);
}
UsedTemplateArgs.push_back(
@@ -312,7 +304,7 @@ class HashParameterMapping : public RecursiveASTVisitor<HashParameterMapping> {
if (NTTP->isParameterPack() && SemaRef.ArgPackSubstIndex) {
assert(Arg.getKind() == TemplateArgument::Pack &&
"Missing argument pack");
- Arg = getPackSubstitutedTemplateArgument(Arg);
+ Arg = SemaRef.getPackSubstitutedTemplateArgument(Arg);
}
UsedTemplateArgs.push_back(
@@ -363,6 +355,10 @@ class HashParameterMapping : public RecursiveASTVisitor<HashParameterMapping> {
return inherited::TraverseTemplateArgument(Arg);
}
+ bool TraverseSizeOfPackExpr(SizeOfPackExpr *SOPE) {
+ return TraverseDecl(SOPE->getPack());
+ }
+
void VisitConstraint(const NormalizedConstraintWithParamMapping &Constraint) {
if (!Constraint.hasParameterMapping()) {
for (const auto &List : TemplateArgs)
@@ -2083,8 +2079,8 @@ bool SubstituteParameterMappings::substitute(ConceptIdConstraint &CC) {
/*UpdateArgsWithConversions=*/false))
return true;
auto TemplateArgs = *MLTAL;
- TemplateArgs.replaceOutermostTemplateArguments(
- TemplateArgs.getAssociatedDecl(0).first, CTAI.SugaredConverted);
+ TemplateArgs.replaceOutermostTemplateArguments(CSE->getNamedConcept(),
+ CTAI.SugaredConverted);
return SubstituteParameterMappings(SemaRef, &TemplateArgs, ArgsAsWritten,
InFoldExpr)
.substitute(CC.getNormalizedConstraint());
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 6bba505ece07d..3baa9775a49e4 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -6718,6 +6718,10 @@ struct MarkUsedTemplateParameterVisitor : DynamicRecursiveASTVisitor {
}
return true;
}
+
+ bool TraverseSizeOfPackExpr(SizeOfPackExpr *SOPE) override {
+ return TraverseDecl(SOPE->getPack());
+ }
};
}
diff --git a/clang/test/SemaTemplate/concepts.cpp b/clang/test/SemaTemplate/concepts.cpp
index 6d29f8b798e73..e3b9f9d26bfaf 100644
--- a/clang/test/SemaTemplate/concepts.cpp
+++ b/clang/test/SemaTemplate/concepts.cpp
@@ -1333,4 +1333,32 @@ static_assert(__cpp17_iterator<not_move_constructible>); \
// expected-note@#is_move_constructible_v {{because 'is_move_constructible_v<parameter_mapping_regressions::case3::not_move_constructible>' evaluated to false}}
}
+namespace case4 {
+
+template<bool b>
+concept bool_ = b;
+
+template<typename... Ts>
+concept unary = bool_<sizeof...(Ts) == 1>;
+
+static_assert(!unary<>);
+static_assert(unary<void>);
+
+}
+
+namespace case5 {
+
+template<int size>
+concept true1 = size == size;
+
+template<typename... Ts>
+concept true2 = true1<sizeof...(Ts)>;
+
+template<typename... Ts>
+concept true3 = true2<Ts...>;
+
+static_assert(true3<void>);
+
+}
+
}
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/128/builds/7520 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/72/builds/15352 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/95/builds/18598 Here is the relevant piece of the build log for the reference
|
This expression is not handled by default in RAV, so our parameter mapping and cache mechanism don't work when it appears in a template argument list. There are a few other expressions, such as PackIndexingExpr and FunctionParmPackExpr, which are also no-ops by default. I don't have a test case for them now, so let's leave those until users complain :/ There was also a bug in updating the parameter mapping, where the AssociatedDecl was not updated accordingly. Also also, this fixes another regression reported in llvm#161671 (comment), where we failed to account for the variable initializer in cache profiling. Relies on llvm#161671 Fixes llvm#161983 Fixes llvm#161987
UnsignedOrNone OuterPackSubstIndex; | ||
|
||
TemplateArgument getPackSubstitutedTemplateArgument(TemplateArgument Arg) { | ||
assert(*SemaRef.ArgPackSubstIndex < Arg.pack_size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we lose this assert, was this on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still there, which is guaranteed by ArrayRef.
This expression is not handled by default in RAV, so our parameter mapping and cache mechanism don't work when it appears in a template argument list.
There are a few other expressions, such as PackIndexingExpr and FunctionParmPackExpr, which are also no-ops by default. I don't have a test case for them now, so let's leave those until users complain :/
There was also a bug in updating the parameter mapping, where the AssociatedDecl was not updated accordingly.
Also also, this fixes another regression reported in #161671 (comment), where we failed to account for the variable initializer in cache profiling.
Relies on #161671
Fixes #161983
Fixes #161987