https://gcc.gnu.org/g:9759f4fa7d01775298d8db581a36eef0baafb752
commit r17-5084-g9759f4fa7d01775298d8db581a36eef0baafb752 Author: Tobias Burnus <[email protected]> Date: Mon Oct 12 12:28:08 2026 +0200 OpenMP/C++: Fix 'construct={simd}' trait-selector handling with 'declare variant' [PR127734] For unknown reasons, the C++ code for handling declare variant, c_omp_declare_simd_clauses_to_numbers, updated the 'simd' clause, but then returned without actually adding the trait-selectors to the declaration such that this variant was never added, if 'simd' appeared as construct. The original simd handling code, including early return, was added in commit r10-4230-g42ceec0607f323. With this commit, the xfails of commit r17-4947-gfbcafeec06a661 could be removed. Note: For some reasons, the order of variants is reverse in C++ compared with C, which should not have an effect, however. Cross ref: See also the new PR127850, [OpenMP] Handle user/manual-vectorization with SIMD trait in 'declare variant' which relates to (preexisting) FIXME near the modified code in cp/decl.cc. PR c++/127734 gcc/cp/ChangeLog: * decl.cc (omp_declare_variant_finalize_one): Remove early return when a 'simd' trait exists. gcc/testsuite/ChangeLog: * c-c++-common/gomp/simdlen-scaled-4.c: Remove xfail for C++, add C++ variant for __attribute__ tree scan. * g++.dg/gomp/simdlen-scaled-3.C: New test. Diff: --- gcc/cp/decl.cc | 1 - gcc/testsuite/c-c++-common/gomp/simdlen-scaled-4.c | 11 ++++++--- gcc/testsuite/g++.dg/gomp/simdlen-scaled-3.C | 27 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index fe210c48cfe5..593e67fd03b3 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -9280,7 +9280,6 @@ omp_declare_variant_finalize_one (tree decl, tree attr) = c_omp_declare_simd_clauses_to_numbers (DECL_ARGUMENTS (decl), OMP_TS_PROPERTIES (simd)); /* FIXME, adjusting simd args unimplemented. */ - return true; } tree chain = TREE_CHAIN (TREE_VALUE (attr)); diff --git a/gcc/testsuite/c-c++-common/gomp/simdlen-scaled-4.c b/gcc/testsuite/c-c++-common/gomp/simdlen-scaled-4.c index 574643235e89..aad9a6868173 100644 --- a/gcc/testsuite/c-c++-common/gomp/simdlen-scaled-4.c +++ b/gcc/testsuite/c-c++-common/gomp/simdlen-scaled-4.c @@ -42,7 +42,12 @@ void f() { // but the following three fail because of PR c++/127734: -// { dg-final { scan-tree-dump-times "fvar0 \\(3\\);" 1 "gimple" { xfail c++ } } } -// { dg-final { scan-tree-dump-times "fbase \\(4\\);" 1 "gimple" { target *-*-* } } } +// { dg-final { scan-tree-dump-times "fvar0 \\(3\\);" 1 "gimple" } } +// { dg-final { scan-tree-dump-times "fbase \\(4\\);" 1 "gimple" } } + + +// Same but function-name order reversed: + +// { dg-final { scan-tree-dump "__attribute__\\(\\(omp declare variant base \\(fvar0 match construct = {simd \\(simdlen\\(4\\)\\)}\\), omp declare variant base \\(fvarInt0 match construct = {simd \\(simdlen\\(scaled\\(int\\):8\\)\\)}\\), omp declare variant base \\(fvarInt2 match construct = {simd \\(simdlen\\(scaled\\(int,2\\):8\\)\\)}\\)\\)\\)" "gimple" { target c } } } +// { dg-final { scan-tree-dump "__attribute__\\(\\(omp declare variant base \\(fvarInt2 match construct = {simd \\(simdlen\\(scaled\\(int,2\\):8\\)\\)}\\), omp declare variant base \\(fvarInt0 match construct = {simd \\(simdlen\\(scaled\\(int\\):8\\)\\)}\\), omp declare variant base \\(fvar0 match construct = {simd \\(simdlen\\(4\\)\\)}\\)\\)\\)" "gimple" { target c++ } } } -// { dg-final { scan-tree-dump "__attribute__\\(\\(omp declare variant base \\(fvar0 match construct = {simd \\(simdlen\\(4\\)\\)}\\), omp declare variant base \\(fvarInt0 match construct = {simd \\(simdlen\\(scaled\\(int\\):8\\)\\)}\\), omp declare variant base \\(fvarInt2 match construct = {simd \\(simdlen\\(scaled\\(int,2\\):8\\)\\)}\\)\\)\\)" "gimple" { xfail c++ } } } diff --git a/gcc/testsuite/g++.dg/gomp/simdlen-scaled-3.C b/gcc/testsuite/g++.dg/gomp/simdlen-scaled-3.C new file mode 100644 index 000000000000..2644d2200e03 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/simdlen-scaled-3.C @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fdump-tree-gimple -w" } */ + +// PR c++/127734 +// PR middle-end/127723 + +template<typename T> +void f(T); + +#pragma omp declare variant(f) match(construct={simd(simdlen(scaled(T, 1): 4))}) // { dg-message "sorry, unimplemented: 'simdlen' clause with 'scaled' modifier" } +template<typename T> +void f0(T) { } + +void g() { + f0<int>(1); +} + +#pragma omp declare simd simdlen(scaled(T, 1): 4) // { dg-message "sorry, unimplemented: 'simdlen' clause with 'scaled' modifier" } +template<typename T> +void h() { } + +void c() { + h<float>(); +} + +// { dg-final { scan-tree-dump "__attribute__\\(\\(omp declare variant base \\(f match construct = {simd \\(simdlen\\(scaled\\(int,1\\):4\\)\\)}\\)\\)\\)" "gimple" } } +// { dg-final { scan-tree-dump "__attribute__\\(\\(omp declare simd \\(simdlen\\(scaled\\(float,1\\):4\\)\\)\\)\\)" "gimple" } }
