Skip to content

Commit 96e44b2

Browse files
mizvekovLukacma
authored andcommitted
[clang] OpenMP: fix variant template mismatch crash (llvm#164511)
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.
1 parent c489462 commit 96e44b2

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7246,7 +7246,9 @@ void SemaOpenMP::ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope(
72467246
FunctionDecl *UDecl = nullptr;
72477247
if (IsTemplated && isa<FunctionTemplateDecl>(CandidateDecl)) {
72487248
auto *FTD = cast<FunctionTemplateDecl>(CandidateDecl);
7249-
if (FTD->getTemplateParameters()->size() == TemplateParamLists.size())
7249+
// FIXME: Should this compare the template parameter lists on all levels?
7250+
if (SemaRef.Context.isSameTemplateParameterList(
7251+
FTD->getTemplateParameters(), TemplateParamLists.back()))
72507252
UDecl = FTD->getTemplatedDecl();
72517253
} else if (!IsTemplated)
72527254
UDecl = dyn_cast<FunctionDecl>(CandidateDecl);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -triple x86_64 -fopenmp -verify %s
2+
3+
// FIXME: Is this supposed to work?
4+
5+
#pragma omp begin declare variant match(implementation={extension(allow_templates)})
6+
template <class T> void f(T) {}
7+
// expected-note@-1 {{explicit instantiation refers here}}
8+
#pragma end
9+
template <int> struct A {};
10+
template <bool B> A<B> f() = delete;
11+
template void f<float>(float);
12+
// expected-error@-1 {{explicit instantiation of undefined function template 'f'}}

0 commit comments

Comments
 (0)