-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clang] OpenMP: fix variant template mismatch crash #164511
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 ammends the fix commited in https://reviews.llvm.org/D109770 / 6cf6fa6 Comparing the number of template parameter lists with the number of template parameters is obviously wrong. Even then, the number of parameters being the same doesn't mean the templates are compatible. This change compares if the template parameters are actually equivalent. This fixes the crash, but I am not sure what is the design and intention here, this openmp template support looks too fragile. The added test case still doesn't work, but at least we don't crash now.
|
@llvm/pr-subscribers-clang Author: Matheus Izvekov (mizvekov) ChangesThis ammends the fix commited in https://reviews.llvm.org/D109770 / 6cf6fa6 Comparing the number of template parameter lists with the number of template parameters is obviously wrong. Even then, the number of parameters being the same doesn't mean the templates are compatible. This change compares if the template parameters are actually equivalent. This fixes the crash, but I am not sure what is the design and intention here, this openmp template support looks too fragile. The added test case still doesn't work, but at least we don't crash now. Full diff: https://github.com/llvm/llvm-project/pull/164511.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 5b5b1b685e153..6d5cb0fcaea24 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -7246,7 +7246,9 @@ void SemaOpenMP::ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(
FunctionDecl *UDecl = nullptr;
if (IsTemplated && isa<FunctionTemplateDecl>(CandidateDecl)) {
auto *FTD = cast<FunctionTemplateDecl>(CandidateDecl);
- if (FTD->getTemplateParameters()->size() == TemplateParamLists.size())
+ // FIXME: Should this compare the template parameter lists on all levels?
+ if (SemaRef.Context.isSameTemplateParameterList(
+ FTD->getTemplateParameters(), TemplateParamLists.back()))
UDecl = FTD->getTemplatedDecl();
} else if (!IsTemplated)
UDecl = dyn_cast<FunctionDecl>(CandidateDecl);
diff --git a/clang/test/SemaOpenMP/openmp-begin-declare-variant_template.cpp b/clang/test/SemaOpenMP/openmp-begin-declare-variant_template.cpp
new file mode 100644
index 0000000000000..ded8f58253540
--- /dev/null
+++ b/clang/test/SemaOpenMP/openmp-begin-declare-variant_template.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple x86_64 -fopenmp -verify %s
+
+// FIXME: Is this supposed to work?
+
+#pragma omp begin declare variant match(implementation={extension(allow_templates)})
+template <class T> void f(T) {}
+// expected-note@-1 {{explicit instantiation refers here}}
+#pragma end
+template <int> struct A {};
+template <bool B> A<B> f() = delete;
+template void f<float>(float);
+// expected-error@-1 {{explicit instantiation of undefined function template 'f'}}
|
|
LGTM at least as a temporary workaround |
JonChesterfield
left a comment
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.
Yep, better than what came before, step forward it is. Thanks!
This ammends the fix commited in https://reviews.llvm.org/D109770 / 6cf6fa6 Comparing the number of template parameter lists with the number of template parameters is obviously wrong. Even then, the number of parameters being the same doesn't mean the templates are compatible. This change compares if the template parameters are actually equivalent. This fixes the crash, but I am not sure what is the design and intention here, this openmp template support looks too fragile. The added test case still doesn't work, but at least we don't crash now.
This ammends the fix commited in https://reviews.llvm.org/D109770 / 6cf6fa6 Comparing the number of template parameter lists with the number of template parameters is obviously wrong. Even then, the number of parameters being the same doesn't mean the templates are compatible. This change compares if the template parameters are actually equivalent. This fixes the crash, but I am not sure what is the design and intention here, this openmp template support looks too fragile. The added test case still doesn't work, but at least we don't crash now.
This ammends the fix commited in https://reviews.llvm.org/D109770 / 6cf6fa6 Comparing the number of template parameter lists with the number of template parameters is obviously wrong. Even then, the number of parameters being the same doesn't mean the templates are compatible. This change compares if the template parameters are actually equivalent. This fixes the crash, but I am not sure what is the design and intention here, this openmp template support looks too fragile. The added test case still doesn't work, but at least we don't crash now.
This ammends the fix commited in https://reviews.llvm.org/D109770 / 6cf6fa6
Comparing the number of template parameter lists with the number of template parameters is obviously wrong.
Even then, the number of parameters being the same doesn't mean the templates are compatible.
This change compares if the template parameters are actually equivalent.
This fixes the crash, but I am not sure what is the design and intention here, this openmp template support looks too fragile.
The added test case still doesn't work, but at least we don't crash now.