https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127734

            Bug ID: 127734
           Summary: [OpenMP] 'simd' 'construct' trait selector ignored in
                    'declare variant'
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: openmp, wrong-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: sandra at gcc dot gnu.org
  Target Milestone: ---

It seems as 'match(construct={simd(...)} is completely ignored in C++, contrary
to C.

Example:

void fvar0(int);
void fvar1(int);
void fvar2(int);

#pragma omp declare variant(fvar0) match(construct={parallel})
#pragma omp declare variant(fvar1) match(construct={parallel,simd(simdlen(4))})
#pragma omp declare variant(fvar2) match(construct={simd(simdlen(4))})
void fbase(int) { }

void f() {
 #pragma omp simd simdlen(4)
 for (int i = 0; i < 1; i++)
   fbase(1);  // should call fvar2.
}


For C++ vs. C, I see missing call to
  c_omp_declare_simd_clauses_to_numbers
in C.
[=> Search for 'sel == OMP_TRAIT_CONSTRUCT_SIMD' in C and C++.]

NOTE: In C++, there is code in parser.cc and in pt.cc, I have not checked
what's the relevant code there.


With the C compiler, it gives (-fdump-tree-gimple):

__attribute__((
  omp declare variant base (fvar2 match construct = {simd (simdlen(4))}),
  omp declare variant base (fvar1 match construct = {parallel, simd
(simdlen(4))}),
  omp declare variant base (fvar0 match construct = {parallel})))


But in C++, there is only:

__attribute__((omp declare variant base (fvar0 match construct = {parallel})))


NOTE: The dump requires the following to avoid an ICE (-> PR 127723):

--- a/gcc/tree-pretty-print.cc
+++ b/gcc/tree-pretty-print.cc
@@ -1788,2 +1788,3 @@ dump_omp_context_selector (pretty_printer *pp, tree ctx,
int spc,
          tree props = OMP_TS_PROPERTIES (sel);
+         enum omp_tp_type tp_type = omp_ts_map[OMP_TS_CODE (sel)].tp_type;
          if (props)
@@ -1799,3 +1799,5 @@ dump_omp_context_selector (pretty_printer *pp, tree ctx,
int spc,
                {
-                 if (OMP_TP_NAME (prop) == OMP_TP_NAMELIST_NODE)
+                 if (tp_type == OMP_TRAIT_PROPERTY_CLAUSE_LIST)
+                   dump_omp_clause (pp, prop, spc + 4, flags);
+                 else if (OMP_TP_NAME (prop) == OMP_TP_NAMELIST_NODE)
                    {

* * *

Accordingly, the function-variant replacement only works in C and not in C++.

NOTE: Before GCC 15, C seems to have the same problem - i.e. in GCC 15 it was
fixed for C but not for C++.

NOTE 2: I have not checked Fortran (yet).

Reply via email to