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

            Bug ID: 113905
           Summary: [OpenMP] Declare variant rejects variant-function
                    re-usage
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: openmp, rejects-valid
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org, parras at gcc dot gnu.org,
                    sandra at gcc dot gnu.org
  Target Milestone: ---

The attached testcase works with Clang 17 and prints:

Got 42 (OK)
Got 99 (OK)
Got 1 (OK)
Got 2 (OK)
Got 2 (OK)
Got 1 (OK)

Where foo() and bar() share the variant functions 'var1' and 'var2', which
seems to be perfectly valid.


In GCC it fails to compile:

test.c: In function 'bar':
test.c:8:36: error: 'var1' used as a variant with incompatible 'construct'
selector sets
    8 | #pragma omp declare variant (var1) match(construct={target})
      |                                    ^~~~~
test.c:9:36: error: 'var2' used as a variant with incompatible 'construct'
selector sets
    9 | #pragma omp declare variant (var2) match(construct={parallel})
      |                                    ^~~~~


If I only keep the 'declare variant' for 'foo', it compiles. The gimple dump
shows:


__attribute__((omp declare target, omp declare variant variant (parallel )))
int var1 ()

__attribute__((omp declare target, omp declare variant variant (target )))
int var2 ()

__attribute__((omp declare target, omp declare variant base (var2 construct
target ), omp declare variant base (var1 construct parallel )))
int foo ()


I guess the problem is the 'omp declare variant variant' attribute on 'var1'
and 'var2', which causes the issue I am seeing.

Reply via email to