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

            Bug ID: 126256
           Summary: [OpenMP] declare target with 'enter' initializer and
                    'link' clause wrongly accepted
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid, openmp
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: burnus at gcc dot gnu.org
  Target Milestone: ---

OpenMP (here: TR15) states:

"If a variable appears in an enter clause on a declare target directive, its
initializer must not refer to a variable that appears in a link clause on a
declare target directive."

however, GCC accepts it but the (with nvptx) fails at runtime with: 
  libgomp: cuCtxSynchronize error: an illegal memory access was encountered


* * *

#pragma omp requires self_maps

static int init;
#pragma omp declare target enter(init)
static int *val = &init;
#pragma omp declare target link(val)

#pragma omp begin declare target
int f() { init++; return *val; }
#pragma omp end declare target

int main() {
  int res = 0;
  init = 42;

  #pragma omp target map(from: res)
    res = f();
  __builtin_printf ("val = %d\n", res);
}

Reply via email to