diff options
| author | Matheus Izvekov <mizvekov@gmail.com> | 2025-10-23 13:37:59 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-23 13:37:59 -0300 |
| commit | 7731156f30c6e7731e08b4ff52d262be10f93b16 (patch) | |
| tree | e9542be68080f3ba3eb6b3f5f4744b9c755692ec | |
| parent | 71b21b5391b267f10c8222fbbe73494fbce6dd86 (diff) | |
| download | llvm-7731156f30c6e7731e08b4ff52d262be10f93b16.zip llvm-7731156f30c6e7731e08b4ff52d262be10f93b16.tar.gz llvm-7731156f30c6e7731e08b4ff52d262be10f93b16.tar.bz2 | |
[clang] OpenMP: fix variant template mismatch crash (#164511)
This ammends the fix commited in https://reviews.llvm.org/D109770 /
6cf6fa6ef1c28
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.
| -rw-r--r-- | clang/lib/Sema/SemaOpenMP.cpp | 4 | ||||
| -rw-r--r-- | clang/test/SemaOpenMP/openmp-begin-declare-variant_template.cpp | 12 |
2 files changed, 15 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 5b5b1b6..6d5cb0f 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 0000000..ded8f58 --- /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'}} |
